diff options
-rw-r--r-- | java/demo/Freeze/phonebook/Collocated.java | 21 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/ContactFactory.java | 15 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/ContactI.java | 8 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/PhoneBookI.java | 7 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/Server.java | 19 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/config | 3 | ||||
-rwxr-xr-x | java/src/Freeze/ConnectionI.java | 8 | ||||
-rw-r--r-- | java/src/Freeze/EvictorI.java | 57 | ||||
-rw-r--r-- | java/src/Freeze/EvictorIteratorI.java | 7 | ||||
-rw-r--r-- | java/src/Freeze/Index.java | 14 | ||||
-rw-r--r-- | java/src/Freeze/Map.java | 42 | ||||
-rw-r--r-- | java/src/Ice/PropertiesI.java | 1 |
12 files changed, 169 insertions, 33 deletions
diff --git a/java/demo/Freeze/phonebook/Collocated.java b/java/demo/Freeze/phonebook/Collocated.java index 5289e4b68d0..78207aaf399 100644 --- a/java/demo/Freeze/phonebook/Collocated.java +++ b/java/demo/Freeze/phonebook/Collocated.java @@ -20,6 +20,12 @@ class PhoneBookCollocated extends Ice.Application Ice.Properties properties = communicator().getProperties(); // + // Create and install a factory and initializer for contacts. + // + ContactFactory contactFactory = new ContactFactory(); + communicator().addObjectFactory(contactFactory, "::Contact"); + + // // Create the Name index // NameIndex index = new NameIndex("name"); @@ -35,7 +41,12 @@ class PhoneBookCollocated extends Ice.Application { evictor.setSize(evictorSize); } - + + // + // Set the evictor in the contact factory + // + contactFactory.setEvictor(evictor); + // // Create an Object Adapter, use the Evictor as Servant // Locator. @@ -46,16 +57,10 @@ class PhoneBookCollocated extends Ice.Application // // Create the phonebook, and add it to the Object Adapter. // - PhoneBookI phoneBook = new PhoneBookI(evictor, index); + PhoneBookI phoneBook = new PhoneBookI(evictor, contactFactory, index); adapter.add(phoneBook, Ice.Util.stringToIdentity("phonebook")); // - // Create and install a factory and initializer for contacts. - // - Ice.ObjectFactory contactFactory = new ContactFactory(evictor); - communicator().addObjectFactory(contactFactory, "::Contact"); - - // // Everything ok, let's go. // int status = RunParser.runParser(appName(), args, communicator()); diff --git a/java/demo/Freeze/phonebook/ContactFactory.java b/java/demo/Freeze/phonebook/ContactFactory.java index bce1212441a..e00b0427ce9 100644 --- a/java/demo/Freeze/phonebook/ContactFactory.java +++ b/java/demo/Freeze/phonebook/ContactFactory.java @@ -18,7 +18,7 @@ class ContactFactory extends Ice.LocalObjectImpl implements Ice.ObjectFactory create(String type) { assert(type.equals("::Contact")); - return new ContactI(_evictor); + return new ContactI(this); } public void @@ -26,10 +26,21 @@ class ContactFactory extends Ice.LocalObjectImpl implements Ice.ObjectFactory { } - ContactFactory(Freeze.Evictor evictor) + ContactFactory() + { + } + + void + setEvictor(Freeze.Evictor evictor) { _evictor = evictor; } + Freeze.Evictor + getEvictor() + { + return _evictor; + } + private Freeze.Evictor _evictor; } diff --git a/java/demo/Freeze/phonebook/ContactI.java b/java/demo/Freeze/phonebook/ContactI.java index 748b251a35e..c1df512dc46 100644 --- a/java/demo/Freeze/phonebook/ContactI.java +++ b/java/demo/Freeze/phonebook/ContactI.java @@ -62,7 +62,7 @@ class ContactI extends Contact { try { - _evictor.destroyObject(current.id); + _factory.getEvictor().destroyObject(current.id); } catch(Freeze.DatabaseException ex) { @@ -72,9 +72,9 @@ class ContactI extends Contact } } - ContactI(Freeze.Evictor evictor) + ContactI(ContactFactory factory) { - _evictor = evictor; + _factory = factory; // // It's possible to avoid this if there were two constructors // - one for original creation of the Contact and one for @@ -85,6 +85,6 @@ class ContactI extends Contact phone = new String(); } - private Freeze.Evictor _evictor; + private ContactFactory _factory; } diff --git a/java/demo/Freeze/phonebook/PhoneBookI.java b/java/demo/Freeze/phonebook/PhoneBookI.java index 3ca5e916ebd..b5e79bc4d41 100644 --- a/java/demo/Freeze/phonebook/PhoneBookI.java +++ b/java/demo/Freeze/phonebook/PhoneBookI.java @@ -28,7 +28,7 @@ class PhoneBookI extends _PhoneBookDisp // // Create a new Contact Servant. // - ContactI contact = new ContactI(_evictor); + ContactI contact = new ContactI(_contactFactory); // // Create a new Ice Object in the evictor, using the new @@ -79,12 +79,15 @@ class PhoneBookI extends _PhoneBookDisp current.adapter.getCommunicator().shutdown(); } - PhoneBookI(Freeze.Evictor evictor, NameIndex index) + PhoneBookI(Freeze.Evictor evictor, ContactFactory contactFactory, + NameIndex index) { _evictor = evictor; + _contactFactory = contactFactory; _index = index; } private Freeze.Evictor _evictor; + private ContactFactory _contactFactory; private NameIndex _index; } diff --git a/java/demo/Freeze/phonebook/Server.java b/java/demo/Freeze/phonebook/Server.java index bb105f4a0d3..b8658a87726 100644 --- a/java/demo/Freeze/phonebook/Server.java +++ b/java/demo/Freeze/phonebook/Server.java @@ -20,12 +20,19 @@ class PhoneBookServer extends Ice.Application Ice.Properties properties = communicator().getProperties(); // + // Create and install a factory and initializer for contacts. + // + ContactFactory contactFactory = new ContactFactory(); + communicator().addObjectFactory(contactFactory, "::Contact"); + + // // Create the name index. // NameIndex index = new NameIndex("name"); Freeze.Index[] indices = new Freeze.Index[1]; indices[0] = index; + // // Create an evictor for contacts. // @@ -37,6 +44,11 @@ class PhoneBookServer extends Ice.Application } // + // Set the evictor in the contact factory + // + contactFactory.setEvictor(evictor); + + // // Create an object adapter, use the evictor as servant // locator. // @@ -46,14 +58,9 @@ class PhoneBookServer extends Ice.Application // // Create the phonebook, and add it to the object adapter. // - PhoneBookI phoneBook = new PhoneBookI(evictor, index); + PhoneBookI phoneBook = new PhoneBookI(evictor, contactFactory, index); adapter.add(phoneBook, Ice.Util.stringToIdentity("phonebook")); - // - // Create and install a factory and initializer for contacts. - // - Ice.ObjectFactory contactFactory = new ContactFactory(evictor); - communicator().addObjectFactory(contactFactory, "::Contact"); // // Everything ok, let's go. diff --git a/java/demo/Freeze/phonebook/config b/java/demo/Freeze/phonebook/config index 6ee576770f4..dbb26ef2901 100644 --- a/java/demo/Freeze/phonebook/config +++ b/java/demo/Freeze/phonebook/config @@ -2,9 +2,10 @@ Ice.Warn.Connections=1 #Ice.Trace.Network=3 #Ice.Trace.Protocol=1 -#Freeze.Trace.Evictor=1 +Freeze.Trace.Evictor=1 Freeze.Trace.DbEnv=1 Freeze.Evictor.db.contacts.SavePeriod=10000 +Freeze.Evictor.db.contacts.PopulateEmptyIndices=1 PhoneBook.Endpoints=default -p 10000 PhoneBook.Proxy=phonebook:default -p 10000 diff --git a/java/src/Freeze/ConnectionI.java b/java/src/Freeze/ConnectionI.java index 41c3a674ad8..afdcadeb45b 100755 --- a/java/src/Freeze/ConnectionI.java +++ b/java/src/Freeze/ConnectionI.java @@ -103,6 +103,7 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection _dbEnv = _dbEnvHolder;
_envName = envName;
_trace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Map");
+ _deadlockWarning = _communicator.getProperties().getPropertyAsInt("Freeze.Warn.Deadlocks") != 0;
}
ConnectionI(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv)
@@ -180,6 +181,12 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection return _trace;
}
+ boolean
+ deadlockWarning()
+ {
+ return _deadlockWarning;
+ }
+
private Ice.Communicator _communicator;
private SharedDbEnv _dbEnvHolder;
private com.sleepycat.db.DbEnv _dbEnv;
@@ -187,4 +194,5 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection private TransactionI _transaction;
private java.util.List _mapList = new java.util.LinkedList();
private int _trace;
+ private boolean _deadlockWarning;
}
diff --git a/java/src/Freeze/EvictorI.java b/java/src/Freeze/EvictorI.java index 3b0efe1bd23..59aa83a457a 100644 --- a/java/src/Freeze/EvictorI.java +++ b/java/src/Freeze/EvictorI.java @@ -998,7 +998,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable java.util.List streamedObjectQueue = new java.util.ArrayList(); - long saveStart = System.currentTimeMillis(); + long streamStart = System.currentTimeMillis(); // // Stream each element @@ -1037,7 +1037,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } facet.status = dead; - streamedObjectQueue.add(streamFacet(facet, status, saveStart)); + streamedObjectQueue.add(streamFacet(facet, status, streamStart)); break; } default: @@ -1078,7 +1078,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } facet.status = clean; - streamedObjectQueue.add(streamFacet(facet, status, saveStart)); + streamedObjectQueue.add(streamFacet(facet, status, streamStart)); } else { @@ -1097,7 +1097,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } facet.status = dead; - streamedObjectQueue.add(streamFacet(facet, status, saveStart)); + streamedObjectQueue.add(streamFacet(facet, status, streamStart)); break; } default: @@ -1114,6 +1114,14 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } while(tryAgain); } + if(_trace >= 1) + { + long now = System.currentTimeMillis(); + _communicator.getLogger().trace( + "Freeze.Evictor", + "streamed " + streamedObjectQueue.size() + " objects in " + (now - streamStart) + " ms"); + } + // // Now let's save all these streamed objects to disk using a transaction // @@ -1141,6 +1149,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable txSize = streamedObjectQueue.size(); } + long saveStart = System.currentTimeMillis(); try { com.sleepycat.db.DbTxn tx = _dbEnv.txn_begin(null, 0); @@ -1205,11 +1214,17 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable _communicator.getLogger().trace( "Freeze.Evictor", "saved " + txSize + " objects in " + (now - saveStart) + " ms"); - saveStart = now; } } catch(com.sleepycat.db.DbDeadlockException deadlock) { + if(_deadlockWarning) + { + _communicator.getLogger().warning + ("Deadlock in Freeze.EvictorI.run while writing into Db \"" + _dbName + + "\"; retrying ..."); + } + tryAgain = true; txSize = (txSize + 1)/2; } @@ -1461,6 +1476,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } } + boolean + deadlockWarning() + { + return _deadlockWarning; + } + static byte[] marshalRootKey(Ice.Identity v, Ice.Communicator communicator) { @@ -1568,6 +1589,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable init(String envName, boolean createDb) { _trace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Evictor"); + _deadlockWarning = _communicator.getProperties().getPropertyAsInt("Freeze.Warn.Deadlocks") != 0; _errorPrefix = "Freeze Evictor DbEnv(\"" + envName + "\") Db(\"" + _dbName + "\"): "; @@ -1752,6 +1774,13 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } catch(com.sleepycat.db.DbDeadlockException deadlock) { + if(_deadlockWarning) + { + _communicator.getLogger().warning + ("Deadlock in Freeze.EvictorI.dhHasObject while reading Db \"" + _dbName + + "\"; retrying ..."); + } + // // Ignored, try again // @@ -1779,7 +1808,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } private StreamedObject - streamFacet(Facet facet, byte status, long saveStart) + streamFacet(Facet facet, byte status, long streamStart) { StreamedObject obj = new StreamedObject(); EvictorStorageKey esk = new EvictorStorageKey(); @@ -1789,7 +1818,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable obj.status = status; if(status != destroyed) { - obj.value = writeObjectRecordToValue(saveStart, facet.rec); + obj.value = writeObjectRecordToValue(streamStart, facet.rec); } return obj; } @@ -1833,13 +1862,13 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } private byte[] - writeObjectRecordToValue(long saveStart, ObjectRecord rec) + writeObjectRecordToValue(long streamStart, ObjectRecord rec) { // // Update stats first // Statistics stats = rec.stats; - long diff = saveStart - (stats.creationTime + stats.lastSaveTime); + long diff = streamStart - (stats.creationTime + stats.lastSaveTime); if(stats.lastSaveTime == 0) { stats.lastSaveTime = diff; @@ -1847,7 +1876,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } else { - stats.lastSaveTime = saveStart - stats.creationTime; + stats.lastSaveTime = streamStart - stats.creationTime; stats.avgSaveTime = (long)(stats.avgSaveTime * 0.95 + diff * 0.05); } return marshalValue(rec, _communicator); @@ -1911,6 +1940,13 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } catch(com.sleepycat.db.DbDeadlockException deadlock) { + if(_deadlockWarning) + { + _communicator.getLogger().warning + ("Deadlock in Freeze.EvictorI.load while iterating over Db \"" + _dbName + + "\"; retrying ..."); + } + // // Ignored, try again // @@ -2434,6 +2470,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable private Index[] _indices; private ServantInitializer _initializer; private int _trace = 0; + private boolean _deadlockWarning; // // Threads that have requested a "saveNow" and are waiting for diff --git a/java/src/Freeze/EvictorIteratorI.java b/java/src/Freeze/EvictorIteratorI.java index bcfe5fe8962..22ed67d245a 100644 --- a/java/src/Freeze/EvictorIteratorI.java +++ b/java/src/Freeze/EvictorIteratorI.java @@ -154,6 +154,13 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator _key.set_size(0); } + if(_evictor.deadlockWarning()) + { + communicator.getLogger().warning + ("Deadlock in Freeze.EvictorIteratorI.load while iterating over Db \"" + _evictor.dbName() + + "\"; retrying ..."); + } + // // Retry // diff --git a/java/src/Freeze/Index.java b/java/src/Freeze/Index.java index 63befb42b42..807f30d55c4 100644 --- a/java/src/Freeze/Index.java +++ b/java/src/Freeze/Index.java @@ -110,6 +110,13 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate } catch(com.sleepycat.db.DbDeadlockException dx) { + if(_evictor.deadlockWarning()) + { + communicator().getLogger().warning + ("Deadlock in Freeze.Index.untypedFindFirst while iterating over Db \"" + _evictor.dbName() + + "\"; retrying ..."); + } + // // Retry // @@ -189,6 +196,13 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate } catch(com.sleepycat.db.DbDeadlockException dx) { + if(_evictor.deadlockWarning()) + { + communicator().getLogger().warning + ("Deadlock in Freeze.Index.untypedCount while iterating over Db \"" + _evictor.dbName() + + "\"; retrying ..."); + } + // // Retry // diff --git a/java/src/Freeze/Map.java b/java/src/Freeze/Map.java index bb06d01c1b0..40e2e68bd51 100644 --- a/java/src/Freeze/Map.java +++ b/java/src/Freeze/Map.java @@ -134,6 +134,13 @@ public abstract class Map extends java.util.AbstractMap } else { + if(_connection.deadlockWarning()) + { + _connection.communicator().getLogger().warning + ("Deadlock in Freeze.Map.containsValue while iterating over Db \"" + _db.dbName() + + "\"; retrying ..."); + } + // // Try again // @@ -198,6 +205,13 @@ public abstract class Map extends java.util.AbstractMap } else { + if(_connection.deadlockWarning()) + { + _connection.communicator().getLogger().warning + ("Deadlock in Freeze.Map.containsKey while reading Db \"" + _db.dbName() + + "\"; retrying ..."); + } + // // Try again // @@ -317,6 +331,13 @@ public abstract class Map extends java.util.AbstractMap } else { + if(_connection.deadlockWarning()) + { + _connection.communicator().getLogger().warning + ("Deadlock in Freeze.Map.clear on Db \"" + _db.dbName() + + "\"; retrying ..."); + } + // // Try again // @@ -473,6 +494,13 @@ public abstract class Map extends java.util.AbstractMap } else { + if(_connection.deadlockWarning()) + { + _connection.communicator().getLogger().warning + ("Deadlock in Freeze.Map.getImpl while reading Db \"" + _db.dbName() + + "\"; retrying ..."); + } + // // Try again // @@ -531,6 +559,13 @@ public abstract class Map extends java.util.AbstractMap } else { + if(_connection.deadlockWarning()) + { + _connection.communicator().getLogger().warning + ("Deadlock in Freeze.Map.putImpl while writing into Db \"" + _db.dbName() + + "\"; retrying ..."); + } + // // Try again // @@ -586,6 +621,13 @@ public abstract class Map extends java.util.AbstractMap } else { + if(_connection.deadlockWarning()) + { + _connection.communicator().getLogger().warning + ("Deadlock in Freeze.Map.removeImpl while writing into Db \"" + _db.dbName() + + "\"; retrying ..."); + } + // // Try again // diff --git a/java/src/Ice/PropertiesI.java b/java/src/Ice/PropertiesI.java index 9b992b58495..1a220954442 100644 --- a/java/src/Ice/PropertiesI.java +++ b/java/src/Ice/PropertiesI.java @@ -565,6 +565,7 @@ final class PropertiesI extends LocalObjectImpl implements Properties private static final String _freezeProps[] = { + "Warn.Deadlocks", "Trace.Map", "Trace.Evictor", "Trace.DbEnv", |