diff options
Diffstat (limited to 'java/src')
-rwxr-xr-x | java/src/Freeze/ConnectionI.java | 4 | ||||
-rw-r--r-- | java/src/Freeze/EvictorI.java | 261 | ||||
-rw-r--r-- | java/src/Freeze/EvictorIteratorI.java | 50 | ||||
-rw-r--r-- | java/src/Freeze/Index.java | 137 | ||||
-rw-r--r-- | java/src/Freeze/Map.java | 433 | ||||
-rw-r--r-- | java/src/Freeze/ObjectStore.java | 111 | ||||
-rwxr-xr-x | java/src/Freeze/SharedDb.java | 74 | ||||
-rw-r--r-- | java/src/Freeze/SharedDbEnv.java | 133 | ||||
-rwxr-xr-x | java/src/Freeze/TransactionI.java | 67 | ||||
-rw-r--r-- | java/src/Freeze/Util.java | 19 |
10 files changed, 586 insertions, 703 deletions
diff --git a/java/src/Freeze/ConnectionI.java b/java/src/Freeze/ConnectionI.java index ace8e367748..5d2ea9ad894 100755 --- a/java/src/Freeze/ConnectionI.java +++ b/java/src/Freeze/ConnectionI.java @@ -101,7 +101,7 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection } } - ConnectionI(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv) + ConnectionI(Ice.Communicator communicator, String envName, com.sleepycat.db.Environment dbEnv) { _communicator = communicator; _dbEnv = SharedDbEnv.get(communicator, envName, dbEnv); @@ -149,7 +149,7 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection _transaction = null; } - com.sleepycat.db.DbTxn + com.sleepycat.db.Transaction dbTxn() { if(_transaction == null) diff --git a/java/src/Freeze/EvictorI.java b/java/src/Freeze/EvictorI.java index 208ac3b4e13..f3726f3c487 100644 --- a/java/src/Freeze/EvictorI.java +++ b/java/src/Freeze/EvictorI.java @@ -11,7 +11,6 @@ package Freeze; class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable { - final static String defaultDb = "$default"; final static String indexPrefix = "$index:"; @@ -66,8 +65,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable // if(System.currentTimeMillis() - startTime >= _timeout) { - _communicator.getLogger().error - (_errorPrefix + "Fatal error: streaming watch dog thread timed out."); + _communicator.getLogger().error(_errorPrefix + + "Fatal error: streaming watch dog thread timed out."); Util.handleFatalError(EvictorI.this, _communicator, null); } @@ -98,7 +97,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable private boolean _active = false; } - class DeactivateController { synchronized void lock() @@ -158,29 +156,29 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable _deactivating = true; while(_guardCount > 0) { - if(_trace >= 1) - { - _communicator.getLogger().trace( - "Freeze.Evictor", "*** Waiting for " + _guardCount - + " threads to complete before starting deactivation."); - } - - try - { - wait(); - } - catch(InterruptedException e) - { - // Ignored - } - } - - if(_trace >= 1) - { - _communicator.getLogger().trace("Freeze.Evictor", "Starting deactivation."); - } - return true; - } + if(_trace >= 1) + { + _communicator.getLogger().trace( + "Freeze.Evictor", "*** Waiting for " + _guardCount + + " threads to complete before starting deactivation."); + } + + try + { + wait(); + } + catch(InterruptedException e) + { + // Ignored + } + } + + if(_trace >= 1) + { + _communicator.getLogger().trace("Freeze.Evictor", "Starting deactivation."); + } + return true; + } } synchronized void deactivationComplete() @@ -199,12 +197,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable private boolean _deactivated = false; private int _guardCount = 0; } - - public - EvictorI(Ice.ObjectAdapter adapter, String envName, String filename, - ServantInitializer initializer, + EvictorI(Ice.ObjectAdapter adapter, String envName, String filename, ServantInitializer initializer, Index[] indices, boolean createDb) { _adapter = adapter; @@ -216,10 +211,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } public - EvictorI(Ice.ObjectAdapter adapter, String envName, - com.sleepycat.db.DbEnv dbEnv, String filename, - ServantInitializer initializer, - Index[] indices, boolean createDb) + EvictorI(Ice.ObjectAdapter adapter, String envName, com.sleepycat.db.Environment dbEnv, String filename, + ServantInitializer initializer, Index[] indices, boolean createDb) { _adapter = adapter; _communicator = adapter.getCommunicator(); @@ -230,12 +223,10 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } private void - init(String envName, com.sleepycat.db.DbEnv dbEnv, Index[] indices) + init(String envName, com.sleepycat.db.Environment dbEnv, Index[] indices) { - _dbEnv = SharedDbEnv.get(_communicator, envName, dbEnv); - _trace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Evictor"); _txTrace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Transaction"); _deadlockWarning = _communicator.getProperties().getPropertyAsInt("Freeze.Warn.Deadlocks") != 0; @@ -249,25 +240,25 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable // queue reaches 10. // - _saveSizeTrigger = _communicator.getProperties().getPropertyAsIntWithDefault - (propertyPrefix + ".SaveSizeTrigger", 10); + _saveSizeTrigger = + _communicator.getProperties().getPropertyAsIntWithDefault(propertyPrefix + ".SaveSizeTrigger", 10); - _savePeriod = _communicator.getProperties().getPropertyAsIntWithDefault - (propertyPrefix + ".SavePeriod", 60 * 1000); + _savePeriod = + _communicator.getProperties().getPropertyAsIntWithDefault(propertyPrefix + ".SavePeriod", 60 * 1000); // // By default, we save at most 10 * SaveSizeTrigger objects per transaction // - _maxTxSize = _communicator.getProperties().getPropertyAsIntWithDefault - (propertyPrefix + ".MaxTxSize", 10 * _saveSizeTrigger); + _maxTxSize = _communicator.getProperties().getPropertyAsIntWithDefault( + propertyPrefix + ".MaxTxSize", 10 * _saveSizeTrigger); if(_maxTxSize <= 0) { _maxTxSize = 100; } - boolean populateEmptyIndices = (_communicator.getProperties().getPropertyAsIntWithDefault - (propertyPrefix + ".PopulateEmptyIndices", 0) != 0); + boolean populateEmptyIndices = + _communicator.getProperties().getPropertyAsIntWithDefault(propertyPrefix + ".PopulateEmptyIndices", 0) != 0; // // Instantiate all Dbs in 2 steps: @@ -281,7 +272,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable // dbs.add(defaultDb); - if(indices != null) { for(int i = 0; i < indices.length; ++i) @@ -299,8 +289,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } } - ObjectStore store = new ObjectStore(facet, _createDb, this, storeIndices, - populateEmptyIndices); + ObjectStore store = new ObjectStore(facet, _createDb, this, storeIndices, populateEmptyIndices); _storeMap.put(facet, store); } } @@ -344,8 +333,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable // // By default, no stream timeout // - long streamTimeout = _communicator.getProperties() - .getPropertyAsIntWithDefault(propertyPrefix + ".StreamTimeout", 0) * 1000; + long streamTimeout = + _communicator.getProperties().getPropertyAsIntWithDefault(propertyPrefix + ".StreamTimeout", 0) * 1000; if(streamTimeout > 0) { @@ -356,7 +345,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable _thread = new Thread(this, savingThreadName); _thread.start(); } - protected void finalize() @@ -411,7 +399,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable return addFacet(servant, ident, ""); } - public Ice.ObjectPrx addFacet(Ice.Object servant, Ice.Identity ident, String facet) { @@ -470,8 +457,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable assert store != null; boolean alreadyThere = false; - - + for(;;) { // @@ -568,9 +554,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable objString += " with facet \"" + facet + "\""; } - _communicator.getLogger().trace( - "Freeze.Evictor", - "added " + objString + " in the database"); + _communicator.getLogger().trace("Freeze.Evictor", "added " + objString + " in the database"); } Ice.ObjectPrx obj = _adapter.createProxy(ident); @@ -586,7 +570,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } } - // // Deprecated // @@ -692,9 +675,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable if(_trace >= 1) { String objString = "object \"" + Ice.Util.identityToString(ident) + "\""; - _communicator.getLogger().trace( - "Freeze.Evictor", - "added or updated " + objString + " in the database"); + _communicator.getLogger().trace("Freeze.Evictor", "added or updated " + objString + " in the database"); } } finally @@ -703,7 +684,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } } - public Ice.Object remove(Ice.Identity ident) { @@ -841,9 +821,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable objString += " with facet \"" + facet + "\""; } - _communicator.getLogger().trace( - "Freeze.Evictor", - "removed " + objString); + _communicator.getLogger().trace("Freeze.Evictor", "removed " + objString); } return servant; } @@ -873,7 +851,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } } - public void keep(Ice.Identity ident) { @@ -1051,7 +1028,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable _deactivateController.unlock(); } } - public EvictorIterator getIterator(String facet, int batchSize) @@ -1132,8 +1108,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable synchronized(element) { - return element.status != EvictorElement.dead && - element.status != EvictorElement.destroyed; + return element.status != EvictorElement.dead && element.status != EvictorElement.destroyed; } } } @@ -1180,8 +1155,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable synchronized(element) { - if(element.status != EvictorElement.dead && - element.status != EvictorElement.destroyed) + if(element.status != EvictorElement.dead && element.status != EvictorElement.destroyed) { return true; } @@ -1206,7 +1180,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable _deactivateController.lock(); try { - // // Special ice_ping() handling // @@ -1219,9 +1192,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable if(_trace >= 3) { _communicator.getLogger().trace( - "Freeze.Evictor", - "ice_ping found \"" + Ice.Util.identityToString(current.id) - + "\" with facet \"" + current.facet + "\""); + "Freeze.Evictor", "ice_ping found \"" + Ice.Util.identityToString(current.id) + + "\" with facet \"" + current.facet + "\""); } cookie.value = null; return _pingObject; @@ -1231,9 +1203,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable if(_trace >= 3) { _communicator.getLogger().trace( - "Freeze.Evictor", - "ice_ping raises FacetNotExistException for \"" + Ice.Util.identityToString(current.id) - + "\" with facet \"" + current.facet + "\""); + "Freeze.Evictor", "ice_ping raises FacetNotExistException for \"" + + Ice.Util.identityToString(current.id) + "\" with facet \"" + current.facet + "\""); } throw new Ice.FacetNotExistException(); @@ -1243,16 +1214,14 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable if(_trace >= 3) { _communicator.getLogger().trace( - "Freeze.Evictor", - "ice_ping will raise ObjectNotExistException for \"" + Ice.Util.identityToString(current.id) - + "\" with facet \"" + current.facet + "\""); + "Freeze.Evictor", "ice_ping will raise ObjectNotExistException for \"" + + Ice.Util.identityToString(current.id) + "\" with facet \"" + current.facet + "\""); } return null; } } - Ice.Object result = locateImpl(current, cookie); if(result == null) @@ -1287,9 +1256,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable { if(_trace >= 2) { - _communicator.getLogger().trace( - "Freeze.Evictor", - "locate could not find a database for facet \"" + current.facet + "\""); + _communicator.getLogger().trace("Freeze.Evictor", "locate could not find a database for facet \"" + + current.facet + "\""); } return null; } @@ -1301,10 +1269,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable { if(_trace >= 2) { - _communicator.getLogger().trace( - "Freeze.Evictor", - "locate could not find \"" + Ice.Util.identityToString(ident) - + "\" in database \"" + current.facet + "\""); + _communicator.getLogger().trace("Freeze.Evictor", "locate could not find \"" + + Ice.Util.identityToString(ident) + "\" in database \"" + + current.facet + "\""); } return null; } @@ -1326,11 +1293,10 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable { if(_trace >= 2) { - _communicator.getLogger().trace( - "Freeze.Evictor", - "locate found \"" + Ice.Util.identityToString(ident) - + "\" in the cache for database \"" + current.facet - + "\" but it was dead or destroyed"); + _communicator.getLogger().trace("Freeze.Evictor", "locate found \"" + + Ice.Util.identityToString(ident) + + "\" in the cache for database \"" + current.facet + + "\" but it was dead or destroyed"); } return null; } @@ -1339,13 +1305,11 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable // It's a good one! // - if(_trace >= 2) { - _communicator.getLogger().trace( - "Freeze.Evictor", - "locate found \"" + Ice.Util.identityToString(ident) - + "\" in database \"" + current.facet + "\""); + _communicator.getLogger().trace("Freeze.Evictor", "locate found \"" + + Ice.Util.identityToString(ident) + "\" in database \"" + + current.facet + "\""); } fixEvictPosition(element); @@ -1696,9 +1660,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable if(_trace >= 1) { long now = System.currentTimeMillis(); - _communicator.getLogger().trace( - "Freeze.Evictor", - "streamed " + streamedObjectQueue.size() + " objects in " + (now - streamStart) + " ms"); + _communicator.getLogger().trace("Freeze.Evictor", "streamed " + streamedObjectQueue.size() + + " objects in " + (now - streamStart) + " ms"); } // @@ -1733,15 +1696,14 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable try { - com.sleepycat.db.DbTxn tx = _dbEnv.getEnv().txnBegin(null, 0); + com.sleepycat.db.Transaction tx = _dbEnv.getEnv().beginTransaction(null, null); if(_txTrace >= 1) { - txnId = Long.toHexString((tx.id() & 0x7FFFFFFF) + 0x80000000L); + txnId = Long.toHexString((tx.getId() & 0x7FFFFFFF) + 0x80000000L); - _communicator.getLogger().trace - ("Freeze.Evictor", _errorPrefix + "started transaction " + - txnId + " in saving thread"); + _communicator.getLogger().trace("Freeze.Evictor", _errorPrefix + + "started transaction " + txnId + " in saving thread"); } try @@ -1752,15 +1714,14 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable obj.store.save(obj.key, obj.value, obj.status, tx); } - com.sleepycat.db.DbTxn toCommit = tx; + com.sleepycat.db.Transaction toCommit = tx; tx = null; - toCommit.commit(0); + toCommit.commit(); if(_txTrace >= 1) { - _communicator.getLogger().trace - ("Freeze.Evictor", _errorPrefix + "committed transaction " + - txnId); + _communicator.getLogger().trace("Freeze.Evictor", _errorPrefix + + "committed transaction " + txnId); } } finally @@ -1770,9 +1731,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable tx.abort(); if(_txTrace >= 1) { - _communicator.getLogger().trace - ("Freeze.Evictor", _errorPrefix + "rolled back transaction " + - txnId); + _communicator.getLogger().trace("Freeze.Evictor", _errorPrefix + + "rolled back transaction " + txnId); } } } @@ -1785,24 +1745,22 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable if(_trace >= 1) { long now = System.currentTimeMillis(); - _communicator.getLogger().trace( - "Freeze.Evictor", - "saved " + txSize + " objects in " + (now - saveStart) + " ms"); + _communicator.getLogger().trace("Freeze.Evictor", "saved " + txSize + " objects in " + + (now - saveStart) + " ms"); } } - catch(com.sleepycat.db.DbDeadlockException deadlock) + catch(com.sleepycat.db.DeadlockException dx) { if(_deadlockWarning) { - _communicator.getLogger().warning - ("Deadlock in Freeze.EvictorI.run while writing into Db \"" + _filename - + "\"; retrying ..."); + _communicator.getLogger().warning("Deadlock in Freeze.EvictorI.run while writing " + + "into Db \"" + _filename + "\"; retrying..."); } tryAgain = true; txSize = (txSize + 1)/2; } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -1868,14 +1826,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable java.io.PrintWriter pw = new java.io.PrintWriter(sw); ex.printStackTrace(pw); pw.flush(); - _communicator.getLogger(). - error(_errorPrefix + "Fatal error in saving thread:\n" + sw.toString()); + _communicator.getLogger().error(_errorPrefix + "Fatal error in saving thread:\n" + sw.toString()); Util.handleFatalError(this, _communicator, ex); } } - final DeactivateController deactivateController() { @@ -1974,10 +1930,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable objString += " with facet \"" + facet + "\""; } - _communicator.getLogger().trace( - "Freeze.Evictor", - "evicting " + objString + " from the queue; " + "number of elements in the queue: " + - _currentEvictorSize); + _communicator.getLogger().trace("Freeze.Evictor", "evicting " + objString + " from the queue; " + + "number of elements in the queue: " + _currentEvictorSize); } // @@ -1992,7 +1946,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable } } - private void fixEvictPosition(EvictorElement element) { @@ -2040,7 +1993,6 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable element.store.cache().unpin(element.identity); } - private void addToModifiedQueue(EvictorElement element) { @@ -2096,32 +2048,30 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable return (ObjectStore) _storeMap.get(facet); } - private java.util.List allDbs() { java.util.List result = new java.util.LinkedList(); - com.sleepycat.db.Db db = null; - com.sleepycat.db.Dbc dbc = null; + com.sleepycat.db.Database db = null; + com.sleepycat.db.Cursor dbc = null; try { - db = new com.sleepycat.db.Db(_dbEnv.getEnv(), 0); - db.open(null, _filename, null, com.sleepycat.db.Db.DB_UNKNOWN, com.sleepycat.db.Db.DB_RDONLY, 0); - - dbc = db.cursor(null, 0); - - com.sleepycat.db.Dbt key = new com.sleepycat.db.Dbt(); - key.setFlags(com.sleepycat.db.Db.DB_DBT_MALLOC); - - com.sleepycat.db.Dbt value = new com.sleepycat.db.Dbt(); - value.setFlags(com.sleepycat.db.Db.DB_DBT_MALLOC); - + com.sleepycat.db.DatabaseConfig config = new com.sleepycat.db.DatabaseConfig(); + config.setType(com.sleepycat.db.DatabaseType.UNKNOWN); + config.setReadOnly(true); + db = _dbEnv.getEnv().openDatabase(null, _filename, null, config); + + dbc = db.openCursor(null, null); + + com.sleepycat.db.DatabaseEntry key = new com.sleepycat.db.DatabaseEntry(); + com.sleepycat.db.DatabaseEntry value = new com.sleepycat.db.DatabaseEntry(); + boolean more = true; while(more) { - more = (dbc.get(key, value, com.sleepycat.db.Db.DB_NEXT) == 0); + more = (dbc.getNext(key, value, null) == com.sleepycat.db.OperationStatus.SUCCESS); if(more) { // @@ -2138,7 +2088,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable dbc.close(); dbc = null; - db.close(0); + db.close(); db = null; } catch(java.io.UnsupportedEncodingException ix) @@ -2154,7 +2104,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable // New file // } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -2169,7 +2119,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable { dbc.close(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { // Ignored } @@ -2179,9 +2129,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable { try { - db.close(0); + db.close(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { // Ignored } @@ -2190,15 +2140,13 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable return result; } - private static void checkIdentity(Ice.Identity ident) { if(ident.name == null || ident.name.length() == 0) { - Ice.IllegalIdentityException e = - new Ice.IllegalIdentityException(); + Ice.IllegalIdentityException e = new Ice.IllegalIdentityException(); e.id = (Ice.Identity)ident.clone(); throw e; } @@ -2266,5 +2214,4 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable private boolean _deadlockWarning; private Ice.Object _pingObject = new PingObject(); - } diff --git a/java/src/Freeze/EvictorIteratorI.java b/java/src/Freeze/EvictorIteratorI.java index 93a2fd521f9..f39f9be6cc9 100644 --- a/java/src/Freeze/EvictorIteratorI.java +++ b/java/src/Freeze/EvictorIteratorI.java @@ -46,16 +46,12 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator assert batchSize > 0; - // - // We should use DB_DBT_REALLOC, but it's buggy in 4.1.25 - // (causes weird problems, e.g. can't find some values) - // - _key.setFlags(com.sleepycat.db.Db.DB_DBT_MALLOC); + _key.setReuseBuffer(true); // // dlen is 0, so we should not retrieve any value // - _value.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + _value.setPartial(true); } private java.util.Iterator @@ -86,7 +82,7 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator { for(;;) { - com.sleepycat.db.Dbc dbc = null; + com.sleepycat.db.Cursor dbc = null; _batch = new java.util.ArrayList(); @@ -95,27 +91,36 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator // // Move to the first record // - int flags = com.sleepycat.db.Db.DB_NEXT; + boolean range = false; if(firstKey != null) { // // _key represents the next element not yet returned // if it has been deleted, we want the one after // - flags = com.sleepycat.db.Db.DB_SET_RANGE; + range = true; } - dbc = _store.db().cursor(null, 0); + dbc = _store.db().openCursor(null, null); boolean done = false; do { - _more = (dbc.get(_key, _value, flags) == 0); - + com.sleepycat.db.OperationStatus status; + if(range) + { + status = dbc.getSearchKeyRange(_key, _value, null); + } + else + { + status = dbc.getNext(_key, _value, null); + } + _more = (status == com.sleepycat.db.OperationStatus.SUCCESS); + if(_more) { - flags = com.sleepycat.db.Db.DB_NEXT; - + range = false; + if(_batch.size() < _batchSize) { Ice.Identity ident = ObjectStore.unmarshalKey(_key.getData(), communicator); @@ -134,7 +139,7 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator break; // for (;;) } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { if(firstKey != null) { @@ -149,10 +154,9 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator if(_store.evictor().deadlockWarning()) { - communicator.getLogger().warning - ("Deadlock in Freeze.EvictorIteratorI.load while iterating over Db \"" - + _store.evictor().filename() + "/" + _store.dbName() - + "\"; retrying ..."); + communicator.getLogger().warning("Deadlock in Freeze.EvictorIteratorI.load while " + + "iterating over Db \"" + _store.evictor().filename() + "/" + _store.dbName() + + "\"; retrying..."); } // @@ -167,7 +171,7 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator { dbc.close(); } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { // // Ignored @@ -177,7 +181,7 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator } } } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -204,8 +208,8 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator private final int _batchSize; private java.util.Iterator _batchIterator; - private final com.sleepycat.db.Dbt _key = new com.sleepycat.db.Dbt(); - private final com.sleepycat.db.Dbt _value = new com.sleepycat.db.Dbt(); + private final com.sleepycat.db.DatabaseEntry _key = new com.sleepycat.db.DatabaseEntry(); + private final com.sleepycat.db.DatabaseEntry _value = new com.sleepycat.db.DatabaseEntry(); private java.util.List _batch = null; private boolean _more = true; } diff --git a/java/src/Freeze/Index.java b/java/src/Freeze/Index.java index 58b7735b5ce..17c7ef0903a 100644 --- a/java/src/Freeze/Index.java +++ b/java/src/Freeze/Index.java @@ -9,18 +9,18 @@ package Freeze; -public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate +public abstract class Index implements com.sleepycat.db.SecondaryKeyCreator { - // // Implementation details // - public int - secondaryKeyCreate(com.sleepycat.db.Db secondary, - com.sleepycat.db.Dbt key, - com.sleepycat.db.Dbt value, - com.sleepycat.db.Dbt result) + public boolean + createSecondaryKey(com.sleepycat.db.SecondaryDatabase secondary, + com.sleepycat.db.DatabaseEntry key, + com.sleepycat.db.DatabaseEntry value, + com.sleepycat.db.DatabaseEntry result) + throws com.sleepycat.db.DatabaseException { Ice.Communicator communicator = _store.communicator(); ObjectRecord rec = ObjectStore.unmarshalValue(value.getData(), communicator); @@ -30,28 +30,16 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate { result.setData(secondaryKey); result.setSize(secondaryKey.length); - return 0; + return true; } else { // // Don't want to index this one // - return com.sleepycat.db.Db.DB_DONOTINDEX; + return false; } } - - // - // Alias for Berkeley DB 4.1.25 - // - public int - secondary_key_create(com.sleepycat.db.Db secondary, - com.sleepycat.db.Dbt key, - com.sleepycat.db.Dbt value, - com.sleepycat.db.Dbt result) - { - return secondaryKeyCreate(secondary, key, value, result); - } public String name() @@ -82,16 +70,14 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate try { - com.sleepycat.db.Dbt key = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry key = new com.sleepycat.db.DatabaseEntry(k); - com.sleepycat.db.Dbt pkey = new com.sleepycat.db.Dbt(); - pkey.setFlags(com.sleepycat.db.Db.DB_DBT_MALLOC); - - com.sleepycat.db.Dbt value = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry pkey = new com.sleepycat.db.DatabaseEntry(); + com.sleepycat.db.DatabaseEntry value = new com.sleepycat.db.DatabaseEntry(); // // dlen is 0, so we should not retrieve any value // - value.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + value.setPartial(true); Ice.Communicator communicator = _store.communicator(); _store.evictor().saveNow(); @@ -102,7 +88,7 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate { for(;;) { - com.sleepycat.db.Dbc dbc = null; + com.sleepycat.db.SecondaryCursor dbc = null; identities = new java.util.ArrayList(); try @@ -110,34 +96,43 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate // // Move to the first record // - dbc = _db.cursor(null, 0); - int flags = com.sleepycat.db.Db.DB_SET; + dbc = _db.openSecondaryCursor(null, null); + boolean first = true; boolean found; do { - found = (dbc.get(key, pkey, value, flags) == 0); + com.sleepycat.db.OperationStatus status; + if(first) + { + status = dbc.getSearchKey(key, pkey, value, null); + } + else + { + status = dbc.getNextDup(key, pkey, value, null); + } + + found = status == com.sleepycat.db.OperationStatus.SUCCESS; if(found) { Ice.Identity ident = ObjectStore.unmarshalKey(pkey.getData(), communicator); identities.add(ident); - flags = com.sleepycat.db.Db.DB_NEXT_DUP; + first = false; } } while((firstN <= 0 || identities.size() < firstN) && found); break; // for(;;) } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { if(_store.evictor().deadlockWarning()) { - communicator.getLogger().warning - ("Deadlock in Freeze.Index.untypedFindFirst while iterating over Db \"" - + _store.evictor().filename() + "/" + _dbName - + "\"; retrying ..."); + communicator.getLogger().warning("Deadlock in Freeze.Index.untypedFindFirst while " + + "iterating over Db \"" + _store.evictor().filename() + + "/" + _dbName + "\"; retrying..."); } // @@ -152,7 +147,7 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate { dbc.close(); } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { // // Ignored @@ -162,7 +157,7 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate } } } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -200,41 +195,39 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate try { - com.sleepycat.db.Dbt key = new com.sleepycat.db.Dbt(k); - com.sleepycat.db.Dbt value = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry key = new com.sleepycat.db.DatabaseEntry(k); + com.sleepycat.db.DatabaseEntry value = new com.sleepycat.db.DatabaseEntry(); // // dlen is 0, so we should not retrieve any value // - value.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + value.setPartial(true); _store.evictor().saveNow(); try { for(;;) { - com.sleepycat.db.Dbc dbc = null; + com.sleepycat.db.Cursor dbc = null; try { - dbc = _db.cursor(null, 0); - boolean found = (dbc.get(key, value, com.sleepycat.db.Db.DB_SET) == 0); - - if(found) + dbc = _db.openCursor(null, null); + if(dbc.getSearchKey(key, value, null) == com.sleepycat.db.OperationStatus.SUCCESS) { - return dbc.count(0); + return dbc.count(); } else { return 0; } } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { if(_store.evictor().deadlockWarning()) { - _store.communicator().getLogger().warning - ("Deadlock in Freeze.Index.untypedCount while iterating over Db \"" - + _store.evictor().filename() + "/" + _dbName - + "\"; retrying ..."); + _store.communicator().getLogger().warning("Deadlock in Freeze.Index.untypedCount while " + + "iterating over Db \"" + + _store.evictor().filename() + "/" + _dbName + + "\"; retrying..."); } // @@ -249,7 +242,7 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate { dbc.close(); } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { // // Ignored @@ -259,7 +252,7 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate } } } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -280,31 +273,23 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate } void - associate(ObjectStore store, com.sleepycat.db.DbTxn txn, boolean createDb, boolean populateIndex) - throws com.sleepycat.db.DbException, java.io.FileNotFoundException + associate(ObjectStore store, com.sleepycat.db.Transaction txn, boolean createDb, boolean populateIndex) + throws com.sleepycat.db.DatabaseException, java.io.FileNotFoundException { assert(txn != null); _store = store; - _db= new com.sleepycat.db.Db(_store.evictor().dbEnv().getEnv(), 0); - _db.setFlags(com.sleepycat.db.Db.DB_DUP | com.sleepycat.db.Db.DB_DUPSORT); - - int flags = 0; - if(createDb) - { - flags = com.sleepycat.db.Db.DB_CREATE; - } - _dbName = EvictorI.indexPrefix + store.dbName() + "." + _name; - _db.open(txn, _store.evictor().filename(), _dbName, com.sleepycat.db.Db.DB_BTREE, flags, 0); + com.sleepycat.db.SecondaryConfig config = new com.sleepycat.db.SecondaryConfig(); + config.setAllowCreate(createDb); + config.setAllowPopulate(populateIndex); + config.setSortedDuplicates(true); + config.setType(com.sleepycat.db.DatabaseType.BTREE); + config.setKeyCreator(this); - flags = 0; - if(populateIndex) - { - flags = com.sleepycat.db.Db.DB_CREATE; - } - _store.db().associate(txn, _db, this, flags); + _db = _store.evictor().dbEnv().getEnv().openSecondaryDatabase(txn, _store.evictor().filename(), _dbName, + _store.db(), config); } void @@ -314,9 +299,9 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate { try { - _db.close(0); + _db.close(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -331,6 +316,6 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate private final String _facet; private String _dbName; - private com.sleepycat.db.Db _db = null; + private com.sleepycat.db.SecondaryDatabase _db = null; private ObjectStore _store = null; } diff --git a/java/src/Freeze/Map.java b/java/src/Freeze/Map.java index 5a73281a0b5..b1b13ee2772 100644 --- a/java/src/Freeze/Map.java +++ b/java/src/Freeze/Map.java @@ -76,10 +76,16 @@ public abstract class Map extends java.util.AbstractMap // try { - com.sleepycat.db.DbBtreeStat s = (com.sleepycat.db.DbBtreeStat)_db.stat(0); - return s.bt_ndata; + com.sleepycat.db.StatsConfig config = new com.sleepycat.db.StatsConfig(); + // + // TODO: DB_FAST_STAT doesn't seem to do what the + // documentation says... + // + //config.setFast(true); + com.sleepycat.db.BtreeStats s = (com.sleepycat.db.BtreeStats)_db.db().getStats(null, config); + return s.getNumData(); } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -134,9 +140,9 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.containsValue while iterating over Db \"" + _db.dbName() - + "\"; retrying ..."); + _connection.communicator().getLogger().warning("Deadlock in Freeze.Map.containsValue while " + + "iterating over Db \"" + _db.dbName() + + "\"; retrying..."); } // @@ -166,33 +172,31 @@ public abstract class Map extends java.util.AbstractMap byte[] k = encodeKey(key, _connection.communicator()); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); - dbValue.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); + dbValue.setPartial(true); if(_trace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", "checking key in Db \"" + _db.dbName() + "\""); + _connection.communicator().getLogger().trace("Freeze.Map", "checking key in Db \"" + _db.dbName() + "\""); } for(;;) { try { - int rc = _db.get(_connection.dbTxn(), dbKey, dbValue, 0); - if(rc == com.sleepycat.db.Db.DB_NOTFOUND) + com.sleepycat.db.OperationStatus rc = _db.db().get(_connection.dbTxn(), dbKey, dbValue, null); + if(rc == com.sleepycat.db.OperationStatus.SUCCESS) { - return false; + return true; } else { - assert(rc == 0); - return true; + return false; } } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(_connection.dbTxn() != null) { @@ -205,9 +209,9 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.containsKey while reading Db \"" + _db.dbName() - + "\"; retrying ..."); + _connection.communicator().getLogger().warning("Deadlock in Freeze.Map.containsKey while " + + "reading Db \"" + _db.dbName() + + "\"; retrying..."); } // @@ -215,7 +219,7 @@ public abstract class Map extends java.util.AbstractMap // } } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -229,7 +233,7 @@ public abstract class Map extends java.util.AbstractMap get(Object key) { byte[] k = encodeKey(key, _connection.communicator()); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); byte[] v = getImpl(dbKey); if(v == null) { @@ -245,7 +249,7 @@ public abstract class Map extends java.util.AbstractMap put(Object key, Object value) { byte[] k = encodeKey(key, _connection.communicator()); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); byte[] v = getImpl(dbKey); Object o = null; if(v != null) @@ -260,7 +264,7 @@ public abstract class Map extends java.util.AbstractMap remove(Object key) { byte[] k = encodeKey(key, _connection.communicator()); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); byte[] v = getImpl(dbKey); if(v != null && removeImpl(dbKey)) @@ -282,7 +286,7 @@ public abstract class Map extends java.util.AbstractMap fastPut(Object key, Object value) { byte[] k = encodeKey(key, _connection.communicator()); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); putImpl(dbKey, value); } @@ -293,7 +297,7 @@ public abstract class Map extends java.util.AbstractMap fastRemove(Object key) { byte[] k = encodeKey(key, _connection.communicator()); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); return removeImpl(dbKey); } @@ -307,16 +311,16 @@ public abstract class Map extends java.util.AbstractMap throw ex; } - com.sleepycat.db.DbTxn txn = _connection.dbTxn(); + com.sleepycat.db.Transaction txn = _connection.dbTxn(); for(;;) { try { - _db.truncate(txn, txn != null ? 0 : com.sleepycat.db.Db.DB_AUTO_COMMIT); + _db.db().truncate(txn, false); break; } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(txn != null) { @@ -329,9 +333,8 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.clear on Db \"" + _db.dbName() - + "\"; retrying ..."); + _connection.communicator().getLogger().warning("Deadlock in Freeze.Map.clear on Db \"" + + _db.dbName() + "\"; retrying..."); } // @@ -339,7 +342,7 @@ public abstract class Map extends java.util.AbstractMap // } } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -473,7 +476,7 @@ public abstract class Map extends java.util.AbstractMap } private byte[] - getImpl(com.sleepycat.db.Dbt dbKey) + getImpl(com.sleepycat.db.DatabaseEntry dbKey) { if(_db == null) { @@ -482,29 +485,29 @@ public abstract class Map extends java.util.AbstractMap throw ex; } - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); if(_trace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", "reading value from Db \"" + _db.dbName() + "\""); + _connection.communicator().getLogger().trace("Freeze.Map", "reading value from Db \"" + _db.dbName() + + "\""); } for(;;) { try { - int rc = _db.get(_connection.dbTxn(), dbKey, dbValue, 0); - if(rc == com.sleepycat.db.Db.DB_NOTFOUND) + com.sleepycat.db.OperationStatus rc = _db.db().get(_connection.dbTxn(), dbKey, dbValue, null); + if(rc == com.sleepycat.db.OperationStatus.SUCCESS) { - return null; + return dbValue.getData(); } else { - return dbValue.getData(); + return null; } } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(_connection.dbTxn() != null) { @@ -517,9 +520,9 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.getImpl while reading Db \"" + _db.dbName() - + "\"; retrying ..."); + _connection.communicator().getLogger().warning("Deadlock in Freeze.Map.getImpl while " + + "reading Db \"" + _db.dbName() + + "\"; retrying..."); } // @@ -527,7 +530,7 @@ public abstract class Map extends java.util.AbstractMap // } } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -538,7 +541,7 @@ public abstract class Map extends java.util.AbstractMap } private void - putImpl(com.sleepycat.db.Dbt dbKey, Object value) + putImpl(com.sleepycat.db.DatabaseEntry dbKey, Object value) { if(_db == null) { @@ -548,15 +551,14 @@ public abstract class Map extends java.util.AbstractMap } byte[] v = encodeValue(value, _connection.communicator()); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(v); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(v); if(_trace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", "writing value in Db \"" + _db.dbName() + "\""); + _connection.communicator().getLogger().trace("Freeze.Map", "writing value in Db \"" + _db.dbName() + "\""); } - com.sleepycat.db.DbTxn txn = _connection.dbTxn(); + com.sleepycat.db.Transaction txn = _connection.dbTxn(); if(txn == null) { closeAllIterators(); @@ -566,10 +568,10 @@ public abstract class Map extends java.util.AbstractMap { try { - _db.put(txn, dbKey, dbValue, txn != null ? 0 : com.sleepycat.db.Db.DB_AUTO_COMMIT); + _db.db().put(txn, dbKey, dbValue); break; } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(txn != null) { @@ -582,9 +584,9 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.putImpl while writing into Db \"" + _db.dbName() - + "\"; retrying ..."); + _connection.communicator().getLogger().warning("Deadlock in Freeze.Map.putImpl while " + + "writing into Db \"" + _db.dbName() + + "\"; retrying..."); } // @@ -592,7 +594,7 @@ public abstract class Map extends java.util.AbstractMap // } } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -603,7 +605,7 @@ public abstract class Map extends java.util.AbstractMap } private boolean - removeImpl(com.sleepycat.db.Dbt dbKey) + removeImpl(com.sleepycat.db.DatabaseEntry dbKey) { if(_db == null) { @@ -614,11 +616,11 @@ public abstract class Map extends java.util.AbstractMap if(_trace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", "deleting value from Db \"" + _db.dbName() + "\""); + _connection.communicator().getLogger().trace("Freeze.Map", "deleting value from Db \"" + _db.dbName() + + "\""); } - com.sleepycat.db.DbTxn txn = _connection.dbTxn(); + com.sleepycat.db.Transaction txn = _connection.dbTxn(); if(txn == null) { closeAllIterators(); @@ -628,10 +630,10 @@ public abstract class Map extends java.util.AbstractMap { try { - int rc = _db.delete(txn, dbKey, txn != null ? 0 : com.sleepycat.db.Db.DB_AUTO_COMMIT); - return (rc == 0); + com.sleepycat.db.OperationStatus rc = _db.db().delete(txn, dbKey); + return (rc == com.sleepycat.db.OperationStatus.SUCCESS); } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(txn != null) { @@ -644,9 +646,9 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.removeImpl while writing into Db \"" + _db.dbName() - + "\"; retrying ..."); + _connection.communicator().getLogger().warning("Deadlock in Freeze.Map.removeImpl while " + + "writing into Db \"" + _db.dbName() + + "\"; retrying..."); } // @@ -654,7 +656,7 @@ public abstract class Map extends java.util.AbstractMap // } } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -664,18 +666,17 @@ public abstract class Map extends java.util.AbstractMap } } - - protected abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate + protected abstract class Index implements com.sleepycat.db.SecondaryKeyCreator { // // Implementation details // - - public int - secondaryKeyCreate(com.sleepycat.db.Db secondary, - com.sleepycat.db.Dbt key, - com.sleepycat.db.Dbt value, - com.sleepycat.db.Dbt result) + public boolean + createSecondaryKey(com.sleepycat.db.SecondaryDatabase secondary, + com.sleepycat.db.DatabaseEntry key, + com.sleepycat.db.DatabaseEntry value, + com.sleepycat.db.DatabaseEntry result) + throws com.sleepycat.db.DatabaseException { Ice.Communicator communicator = _connection.getCommunicator(); byte[] secondaryKey = marshalKey(value.getData()); @@ -683,23 +684,10 @@ public abstract class Map extends java.util.AbstractMap result.setData(secondaryKey); result.setSize(secondaryKey.length); - return 0; + return true; } - - - // - // Alias for Berkeley DB 4.1.25 - // - public int - secondary_key_create(com.sleepycat.db.Db secondary, - com.sleepycat.db.Dbt key, - com.sleepycat.db.Dbt value, - com.sleepycat.db.Dbt result) - { - return secondaryKeyCreate(secondary, key, value, result); - } - - com.sleepycat.db.Db + + com.sleepycat.db.SecondaryDatabase db() { return _db; @@ -711,30 +699,22 @@ public abstract class Map extends java.util.AbstractMap } void - associate(String dbName, com.sleepycat.db.Db db, - com.sleepycat.db.DbTxn txn, boolean createDb) - throws com.sleepycat.db.DbException, java.io.FileNotFoundException + associate(String dbName, com.sleepycat.db.Database db, + com.sleepycat.db.Transaction txn, boolean createDb) + throws com.sleepycat.db.DatabaseException, java.io.FileNotFoundException { _dbName = dbName + "." + _name; assert(txn != null); assert(_db == null); - _db = new com.sleepycat.db.Db(_connection.dbEnv().getEnv(), 0); - _db.setFlags(com.sleepycat.db.Db.DB_DUP | com.sleepycat.db.Db.DB_DUPSORT); - - int flags = 0; - if(createDb) - { - flags = com.sleepycat.db.Db.DB_CREATE; - } - - _db.open(txn, _dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0); + com.sleepycat.db.SecondaryConfig config = new com.sleepycat.db.SecondaryConfig(); + config.setAllowCreate(createDb); + config.setAllowPopulate(true); // We always populate empty indices + config.setSortedDuplicates(true); + config.setType(com.sleepycat.db.DatabaseType.BTREE); + config.setKeyCreator(this); - // - // We always populate empty indices - // - flags = com.sleepycat.db.Db.DB_CREATE; - db.associate(txn, _db, this, flags); + _db = _connection.dbEnv().getEnv().openSecondaryDatabase(txn, _dbName, null, db, config); } void init(Index from) @@ -757,14 +737,13 @@ public abstract class Map extends java.util.AbstractMap { try { - _db.close(0); + _db.close(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); - ex.message = _errorPrefix + "Db.close for index \"" - + _dbName + "\": " + dx.getMessage(); + ex.message = _errorPrefix + "Db.close for index \"" + _dbName + "\": " + dx.getMessage(); throw ex; } _db = null; @@ -780,39 +759,37 @@ public abstract class Map extends java.util.AbstractMap public int untypedCount(byte[] k) { - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(k); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(k); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); // // dlen is 0, so we should not retrieve any value // - dbValue.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + dbValue.setPartial(true); try { for(;;) { - com.sleepycat.db.Dbc dbc = null; + com.sleepycat.db.Cursor dbc = null; try { - dbc = _db.cursor(null, 0); - boolean found = (dbc.get(dbKey, dbValue, com.sleepycat.db.Db.DB_SET) == 0); - - if(found) + dbc = _db.openCursor(null, null); + if(dbc.getSearchKey(dbKey, dbValue, null) == com.sleepycat.db.OperationStatus.SUCCESS) { - return dbc.count(0); + return dbc.count(); } else { return 0; } } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { if(_connection.deadlockWarning()) { - _connection.communicator().getLogger().warning - ("Deadlock in Freeze.Map.Index.untypedCount while iterating over index \"" - + _dbName + "\"; retrying ..."); + _connection.communicator().getLogger().warning( + "Deadlock in Freeze.Map.Index.untypedCount while iterating over index \"" + _dbName + + "\"; retrying..."); } // @@ -827,7 +804,7 @@ public abstract class Map extends java.util.AbstractMap { dbc.close(); } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { // // Ignored @@ -837,12 +814,11 @@ public abstract class Map extends java.util.AbstractMap } } } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); - ex.message = _errorPrefix + "Db.cursor for index \"" - + _dbName + "\": " + dx.getMessage(); + ex.message = _errorPrefix + "Db.cursor for index \"" + _dbName + "\": " + dx.getMessage(); throw ex; } } @@ -852,7 +828,7 @@ public abstract class Map extends java.util.AbstractMap private String _name; private String _dbName; - private com.sleepycat.db.Db _db; + private com.sleepycat.db.SecondaryDatabase _db; } @@ -871,22 +847,21 @@ public abstract class Map extends java.util.AbstractMap try { - com.sleepycat.db.DbTxn txn = _connection.dbTxn(); + com.sleepycat.db.Transaction txn = _connection.dbTxn(); if(txn == null) { // // Start transaction // - txn = _connection.dbEnv().getEnv().txnBegin(null, 0); + txn = _connection.dbEnv().getEnv().beginTransaction(null, null); _txn = txn; if(_connection.txTrace() >= 1) { - String txnId = Long.toHexString((_txn.id() & 0x7FFFFFFF) + 0x80000000L); + String txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L); - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "started transaction " + - txnId + " for cursor"); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "started transaction " + txnId + " for cursor"); } } @@ -895,14 +870,14 @@ public abstract class Map extends java.util.AbstractMap // if(index == null) { - _cursor = _db.cursor(txn, 0); + _cursor = _db.db().openCursor(txn, null); } else { - _cursor = index.db().cursor(txn, 0); + _cursor = index.db().openSecondaryCursor(txn, null); } } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { dead(); DeadlockException ex = new DeadlockException(); @@ -910,7 +885,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "EntryIterator constructor: " + dx.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { dead(); DatabaseException ex = new DatabaseException(); @@ -919,22 +894,21 @@ public abstract class Map extends java.util.AbstractMap throw ex; } - if(_indexed) { - com.sleepycat.db.Dbt dbIKey = new com.sleepycat.db.Dbt(k); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry dbIKey = new com.sleepycat.db.DatabaseEntry(k); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); try { - if(_cursor.get(dbIKey, dbKey, dbValue, com.sleepycat.db.Db.DB_SET) == 0) + com.sleepycat.db.SecondaryCursor c = (com.sleepycat.db.SecondaryCursor)_cursor; + if(c.getSearchKey(dbIKey, dbKey, dbValue, null) == com.sleepycat.db.OperationStatus.SUCCESS) { - _current = new Entry(this, Map.this, _connection.communicator(), - dbKey, dbValue.getData()); + _current = new Entry(this, Map.this, _connection.communicator(), dbKey, dbValue.getData()); } } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { dead(); DeadlockException ex = new DeadlockException(); @@ -942,7 +916,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "Dbc.get: " + dx.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { dead(); DatabaseException ex = new DatabaseException(); @@ -975,31 +949,31 @@ public abstract class Map extends java.util.AbstractMap // Move _cursor, set _current // - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); try { - int err; + com.sleepycat.db.OperationStatus err; if(_indexed) { - com.sleepycat.db.Dbt dbIKey = new com.sleepycat.db.Dbt(); + com.sleepycat.db.SecondaryCursor c = (com.sleepycat.db.SecondaryCursor)_cursor; + com.sleepycat.db.DatabaseEntry dbIKey = new com.sleepycat.db.DatabaseEntry(); // // dlen is 0, so we should not retrieve any value // - dbIKey.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + dbIKey.setPartial(true); - err = _cursor.get(dbIKey, dbKey, dbValue, com.sleepycat.db.Db.DB_NEXT_DUP); + err = c.getNextDup(dbIKey, dbKey, dbValue, null); } else { - err = _cursor.get(dbKey, dbValue, com.sleepycat.db.Db.DB_NEXT); + err = _cursor.getNext(dbKey, dbValue, null); } - if(err == 0) + if(err == com.sleepycat.db.OperationStatus.SUCCESS) { - _current = new Entry(this, Map.this, _connection.communicator(), - dbKey, dbValue.getData()); + _current = new Entry(this, Map.this, _connection.communicator(), dbKey, dbValue.getData()); return true; } else @@ -1007,7 +981,7 @@ public abstract class Map extends java.util.AbstractMap return false; } } - catch(com.sleepycat.db.DbDeadlockException dx) + catch(com.sleepycat.db.DeadlockException dx) { dead(); DeadlockException ex = new DeadlockException(); @@ -1015,7 +989,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "Dbc.get: " + dx.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -1063,12 +1037,12 @@ public abstract class Map extends java.util.AbstractMap { try { - if(_cursor.delete(0) == com.sleepycat.db.Db.DB_KEYEMPTY) + if(_cursor.delete() == com.sleepycat.db.OperationStatus.KEYEMPTY) { throw new IllegalStateException(); } } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { dead(); DeadlockException ex = new DeadlockException(); @@ -1076,7 +1050,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "Dbc.del: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -1099,30 +1073,30 @@ public abstract class Map extends java.util.AbstractMap throw new IllegalStateException(); } - com.sleepycat.db.Dbc clone = null; + com.sleepycat.db.Cursor clone = null; try { - clone = _cursor.dup(com.sleepycat.db.Db.DB_POSITION); + clone = _cursor.dup(true); // - // No interested in data + // Not interested in data // - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); - dbValue.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); + dbValue.setPartial(true); - int rc = clone.get(_lastReturned.getDbKey(), dbValue, com.sleepycat.db.Db.DB_SET); + com.sleepycat.db.OperationStatus rc = clone.getSearchKey(_lastReturned.getDbKey(), dbValue, null); - if(rc == com.sleepycat.db.Db.DB_NOTFOUND) + if(rc == com.sleepycat.db.OperationStatus.NOTFOUND) { throw new IllegalStateException(); } - if(clone.delete(0) == com.sleepycat.db.Db.DB_KEYEMPTY) + if(clone.delete() == com.sleepycat.db.OperationStatus.KEYEMPTY) { throw new IllegalStateException(); } } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { dead(); DeadlockException ex = new DeadlockException(); @@ -1130,7 +1104,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "EntryIterator.remove: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -1165,11 +1139,11 @@ public abstract class Map extends java.util.AbstractMap { if(finalizing && (_cursor != null || _txn != null) && _connection.closeInFinalizeWarning()) { - _connection.communicator().getLogger().warning - ("finalize() closing a live iterator on Map \"" + _db.dbName() + "\"; the application " - + "should have closed it earlier by calling Map.EntryIterator.close(), " - + "Map.closeAllIterators(), Map.close(), Connection.close(), or (if also " - + "leaking a transaction) Transaction.commit() or Transaction.rollback()"); + _connection.communicator().getLogger().warning( + "finalize() closing a live iterator on Map \"" + _db.dbName() + "\"; the application " + + "should have closed it earlier by calling Map.EntryIterator.close(), " + + "Map.closeAllIterators(), Map.close(), Connection.close(), or (if also " + + "leaking a transaction) Transaction.commit() or Transaction.rollback()"); } if(_iteratorListToken != null) @@ -1183,7 +1157,7 @@ public abstract class Map extends java.util.AbstractMap if(_cursor != null) { - com.sleepycat.db.Dbc cursor = _cursor; + com.sleepycat.db.Cursor cursor = _cursor; _cursor = null; closeCursor(cursor); } @@ -1196,26 +1170,24 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.txTrace() >= 1) { - txnId = Long.toHexString((_txn.id() & 0x7FFFFFFF) + 0x80000000L); + txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L); } - _txn.commit(0); + _txn.commit(); if(_connection.txTrace() >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "committed transaction " + - txnId); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "committed transaction " + txnId); } - } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(_connection.txTrace() >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to commit transaction " + - txnId + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to commit transaction " + txnId + ": " + + e.getMessage()); } DeadlockException ex = new DeadlockException(); @@ -1223,13 +1195,13 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "DbTxn.commit: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { if(_connection.txTrace() >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to commit transaction " + - txnId + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to commit transaction " + txnId + ": " + + e.getMessage()); } DatabaseException ex = new DatabaseException(); @@ -1283,13 +1255,13 @@ public abstract class Map extends java.util.AbstractMap // Yes, update it directly // byte[] v = encodeValue(value, _connection.communicator()); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(v); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(v); try { - _cursor.put(entry.getDbKey(), dbValue, com.sleepycat.db.Db.DB_CURRENT); + _cursor.putCurrent(dbValue); } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { dead(); DeadlockException ex = new DeadlockException(); @@ -1297,7 +1269,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "Dbc.put: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -1312,21 +1284,21 @@ public abstract class Map extends java.util.AbstractMap // element to update it (using the duplicate cursor) // - com.sleepycat.db.Dbc clone = null; + com.sleepycat.db.Cursor clone = null; try { - clone = _cursor.dup(com.sleepycat.db.Db.DB_POSITION); + clone = _cursor.dup(true); // // Not interested in data // - com.sleepycat.db.Dbt dummy = new com.sleepycat.db.Dbt(); - dummy.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + com.sleepycat.db.DatabaseEntry dummy = new com.sleepycat.db.DatabaseEntry(); + dummy.setPartial(true); - int rc = clone.get(entry.getDbKey(), dummy, com.sleepycat.db.Db.DB_SET); + com.sleepycat.db.OperationStatus rc = clone.getSearchKey(entry.getDbKey(), dummy, null); - if(rc == com.sleepycat.db.Db.DB_NOTFOUND) + if(rc == com.sleepycat.db.OperationStatus.NOTFOUND) { NotFoundException ex = new NotFoundException(); ex.message = _errorPrefix + "Dbc.get: DB_NOTFOUND"; @@ -1334,10 +1306,10 @@ public abstract class Map extends java.util.AbstractMap } byte[] v = encodeValue(value, _connection.communicator()); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(v); - clone.put(entry.getDbKey(), dbValue, com.sleepycat.db.Db.DB_CURRENT); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(v); + clone.putCurrent(dbValue); } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { dead(); DeadlockException ex = new DeadlockException(); @@ -1345,7 +1317,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "EntryIterator.setValue: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -1363,13 +1335,13 @@ public abstract class Map extends java.util.AbstractMap } private void - closeCursor(com.sleepycat.db.Dbc cursor) + closeCursor(com.sleepycat.db.Cursor cursor) { try { cursor.close(); } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { dead(); DeadlockException ex = new DeadlockException(); @@ -1377,7 +1349,7 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "Dbc.close: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { DatabaseException ex = new DatabaseException(); ex.initCause(e); @@ -1391,7 +1363,7 @@ public abstract class Map extends java.util.AbstractMap { if(_cursor != null) { - com.sleepycat.db.Dbc cursor = _cursor; + com.sleepycat.db.Cursor cursor = _cursor; _cursor = null; closeCursor(cursor); } @@ -1404,25 +1376,24 @@ public abstract class Map extends java.util.AbstractMap { if(_connection.txTrace() >= 1) { - txnId = Long.toHexString((_txn.id() & 0x7FFFFFFF) + 0x80000000L); + txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L); } _txn.abort(); if(_connection.txTrace() >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "rolled back transaction " + - txnId); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "rolled back transaction " + txnId); } } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(_connection.txTrace() >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to roll back transaction " + - txnId + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to roll back transaction " + txnId + + ": " + e.getMessage()); } DeadlockException ex = new DeadlockException(); @@ -1430,13 +1401,13 @@ public abstract class Map extends java.util.AbstractMap ex.message = _errorPrefix + "DbTxn.abort: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { if(_connection.txTrace() >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to roll back transaction " + - txnId + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to roll back transaction " + + txnId + ": " + e.getMessage()); } DatabaseException ex = new DatabaseException(); @@ -1451,8 +1422,8 @@ public abstract class Map extends java.util.AbstractMap } } - private com.sleepycat.db.DbTxn _txn; - private com.sleepycat.db.Dbc _cursor; + private com.sleepycat.db.Transaction _txn; + private com.sleepycat.db.Cursor _cursor; private Entry _current; private Entry _lastReturned; private java.util.Iterator _iteratorListToken; @@ -1464,7 +1435,7 @@ public abstract class Map extends java.util.AbstractMap { public Entry(Map.EntryIterator iterator, Map map, Ice.Communicator communicator, - com.sleepycat.db.Dbt dbKey, byte[] valueBytes) + com.sleepycat.db.DatabaseEntry dbKey, byte[] valueBytes) { _iterator = iterator; _map = map; @@ -1535,7 +1506,7 @@ public abstract class Map extends java.util.AbstractMap return getKey() + "=" + getValue(); } - com.sleepycat.db.Dbt + com.sleepycat.db.DatabaseEntry getDbKey() { return _dbKey; @@ -1550,7 +1521,7 @@ public abstract class Map extends java.util.AbstractMap private Map.EntryIterator _iterator; private Map _map; private Ice.Communicator _communicator; - private com.sleepycat.db.Dbt _dbKey; + private com.sleepycat.db.DatabaseEntry _dbKey; private byte[] _valueBytes; private Object _key; private boolean _haveKey = false; diff --git a/java/src/Freeze/ObjectStore.java b/java/src/Freeze/ObjectStore.java index 887e6d76cbf..dcf4da7ee30 100644 --- a/java/src/Freeze/ObjectStore.java +++ b/java/src/Freeze/ObjectStore.java @@ -45,26 +45,21 @@ class ObjectStore implements IceUtil.Store throw ex; } - com.sleepycat.db.DbEnv dbEnv = evictor.dbEnv().getEnv(); + com.sleepycat.db.Environment dbEnv = evictor.dbEnv().getEnv(); try { - _db = new com.sleepycat.db.Db(dbEnv, 0); - Transaction tx = connection.beginTransaction(); - com.sleepycat.db.DbTxn txn = Util.getTxn(tx); + com.sleepycat.db.Transaction txn = Util.getTxn(tx); // // TODO: FREEZE_DB_MODE // - int flags = 0; - if(createDb) - { - flags |= com.sleepycat.db.Db.DB_CREATE; - } - _db.open(txn, evictor.filename(), _dbName, com.sleepycat.db.Db.DB_BTREE, flags, 0); - - + com.sleepycat.db.DatabaseConfig config = new com.sleepycat.db.DatabaseConfig(); + config.setType(com.sleepycat.db.DatabaseType.BTREE); + config.setAllowCreate(createDb); + _db = dbEnv.openDatabase(txn, evictor.filename(), _dbName, config); + java.util.Iterator p = _indices.iterator(); while(p.hasNext()) { @@ -78,7 +73,7 @@ class ObjectStore implements IceUtil.Store catalogData.evictor = true; catalog.put(evictor.filename(), catalogData); } - + tx.commit(); } catch(java.io.FileNotFoundException dx) @@ -88,7 +83,7 @@ class ObjectStore implements IceUtil.Store ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -124,13 +119,13 @@ class ObjectStore implements IceUtil.Store close(); } } - + void close() { try { - _db.close(0); + _db.close(); java.util.Iterator p = _indices.iterator(); while(p.hasNext()) @@ -140,7 +135,7 @@ class ObjectStore implements IceUtil.Store } _indices.clear(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -154,25 +149,25 @@ class ObjectStore implements IceUtil.Store dbHasObject(Ice.Identity ident) { byte[] key = marshalKey(ident, _communicator); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(key); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(key); // // Keep 0 length since we're not interested in the data // - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); - dbValue.setFlags(com.sleepycat.db.Db.DB_DBT_PARTIAL); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); + dbValue.setPartial(true); for(;;) { try { - int err = _db.get(null, dbKey, dbValue, 0); + com.sleepycat.db.OperationStatus err = _db.get(null, dbKey, dbValue, null); - if(err == 0) + if(err == com.sleepycat.db.OperationStatus.SUCCESS) { return true; } - else if(err == com.sleepycat.db.Db.DB_NOTFOUND) + else if(err == com.sleepycat.db.OperationStatus.NOTFOUND) { return false; } @@ -181,21 +176,20 @@ class ObjectStore implements IceUtil.Store throw new DatabaseException(); } } - catch(com.sleepycat.db.DbDeadlockException deadlock) + catch(com.sleepycat.db.DeadlockException dx) { if(_evictor.deadlockWarning()) { - _communicator.getLogger().warning - ("Deadlock in Freeze.ObjectStore.dhHasObject while reading Db \"" - + _evictor.filename() + "/" + _dbName - + "\"; retrying ..."); + _communicator.getLogger().warning("Deadlock in Freeze.ObjectStore.dhHasObject while reading " + + "Db \"" + _evictor.filename() + "/" + _dbName + + "\"; retrying..."); } // // Ignored, try again // } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -206,19 +200,26 @@ class ObjectStore implements IceUtil.Store } void - save(byte[] key, byte[] value, byte status, com.sleepycat.db.DbTxn tx) - throws com.sleepycat.db.DbException + save(byte[] key, byte[] value, byte status, com.sleepycat.db.Transaction tx) + throws com.sleepycat.db.DatabaseException { switch(status) { case EvictorElement.created: case EvictorElement.modified: { - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(key); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(value); - int flags = (status == EvictorElement.created) ? com.sleepycat.db.Db.DB_NOOVERWRITE : 0; - int err = _db.put(tx, dbKey, dbValue, flags); - if(err != 0) + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(key); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(value); + com.sleepycat.db.OperationStatus err; + if(status == EvictorElement.created) + { + err = _db.putNoOverwrite(tx, dbKey, dbValue); + } + else + { + err = _db.put(tx, dbKey, dbValue); + } + if(err != com.sleepycat.db.OperationStatus.SUCCESS) { throw new DatabaseException(); } @@ -226,9 +227,9 @@ class ObjectStore implements IceUtil.Store } case EvictorElement.destroyed: { - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(key); - int err = _db.delete(tx, dbKey, 0); - if(err != 0) + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(key); + com.sleepycat.db.OperationStatus err = _db.delete(tx, dbKey); + if(err != com.sleepycat.db.OperationStatus.SUCCESS) { throw new DatabaseException(); } @@ -305,7 +306,7 @@ class ObjectStore implements IceUtil.Store return _cache; } - final com.sleepycat.db.Db + final com.sleepycat.db.Database db() { return _db; @@ -342,41 +343,39 @@ class ObjectStore implements IceUtil.Store byte[] key = marshalKey(ident, _communicator); - com.sleepycat.db.Dbt dbKey = new com.sleepycat.db.Dbt(key); - com.sleepycat.db.Dbt dbValue = new com.sleepycat.db.Dbt(); + com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(key); + com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); for(;;) { try { - int rs = _db.get(null, dbKey, dbValue, 0); + com.sleepycat.db.OperationStatus rs = _db.get(null, dbKey, dbValue, null); - if(rs == com.sleepycat.db.Db.DB_NOTFOUND) + if(rs == com.sleepycat.db.OperationStatus.NOTFOUND) { return null; } - else if (rs != 0) + else if (rs != com.sleepycat.db.OperationStatus.SUCCESS) { assert false; throw new DatabaseException(); } break; } - catch(com.sleepycat.db.DbDeadlockException deadlock) + catch(com.sleepycat.db.DeadlockException dx) { if(_evictor.deadlockWarning()) { - _communicator.getLogger().warning - ("Deadlock in Freeze.ObjectStore.load while reading Db \"" - + _evictor.filename() + "/" + _dbName - + "\"; retrying ..."); + _communicator.getLogger().warning("Deadlock in Freeze.ObjectStore.load while reading Db \"" + + _evictor.filename() + "/" + _dbName + "\"; retrying..."); } // // Ignored, try again // } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -394,18 +393,10 @@ class ObjectStore implements IceUtil.Store private final IceUtil.Cache _cache; - private com.sleepycat.db.Db _db; + private com.sleepycat.db.Database _db; private final String _facet; private final String _dbName; private final EvictorI _evictor; private final java.util.List _indices; private final Ice.Communicator _communicator; - } - - - - - - - diff --git a/java/src/Freeze/SharedDb.java b/java/src/Freeze/SharedDb.java index d187f4d4507..e192390db7e 100755 --- a/java/src/Freeze/SharedDb.java +++ b/java/src/Freeze/SharedDb.java @@ -9,11 +9,10 @@ package Freeze; -class SharedDb extends com.sleepycat.db.Db +class SharedDb { public static SharedDb - get(ConnectionI connection, String dbName, String key, String value, - Map.Index[] indices, boolean createDb) + get(ConnectionI connection, String dbName, String key, String value, Map.Index[] indices, boolean createDb) { MapKey mapKey = new MapKey(connection.envName(), connection.communicator(), dbName); @@ -37,7 +36,7 @@ class SharedDb extends com.sleepycat.db.Db { result = new SharedDb(mapKey, key, value, connection, indices, createDb); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -77,7 +76,7 @@ class SharedDb extends com.sleepycat.db.Db { result = new SharedDb(mapKey, dbEnv.getEnv()); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -90,6 +89,12 @@ class SharedDb extends com.sleepycat.db.Db } } + public com.sleepycat.db.Database + db() + { + return _db; + } + public String dbName() { @@ -122,9 +127,9 @@ class SharedDb extends com.sleepycat.db.Db { cleanupIndices(); - super.close(0); + _db.close(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -141,11 +146,10 @@ class SharedDb extends com.sleepycat.db.Db assert(_refCount == 0); } - private SharedDb(MapKey mapKey, String key, String value, - ConnectionI connection, Map.Index[] indices, - boolean createDb) throws com.sleepycat.db.DbException + private SharedDb(MapKey mapKey, String key, String value, ConnectionI connection, Map.Index[] indices, + boolean createDb) + throws com.sleepycat.db.DatabaseException { - super(connection.dbEnv().getEnv(), 0); _mapKey = mapKey; _indices = indices; _trace = connection.trace(); @@ -161,7 +165,6 @@ class SharedDb extends com.sleepycat.db.Db if(catalogData.evictor) { DatabaseException ex = new DatabaseException(); - ex.message = errorPrefix(_mapKey) + "is not an evictor"; throw ex; } @@ -178,27 +181,24 @@ class SharedDb extends com.sleepycat.db.Db try { Transaction tx = catalogConnection.beginTransaction(); - com.sleepycat.db.DbTxn txn = Util.getTxn(tx); + com.sleepycat.db.Transaction txn = Util.getTxn(tx); + + com.sleepycat.db.DatabaseConfig config = new com.sleepycat.db.DatabaseConfig(); + config.setAllowCreate(createDb); + config.setType(com.sleepycat.db.DatabaseType.BTREE); - int flags = 0; - - if(createDb) - { - flags |= com.sleepycat.db.Db.DB_CREATE; - } - if(_trace >= 1) { _mapKey.communicator.getLogger().trace("Freeze.Map", "opening Db \"" + _mapKey.dbName + "\""); } - - open(txn, mapKey.dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0); - + + _db = connection.dbEnv().getEnv().openDatabase(txn, mapKey.dbName, null, config); + if(_indices != null) { for(int i = 0; i < _indices.length; ++i) { - _indices[i].associate(mapKey.dbName, this, txn, createDb); + _indices[i].associate(mapKey.dbName, _db, txn, createDb); } } @@ -225,7 +225,7 @@ class SharedDb extends com.sleepycat.db.Db ex.message = errorPrefix(_mapKey) + "Db.open: " + dx.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { cleanupIndices(); DatabaseException ex = new DatabaseException(); @@ -256,9 +256,9 @@ class SharedDb extends com.sleepycat.db.Db _refCount = 1; } - private SharedDb(MapKey mapKey, com.sleepycat.db.DbEnv dbEnv) throws com.sleepycat.db.DbException + private SharedDb(MapKey mapKey, com.sleepycat.db.Environment dbEnv) + throws com.sleepycat.db.DatabaseException { - super(dbEnv, 0); _mapKey = mapKey; _key = "string"; _value = "::Freeze::CatalogData"; @@ -267,12 +267,15 @@ class SharedDb extends com.sleepycat.db.Db { _mapKey.communicator.getLogger().trace("Freeze.Map", "opening Db \"" + _mapKey.dbName + "\""); } - - int flags = com.sleepycat.db.Db.DB_CREATE | com.sleepycat.db.Db.DB_AUTO_COMMIT; + + com.sleepycat.db.DatabaseConfig config = new com.sleepycat.db.DatabaseConfig(); + config.setAllowCreate(true); + config.setType(com.sleepycat.db.DatabaseType.BTREE); + config.setTransactional(true); try { - open(null, mapKey.dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0); + _db = dbEnv.openDatabase(null, mapKey.dbName, null, config); } catch(java.io.FileNotFoundException dx) { @@ -313,7 +316,6 @@ class SharedDb extends com.sleepycat.db.Db _indices = null; } } - private static void checkTypes(SharedDb sharedDb, String key, String value) @@ -321,15 +323,15 @@ class SharedDb extends com.sleepycat.db.Db if(!key.equals(sharedDb._key)) { DatabaseException ex = new DatabaseException(); - ex.message = errorPrefix(sharedDb._mapKey) + - sharedDb.dbName() + "'s key type is " + sharedDb._key + ", not " + key; + ex.message = errorPrefix(sharedDb._mapKey) + sharedDb.dbName() + "'s key type is " + sharedDb._key + + ", not " + key; throw ex; } if(!value.equals(sharedDb._value)) { DatabaseException ex = new DatabaseException(); - ex.message = errorPrefix(sharedDb._mapKey) + - sharedDb.dbName() + "'s value type is " + sharedDb._value + ", not " + value; + ex.message = errorPrefix(sharedDb._mapKey) + sharedDb.dbName() + "'s value type is " + sharedDb._value + + ", not " + value; throw ex; } } @@ -378,6 +380,7 @@ class SharedDb extends com.sleepycat.db.Db } } + private com.sleepycat.db.Database _db; private MapKey _mapKey; private String _key; private String _value; @@ -390,4 +393,3 @@ class SharedDb extends com.sleepycat.db.Db // private static java.util.Map _map = new java.util.HashMap(); } - diff --git a/java/src/Freeze/SharedDbEnv.java b/java/src/Freeze/SharedDbEnv.java index a44524075f4..249576ef9ae 100644 --- a/java/src/Freeze/SharedDbEnv.java +++ b/java/src/Freeze/SharedDbEnv.java @@ -9,10 +9,10 @@ package Freeze; -class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable +class SharedDbEnv implements com.sleepycat.db.ErrorHandler, Runnable { public static SharedDbEnv - get(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv) + get(Ice.Communicator communicator, String envName, com.sleepycat.db.Environment dbEnv) { MapKey key = new MapKey(envName, communicator); @@ -27,7 +27,7 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable { result = new SharedDbEnv(key, dbEnv); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -63,7 +63,7 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable return _key.communicator; } - public com.sleepycat.db.DbEnv + public com.sleepycat.db.Environment getEnv() { return _dbEnv; @@ -124,8 +124,8 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable if(_trace >= 1) { - _key.communicator.getLogger().trace - ("Freeze.DbEnv", "closing database environment \"" + _key.envName + "\""); + _key.communicator.getLogger().trace("Freeze.DbEnv", "closing database environment \"" + + _key.envName + "\""); } // @@ -134,9 +134,9 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable // try { - _dbEnv.close(0); + _dbEnv.close(); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { DatabaseException ex = new DatabaseException(); ex.initCause(dx); @@ -147,7 +147,6 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable } } - public void run() { @@ -175,28 +174,28 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable if(_trace >= 2) { - _key.communicator.getLogger().trace - ("Freeze.DbEnv", "checkpointing environment \"" + _key.envName + "\""); + _key.communicator.getLogger().trace("Freeze.DbEnv", "checkpointing environment \"" + _key.envName + + "\""); } try { - _dbEnv.txnCheckpoint(_kbyte, 0, 0); + com.sleepycat.db.CheckpointConfig config = new com.sleepycat.db.CheckpointConfig(); + config.setKBytes(_kbyte); + _dbEnv.checkpoint(config); } - catch(com.sleepycat.db.DbException dx) + catch(com.sleepycat.db.DatabaseException dx) { - _key.communicator.getLogger().warning( - "checkpoint on DbEnv \"" + _key.envName + "\" raised DbException: " - + dx.getMessage()); + _key.communicator.getLogger().warning("checkpoint on DbEnv \"" + _key.envName + + "\" raised DbException: " + dx.getMessage()); } } } public void - error(String errorPrefix, String message) + error(com.sleepycat.db.Environment env, String errorPrefix, String message) { - _key.communicator.getLogger().error - ("Freeze database error in DbEnv \"" + _key.envName + "\": " + message); + _key.communicator.getLogger().error("Freeze database error in DbEnv \"" + _key.envName + "\": " + message); } protected void @@ -205,73 +204,68 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable assert(_refCount == 0); } - private SharedDbEnv(MapKey key, com.sleepycat.db.DbEnv dbEnv) throws com.sleepycat.db.DbException + private + SharedDbEnv(MapKey key, com.sleepycat.db.Environment dbEnv) + throws com.sleepycat.db.DatabaseException { _key = key; _dbEnv = dbEnv; _ownDbEnv = (dbEnv == null); - + Ice.Properties properties = key.communicator.getProperties(); _trace = properties.getPropertyAsInt("Freeze.Trace.DbEnv"); - + if(_ownDbEnv) { - _dbEnv = new com.sleepycat.db.DbEnv(0); + com.sleepycat.db.EnvironmentConfig config = new com.sleepycat.db.EnvironmentConfig(); + + config.setErrorHandler(this); + config.setInitializeLocking(true); + config.setInitializeLogging(true); + config.setInitializeCache(true); + config.setAllowCreate(true); + config.setTransactional(true); - if(_trace >= 1) - { - _key.communicator.getLogger().trace - ("Freeze.DbEnv", "opening database environment \"" + _key.envName + "\""); - } - - String propertyPrefix = "Freeze.DbEnv." + _key.envName; - - _dbEnv.setErrorHandler(this); - // // Deadlock detection // - _dbEnv.setLockDetect(com.sleepycat.db.Db.DB_LOCK_YOUNGEST); - - int flags = com.sleepycat.db.Db.DB_INIT_LOCK | - com.sleepycat.db.Db.DB_INIT_LOG | - com.sleepycat.db.Db.DB_INIT_MPOOL | - com.sleepycat.db.Db.DB_INIT_TXN; - - if(properties.getPropertyAsInt( - propertyPrefix + ".DbRecoverFatal") != 0) + config.setLockDetectMode(com.sleepycat.db.LockDetectMode.YOUNGEST); + + String propertyPrefix = "Freeze.DbEnv." + _key.envName; + if(properties.getPropertyAsInt(propertyPrefix + ".DbRecoverFatal") != 0) { - flags |= com.sleepycat.db.Db.DB_RECOVER_FATAL | - com.sleepycat.db.Db.DB_CREATE; + config.setRunFatalRecovery(true); } else { - flags |= com.sleepycat.db.Db. DB_RECOVER | - com.sleepycat.db.Db.DB_CREATE; + config.setRunRecovery(true); } - - if(properties.getPropertyAsIntWithDefault( - propertyPrefix + ".DbPrivate", 1) != 0) + + if(properties.getPropertyAsIntWithDefault(propertyPrefix + ".DbPrivate", 1) != 0) { - flags |= com.sleepycat.db.Db.DB_PRIVATE; + config.setPrivate(true); } - - if(properties.getPropertyAsIntWithDefault - (propertyPrefix + ".OldLogsAutoDelete", 1) != 0) + + if(properties.getPropertyAsIntWithDefault(propertyPrefix + ".OldLogsAutoDelete", 1) != 0) { - flags |= com.sleepycat.db.Db.DB_LOG_AUTOREMOVE; + config.setLogAutoRemove(true); } - - String dbHome = properties.getPropertyWithDefault( - propertyPrefix + ".DbHome", _key.envName); - + + if(_trace >= 1) + { + _key.communicator.getLogger().trace("Freeze.DbEnv", "opening database environment \"" + + _key.envName + "\""); + } + // // TODO: FREEZE_DB_MODE // try { - _dbEnv.open(dbHome, flags, 0); + String dbHome = properties.getPropertyWithDefault(propertyPrefix + ".DbHome", _key.envName); + java.io.File home = new java.io.File(dbHome); + _dbEnv = new com.sleepycat.db.Environment(home, config); } catch(java.io.FileNotFoundException dx) { @@ -284,13 +278,11 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable // // Default checkpoint period is every 120 seconds // - _checkpointPeriod = properties.getPropertyAsIntWithDefault - (propertyPrefix + ".CheckpointPeriod", 120) * 1000; - - _kbyte = properties.getPropertyAsIntWithDefault - (propertyPrefix + ".PeriodicCheckpointMinSize", 0); - + _checkpointPeriod = + properties.getPropertyAsIntWithDefault(propertyPrefix + ".CheckpointPeriod", 120) * 1000; + _kbyte = properties.getPropertyAsIntWithDefault(propertyPrefix + ".PeriodicCheckpointMinSize", 0); + String threadName; String programName = properties.getProperty("Ice.ProgramName"); if(programName.length() > 0) @@ -302,8 +294,7 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable threadName = ""; } threadName += "FreezeCheckpointThread(" + _key.envName + ")"; - - + if(_checkpointPeriod > 0) { _thread = new Thread(this, threadName); @@ -314,7 +305,8 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable _refCount = 1; } - private synchronized void init() + private synchronized void + init() { if(_catalog == null) { @@ -325,7 +317,7 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable private static String errorPrefix(String envName) { - return "DbEnv(\"" + envName + "\"): "; + return "DbEnv(\"" + envName + "\"): "; } private static class MapKey @@ -361,7 +353,7 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable } private MapKey _key; - private com.sleepycat.db.DbEnv _dbEnv; + private com.sleepycat.db.Environment _dbEnv; private boolean _ownDbEnv; private SharedDb _catalog; private int _refCount = 0; @@ -376,4 +368,3 @@ class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable // private static java.util.Map _map = new java.util.HashMap(); } - diff --git a/java/src/Freeze/TransactionI.java b/java/src/Freeze/TransactionI.java index 816a99b7c77..0ba551c887d 100755 --- a/java/src/Freeze/TransactionI.java +++ b/java/src/Freeze/TransactionI.java @@ -22,25 +22,24 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction if(_txTrace >= 1) { - txnId = Long.toHexString((_txn.id() & 0x7FFFFFFF) + 0x80000000L); + txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L); } - _txn.commit(0); + _txn.commit(); if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "committed transaction " + txnId); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + "committed transaction " + + txnId); } - } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to commit transaction " + txnId - + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to commit transaction " + txnId + ": " + + e.getMessage()); } DeadlockException ex = new DeadlockException(); @@ -48,13 +47,13 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction ex.message = _errorPrefix + "DbTxn.commit: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to commit transaction " + txnId - + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to commit transaction " + txnId + ": " + + e.getMessage()); } DatabaseException ex = new DatabaseException(); @@ -81,25 +80,24 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction if(_txTrace >= 1) { - txnId = Long.toHexString((_txn.id() & 0x7FFFFFFF) + 0x80000000L); + txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L); } _txn.abort(); if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "rolled back transaction " + txnId); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + "rolled back transaction " + + txnId); } - } - catch(com.sleepycat.db.DbDeadlockException e) + catch(com.sleepycat.db.DeadlockException e) { if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to rollback transaction " + txnId - + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to rollback transaction " + txnId + ": " + + e.getMessage()); } DeadlockException ex = new DeadlockException(); @@ -107,13 +105,13 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction ex.message = _errorPrefix + "DbTxn.abort: " + e.getMessage(); throw ex; } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to rollback transaction " + txnId - + ": " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to rollback transaction " + txnId + ": " + + e.getMessage()); } DatabaseException ex = new DatabaseException(); @@ -137,23 +135,22 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction try { - _txn = _connection.dbEnv().getEnv().txnBegin(null, 0); + _txn = _connection.dbEnv().getEnv().beginTransaction(null, null); if(_txTrace >= 1) { - String txnId = Long.toHexString((_txn.id() & 0x7FFFFFFF) + 0x80000000L); + String txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L); - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "started transaction " + txnId); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + "started transaction " + + txnId); } - } - catch(com.sleepycat.db.DbException e) + catch(com.sleepycat.db.DatabaseException e) { if(_txTrace >= 1) { - _connection.communicator().getLogger().trace - ("Freeze.Map", _errorPrefix + "failed to start transaction: " + e.getMessage()); + _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + + "failed to start transaction: " + e.getMessage()); } DatabaseException ex = new DatabaseException(); @@ -163,7 +160,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction } } - com.sleepycat.db.DbTxn + com.sleepycat.db.Transaction dbTxn() { return _txn; @@ -171,7 +168,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction private ConnectionI _connection; private int _txTrace; - private com.sleepycat.db.DbTxn _txn; + private com.sleepycat.db.Transaction _txn; private String _errorPrefix; } diff --git a/java/src/Freeze/Util.java b/java/src/Freeze/Util.java index 4019c2dd4cf..241cf8a074c 100644 --- a/java/src/Freeze/Util.java +++ b/java/src/Freeze/Util.java @@ -11,17 +11,15 @@ package Freeze; public class Util { - public static Evictor - createEvictor(Ice.ObjectAdapter adapter, String envName, String filename, - ServantInitializer initializer, Index[] indices, boolean createDb) + createEvictor(Ice.ObjectAdapter adapter, String envName, String filename, ServantInitializer initializer, + Index[] indices, boolean createDb) { return new EvictorI(adapter, envName, filename, initializer, indices, createDb); } public static Evictor - createEvictor(Ice.ObjectAdapter adapter, String envName, - com.sleepycat.db.DbEnv dbEnv, String filename, + createEvictor(Ice.ObjectAdapter adapter, String envName, com.sleepycat.db.Environment dbEnv, String filename, ServantInitializer initializer, Index[] indices, boolean createDb) { return new EvictorI(adapter, envName, dbEnv, filename, initializer, indices, createDb); @@ -34,17 +32,17 @@ public class Util } public static Connection - createConnection(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv) + createConnection(Ice.Communicator communicator, String envName, com.sleepycat.db.Environment dbEnv) { return new ConnectionI(communicator, envName, dbEnv); - } + } public static String catalogName() { return _catalogName; } - - public static com.sleepycat.db.DbTxn + + public static com.sleepycat.db.Transaction getTxn(Transaction tx) { try @@ -57,7 +55,6 @@ public class Util } } - public static synchronized FatalErrorCallback registerFatalErrorCallback(FatalErrorCallback cb) { @@ -79,8 +76,6 @@ public class Util } } - private static String _catalogName = "__catalog"; private static FatalErrorCallback _fatalErrorCallback = null; } - |