summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-05-30 13:18:35 +0000
committerBernard Normier <bernard@zeroc.com>2007-05-30 13:18:35 +0000
commitcd8abbb04a79b0d93f34742c49b06607e4e989f7 (patch)
treefabe04903dac6bd3ecf2ac6f3248ab5c22300fa7 /java
parentfix problem with possible use of uninitialized local variable (diff)
downloadice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.tar.bz2
ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.tar.xz
ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.zip
Removed transactional evictor context
Diffstat (limited to 'java')
-rw-r--r--java/CHANGES4
-rw-r--r--java/src/Freeze/BackgroundSaveEvictorI.java2
-rwxr-xr-xjava/src/Freeze/ConnectionI.java4
-rw-r--r--java/src/Freeze/EvictorI.java4
-rw-r--r--java/src/Freeze/EvictorIteratorI.java4
-rw-r--r--java/src/Freeze/Index.java8
-rw-r--r--java/src/Freeze/ObjectStore.java52
-rw-r--r--java/src/Freeze/PostCompletionCallback.java15
-rw-r--r--java/src/Freeze/SharedDbEnv.java56
-rwxr-xr-xjava/src/Freeze/TransactionI.java81
-rw-r--r--java/src/Freeze/TransactionalEvictorContext.java (renamed from java/src/Freeze/TransactionalEvictorContextI.java)108
-rw-r--r--java/src/Freeze/TransactionalEvictorI.java75
12 files changed, 264 insertions, 149 deletions
diff --git a/java/CHANGES b/java/CHANGES
index 1d30c87ef58..030c332e546 100644
--- a/java/CHANGES
+++ b/java/CHANGES
@@ -1,6 +1,10 @@
Changes since version 3.2.X (binary incompabible)
-------------------------------------------------
+- Freeze evictor update:
+ - the existing evictor was renamed BackgroundSaveEvictor
+ - added new TransactionalEvictor
+
- Added support for udp multicast. See manual for more information.
- If a proxy contains a host which is multihomed, the client will now
diff --git a/java/src/Freeze/BackgroundSaveEvictorI.java b/java/src/Freeze/BackgroundSaveEvictorI.java
index 488adabadca..ca740cfa1b7 100644
--- a/java/src/Freeze/BackgroundSaveEvictorI.java
+++ b/java/src/Freeze/BackgroundSaveEvictorI.java
@@ -1366,7 +1366,7 @@ class BackgroundSaveEvictorI extends EvictorI implements BackgroundSaveEvictor,
}
}
- protected com.sleepycat.db.Transaction
+ protected TransactionI
beforeQuery()
{
saveNow();
diff --git a/java/src/Freeze/ConnectionI.java b/java/src/Freeze/ConnectionI.java
index 053d32fd353..517cc831da8 100755
--- a/java/src/Freeze/ConnectionI.java
+++ b/java/src/Freeze/ConnectionI.java
@@ -88,7 +88,7 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection
}
- if(_dbEnv != null && _ownDbEnv)
+ if(_dbEnv != null)
{
try
{
@@ -117,7 +117,6 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection
ConnectionI(Ice.Communicator communicator, String envName, com.sleepycat.db.Environment dbEnv)
{
this(SharedDbEnv.get(communicator, envName, dbEnv));
- _ownDbEnv = true;
}
@@ -213,7 +212,6 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection
private Ice.Communicator _communicator;
private SharedDbEnv _dbEnv;
- private boolean _ownDbEnv = false;
private String _envName;
private TransactionI _transaction;
private LinkedList _mapList = new Freeze.LinkedList();
diff --git a/java/src/Freeze/EvictorI.java b/java/src/Freeze/EvictorI.java
index 21d6d633036..0d029e81477 100644
--- a/java/src/Freeze/EvictorI.java
+++ b/java/src/Freeze/EvictorI.java
@@ -256,7 +256,7 @@ abstract class EvictorI extends Ice.LocalObjectImpl implements Evictor
{
facet = "";
}
- com.sleepycat.db.Transaction tx = beforeQuery();
+ TransactionI tx = beforeQuery();
return new EvictorIteratorI(findStore(facet, false), tx, batchSize);
}
finally
@@ -414,7 +414,7 @@ abstract class EvictorI extends Ice.LocalObjectImpl implements Evictor
this(adapter, envName, null, filename, facetTypes, initializer, indices, createDb);
}
- abstract com.sleepycat.db.Transaction beforeQuery();
+ abstract TransactionI beforeQuery();
static void
updateStats(Statistics stats, long time)
diff --git a/java/src/Freeze/EvictorIteratorI.java b/java/src/Freeze/EvictorIteratorI.java
index 437f527f0f7..c96a1fdd7ce 100644
--- a/java/src/Freeze/EvictorIteratorI.java
+++ b/java/src/Freeze/EvictorIteratorI.java
@@ -38,12 +38,12 @@ class EvictorIteratorI extends Ice.LocalObjectImpl implements EvictorIterator
}
}
- EvictorIteratorI(ObjectStore store, com.sleepycat.db.Transaction tx, int batchSize)
+ EvictorIteratorI(ObjectStore store, TransactionI tx, int batchSize)
{
_store = store;
_more = (store != null);
_batchSize = batchSize;
- _tx = tx;
+ _tx = tx == null ? null : tx.dbTxn();
assert batchSize > 0;
diff --git a/java/src/Freeze/Index.java b/java/src/Freeze/Index.java
index 42e72107baf..153640b4133 100644
--- a/java/src/Freeze/Index.java
+++ b/java/src/Freeze/Index.java
@@ -86,8 +86,9 @@ public abstract class Index implements com.sleepycat.db.SecondaryKeyCreator
Ice.Communicator communicator = _store.communicator();
- com.sleepycat.db.Transaction tx = _store.evictor().beforeQuery();
-
+ TransactionI transaction = _store.evictor().beforeQuery();
+ com.sleepycat.db.Transaction tx = transaction == null ? null : transaction.dbTxn();
+
java.util.List identities;
for(;;)
@@ -229,7 +230,8 @@ public abstract class Index implements com.sleepycat.db.SecondaryKeyCreator
// dlen is 0, so we should not retrieve any value
//
value.setPartial(true);
- com.sleepycat.db.Transaction tx = _store.evictor().beforeQuery();
+ TransactionI transaction = _store.evictor().beforeQuery();
+ com.sleepycat.db.Transaction tx = transaction == null ? null : transaction.dbTxn();
for(;;)
{
diff --git a/java/src/Freeze/ObjectStore.java b/java/src/Freeze/ObjectStore.java
index c2425c5bba5..41421446a19 100644
--- a/java/src/Freeze/ObjectStore.java
+++ b/java/src/Freeze/ObjectStore.java
@@ -153,8 +153,20 @@ class ObjectStore implements IceUtil.Store
}
boolean
- dbHasObject(Ice.Identity ident, com.sleepycat.db.Transaction tx)
+ dbHasObject(Ice.Identity ident, TransactionI transaction)
{
+ com.sleepycat.db.Transaction tx = null;
+
+ if(transaction != null)
+ {
+ tx = transaction.dbTxn();
+ if(tx == null)
+ {
+ throw new DatabaseException(_evictor.errorPrefix() + "inactive transaction");
+ }
+ }
+
+
byte[] key = marshalKey(ident, _communicator);
com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(key);
@@ -421,10 +433,14 @@ class ObjectStore implements IceUtil.Store
ObjectRecord
load(Ice.Identity ident, TransactionI transaction)
{
+ if(transaction == null)
+ {
+ throw new DatabaseException(_evictor.errorPrefix() + "no active transaction");
+ }
com.sleepycat.db.Transaction tx = transaction.dbTxn();
if(tx == null)
{
- throw new DatabaseException(_evictor.errorPrefix() + "invalid TransactionalEvictorContext");
+ throw new DatabaseException(_evictor.errorPrefix() + "inactive transaction");
}
byte[] key = marshalKey(ident, _communicator);
@@ -476,10 +492,14 @@ class ObjectStore implements IceUtil.Store
void
update(Ice.Identity ident, ObjectRecord objectRecord, TransactionI transaction)
{
+ if(transaction == null)
+ {
+ throw new DatabaseException(_evictor.errorPrefix() + "no active transaction");
+ }
com.sleepycat.db.Transaction tx = transaction.dbTxn();
if(tx == null)
{
- throw new DatabaseException(_evictor.errorPrefix() + "invalid TransactionalEvictorContext");
+ throw new DatabaseException(_evictor.errorPrefix() + "inactive transaction");
}
if(_sampleServant != null && !objectRecord.servant.ice_id().equals(_sampleServant.ice_id()))
@@ -524,8 +544,19 @@ class ObjectStore implements IceUtil.Store
}
boolean
- insert(Ice.Identity ident, ObjectRecord objectRecord, com.sleepycat.db.Transaction tx)
+ insert(Ice.Identity ident, ObjectRecord objectRecord, TransactionI transaction)
{
+ com.sleepycat.db.Transaction tx = null;
+
+ if(transaction != null)
+ {
+ tx = transaction.dbTxn();
+ if(tx == null)
+ {
+ throw new DatabaseException(_evictor.errorPrefix() + "invalid transaction");
+ }
+ }
+
com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(marshalKey(ident, _communicator));
com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(marshalValue(objectRecord, _communicator));
@@ -573,8 +604,19 @@ class ObjectStore implements IceUtil.Store
}
boolean
- remove(Ice.Identity ident, com.sleepycat.db.Transaction tx)
+ remove(Ice.Identity ident, TransactionI transaction)
{
+ com.sleepycat.db.Transaction tx = null;
+
+ if(transaction != null)
+ {
+ tx = transaction.dbTxn();
+ if(tx == null)
+ {
+ throw new DatabaseException(_evictor.errorPrefix() + "invalid transaction");
+ }
+ }
+
com.sleepycat.db.DatabaseEntry dbKey = new com.sleepycat.db.DatabaseEntry(marshalKey(ident, _communicator));
for(;;)
diff --git a/java/src/Freeze/PostCompletionCallback.java b/java/src/Freeze/PostCompletionCallback.java
new file mode 100644
index 00000000000..a8f52d28d1b
--- /dev/null
+++ b/java/src/Freeze/PostCompletionCallback.java
@@ -0,0 +1,15 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+package Freeze;
+
+interface PostCompletionCallback
+{
+ void postCompletion(boolean committed, boolean deadlock);
+}
diff --git a/java/src/Freeze/SharedDbEnv.java b/java/src/Freeze/SharedDbEnv.java
index 11233f95536..35940fc9425 100644
--- a/java/src/Freeze/SharedDbEnv.java
+++ b/java/src/Freeze/SharedDbEnv.java
@@ -205,49 +205,49 @@ class SharedDbEnv implements com.sleepycat.db.ErrorHandler, Runnable
//
- // Get/create an evictor context associated with the calling thread
+ // Create an evictor context associated with the calling thread
//
- synchronized TransactionalEvictorContextI
- getOrCreateCurrent(Ice.BooleanHolder created)
+ synchronized TransactionalEvictorContext
+ createCurrent()
{
- if(created != null)
- {
- created.value = false;
- }
-
Object k = Thread.currentThread();
- TransactionalEvictorContextI ctx = (TransactionalEvictorContextI)_ctxMap.get(k);
- if(ctx == null)
- {
- ctx = new TransactionalEvictorContextI(this);
-
- if(created != null)
- {
- created.value = true;
- }
- _ctxMap.put(k, ctx);
- }
+ TransactionalEvictorContext ctx = (TransactionalEvictorContext)_ctxMap.get(k);
+ assert ctx == null;
+
+ ctx = new TransactionalEvictorContext(this);
+ _refCount++; // owned by the underlying ConnectionI
+ _ctxMap.put(k, ctx);
+
return ctx;
}
- synchronized TransactionalEvictorContextI
+ synchronized TransactionalEvictorContext
getCurrent()
{
Object k = Thread.currentThread();
- return (TransactionalEvictorContextI)_ctxMap.get(k);
+ return (TransactionalEvictorContext)_ctxMap.get(k);
}
- //
- // Clear evictor context associated with the calling thread
- //
synchronized void
- clearCurrent(TransactionalEvictorContextI oldCtx)
+ setCurrentTransaction(Transaction tx)
{
- Object removedCtx = _ctxMap.remove(Thread.currentThread());
- assert removedCtx == oldCtx;
- }
+ Object k = Thread.currentThread();
+ if(tx != null)
+ {
+ TransactionalEvictorContext ctx = (TransactionalEvictorContext)_ctxMap.get(k);
+ if(ctx == null || !tx.equals(ctx.transaction()))
+ {
+ ctx = new TransactionalEvictorContext((TransactionI)tx);
+ _ctxMap.put(k, ctx);
+ }
+ }
+ else
+ {
+ _ctxMap.put(k, null);
+ }
+ }
private
SharedDbEnv(MapKey key, com.sleepycat.db.Environment dbEnv)
diff --git a/java/src/Freeze/TransactionI.java b/java/src/Freeze/TransactionI.java
index 7d4f7715661..3c97a843426 100755
--- a/java/src/Freeze/TransactionI.java
+++ b/java/src/Freeze/TransactionI.java
@@ -14,7 +14,14 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
public void
commit()
{
+ if(_txn == null)
+ {
+ throw new DatabaseException(_errorPrefix + "inactive transaction");
+ }
+
String txnId = null;
+ boolean committed = false;
+ boolean deadlock = false;
try
{
@@ -26,18 +33,21 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
}
_txn.commit();
+ committed = true;
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + "committed transaction " +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix + "committed transaction " +
txnId);
}
}
catch(com.sleepycat.db.DeadlockException e)
{
+ deadlock = true;
+
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix +
"failed to commit transaction " + txnId + ": " +
e.getMessage());
}
@@ -51,7 +61,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
{
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix +
"failed to commit transaction " + txnId + ": " +
e.getMessage());
}
@@ -64,15 +74,26 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
finally
{
_connection.clearTransaction();
+ if(_ownConnection)
+ {
+ _connection.close();
+ }
_connection = null;
_txn = null;
+ postCompletion(committed, deadlock);
}
}
public void
rollback()
{
+ if(_txn == null)
+ {
+ throw new DatabaseException(_errorPrefix + "inactive transaction");
+ }
+
String txnId = null;
+ boolean deadlock = false;
try
{
@@ -87,7 +108,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + "rolled back transaction " +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix + "rolled back transaction " +
txnId);
}
}
@@ -95,11 +116,13 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
{
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix +
"failed to rollback transaction " + txnId + ": " +
e.getMessage());
}
+ deadlock = true;
+
DeadlockException ex = new DeadlockException();
ex.initCause(e);
ex.message = _errorPrefix + "DbTxn.abort: " + e.getMessage();
@@ -109,7 +132,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
{
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix +
"failed to rollback transaction " + txnId + ": " +
e.getMessage());
}
@@ -122,11 +145,22 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
finally
{
_connection.clearTransaction();
+ if(_ownConnection)
+ {
+ _connection.close();
+ }
_connection = null;
_txn = null;
+ postCompletion(false, deadlock);
}
}
+ public Connection
+ getConnection()
+ {
+ return _connection;
+ }
+
TransactionI(ConnectionI connection)
{
_connection = connection;
@@ -141,7 +175,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
{
String txnId = Long.toHexString((_txn.getId() & 0x7FFFFFFF) + 0x80000000L);
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix + "started transaction " +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix + "started transaction " +
txnId);
}
}
@@ -149,7 +183,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
{
if(_txTrace >= 1)
{
- _connection.communicator().getLogger().trace("Freeze.Map", _errorPrefix +
+ _connection.communicator().getLogger().trace("Freeze.Transaction", _errorPrefix +
"failed to start transaction: " + e.getMessage());
}
@@ -160,15 +194,46 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
}
}
+ void
+ setPostCompletionCallback(PostCompletionCallback cb)
+ {
+ _postCompletionCallback = cb;
+ }
+
+ void
+ adoptConnection()
+ {
+ _ownConnection = true;
+ }
+
+ ConnectionI
+ getConnectionI()
+ {
+ return _connection;
+ }
+
com.sleepycat.db.Transaction
dbTxn()
{
return _txn;
}
+
+ private void
+ postCompletion(boolean committed, boolean deadlock)
+ {
+ if(_postCompletionCallback != null)
+ {
+ _postCompletionCallback.postCompletion(committed, deadlock);
+ }
+ }
+
private ConnectionI _connection;
private int _txTrace;
private com.sleepycat.db.Transaction _txn;
+ private PostCompletionCallback _postCompletionCallback;
+
private String _errorPrefix;
+ private boolean _ownConnection = false;
}
diff --git a/java/src/Freeze/TransactionalEvictorContextI.java b/java/src/Freeze/TransactionalEvictorContext.java
index 91e96fcdf3b..4d5578a2f1e 100644
--- a/java/src/Freeze/TransactionalEvictorContextI.java
+++ b/java/src/Freeze/TransactionalEvictorContext.java
@@ -14,43 +14,17 @@ package Freeze;
// and a number of servants loaded using this transaction.
//
-class TransactionalEvictorContextI extends Ice.LocalObjectImpl
- implements TransactionalEvictorContext, Ice.DispatchInterceptorAsyncCallback
+class TransactionalEvictorContext implements Ice.DispatchInterceptorAsyncCallback, PostCompletionCallback
{
public void
- rollbackOnly()
- {
- _rollbackOnly = true;
- }
-
- public boolean
- isRollbackOnly()
- {
- return _rollbackOnly;
- }
-
- public void
- complete()
- {
+ postCompletion(boolean committed, boolean deadlock)
+ {
try
{
- if(_rollbackOnly)
- {
- _tx.rollback();
- }
- else
+ if(committed)
{
- if(!_stack.empty())
- {
- _dbEnv.getCommunicator().getLogger().warning
- ("Committing TransactionalEvictorContext on DbEnv '" + _dbEnv.getEnvName() + "' with "
- + _stack.size() + " unsaved objects.");
- }
-
- _tx.commit();
-
//
- // Finally, remove updated & removed objects from cache
+ // Remove updated & removed objects from cache
//
java.util.Iterator p = _invalidateList.iterator();
while(p.hasNext())
@@ -58,22 +32,20 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
ToInvalidate ti = (ToInvalidate)p.next();
ti.invalidate();
}
+ _invalidateList.clear();
}
}
- catch(DeadlockException ex)
- {
- deadlockException();
- throw ex;
- }
finally
{
synchronized(this)
{
- if(_dbEnv != null)
+ if(_tx != null)
{
- _dbEnv.clearCurrent(this);
- _dbEnv = null;
-
+ if(deadlock)
+ {
+ _deadlockExceptionDetected = true;
+ }
+ _tx = null;
notifyAll();
}
}
@@ -95,7 +67,7 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
{
return false;
}
- if(_dbEnv == null)
+ if(_tx == null)
{
return true;
}
@@ -163,7 +135,7 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
{
if(_ownServant)
{
- if(!_rollbackOnly)
+ if(_tx != null)
{
if(!_readOnly && !_removed)
{
@@ -215,14 +187,43 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
};
- TransactionalEvictorContextI(SharedDbEnv dbEnv)
+ TransactionalEvictorContext(SharedDbEnv dbEnv)
+ {
+ _tx = (TransactionI)(new ConnectionI(dbEnv).beginTransaction());
+ _owner = Thread.currentThread();
+ _tx.adoptConnection();
+
+ _tx.setPostCompletionCallback(this);
+ }
+
+ TransactionalEvictorContext(TransactionI tx)
{
- _dbEnv = dbEnv;
- _tx = (TransactionI)(new ConnectionI(_dbEnv).beginTransaction());
+ _tx = tx;
_owner = Thread.currentThread();
+
+ _tx.setPostCompletionCallback(this);
+ }
+
+ void
+ rollback()
+ {
+ if(_tx != null)
+ {
+ _tx.rollback();
+ }
}
void
+ commit()
+ {
+ if(_tx != null)
+ {
+ _tx.commit();
+ }
+ }
+
+
+ void
checkDeadlockException()
{
if(_deadlockException != null)
@@ -247,18 +248,19 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
void
deadlockException()
{
- _rollbackOnly = true;
synchronized(this)
{
_deadlockExceptionDetected = true;
notifyAll();
}
+
+ rollback();
}
Ice.Object
servantRemoved(Ice.Identity ident, ObjectStore store)
{
- if(!_rollbackOnly)
+ if(_tx != null)
{
//
// Lookup servant holder on stack
@@ -282,10 +284,10 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
protected void
finalize()
{
- if(_dbEnv != null)
+ if(_tx != null)
{
- _dbEnv.getCommunicator().getLogger().warning
- ("Finalizing incomplete TransactionalEvictorContext on DbEnv '" + _dbEnv.getEnvName() + "'");
+ _tx.getConnectionI().communicator().getLogger().warning
+ ("Finalizing incomplete TransactionalEvictorContext on DbEnv '" + _tx.getConnectionI().dbEnv().getEnvName() + "'");
}
}
@@ -333,15 +335,11 @@ class TransactionalEvictorContextI extends Ice.LocalObjectImpl
//
private final java.util.List _invalidateList = new java.util.LinkedList();
- private final TransactionI _tx;
+ private TransactionI _tx;
private final Thread _owner;
- private boolean _rollbackOnly = false;
-
private DeadlockException _deadlockException;
- private SharedDbEnv _dbEnv;
-
//
// Protected by this
//
diff --git a/java/src/Freeze/TransactionalEvictorI.java b/java/src/Freeze/TransactionalEvictorI.java
index 62696eb061c..143071eac1f 100644
--- a/java/src/Freeze/TransactionalEvictorI.java
+++ b/java/src/Freeze/TransactionalEvictorI.java
@@ -11,13 +11,13 @@ package Freeze;
class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
{
- public TransactionalEvictorContext
- getCurrentContext()
+ public Transaction
+ getCurrentTransaction()
{
_deactivateController.lock();
try
{
- return _dbEnv.getCurrent();
+ return _dbEnv.getCurrent().transaction();
}
finally
{
@@ -25,21 +25,13 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
}
}
- public TransactionalEvictorContext
- createCurrentContext()
+ public void
+ setCurrentTransaction(Transaction tx)
{
_deactivateController.lock();
try
{
- Ice.BooleanHolder created = new Ice.BooleanHolder();
- TransactionalEvictorContext ctx = _dbEnv.getOrCreateCurrent(created);
-
- if(created.value == false)
- {
- throw new DatabaseException(_errorPrefix +
- "createCurrentContext: there is already a current context");
- }
- return ctx;
+ _dbEnv.setCurrentTransaction(tx);
}
finally
{
@@ -73,7 +65,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
throw ex;
}
- com.sleepycat.db.Transaction tx = beforeQuery();
+ TransactionI tx = beforeQuery();
updateStats(rec.stats, currentTime);
@@ -120,14 +112,14 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
ObjectStore store = findStore(facet, false);
if(store != null)
{
- TransactionalEvictorContextI ctx = _dbEnv.getCurrent();
- com.sleepycat.db.Transaction tx = null;
+ TransactionalEvictorContext ctx = _dbEnv.getCurrent();
+ TransactionI tx = null;
if(ctx != null)
{
- tx = ctx.transaction().dbTxn();
+ tx = ctx.transaction();
if(tx == null)
{
- throw new DatabaseException(_errorPrefix + "invalid TransactionalEvictorContext");
+ throw new DatabaseException(_errorPrefix + "inactive transaction");
}
}
@@ -202,7 +194,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
return false;
}
- com.sleepycat.db.Transaction tx = beforeQuery();
+ TransactionI tx = beforeQuery();
if(tx == null)
{
@@ -282,7 +274,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
//
// Is there an existing context?
//
- TransactionalEvictorContextI ctx = _dbEnv.getCurrent();
+ TransactionalEvictorContext ctx = _dbEnv.getCurrent();
if(ctx != null)
{
@@ -291,7 +283,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
//
// If yes, use this context; there is no retrying
//
- TransactionalEvictorContextI.ServantHolder sh = ctx.createServantHolder(current, store, _useNonmutating);
+ TransactionalEvictorContext.ServantHolder sh = ctx.createServantHolder(current, store, _useNonmutating);
if(sh.servant() == null)
{
@@ -304,7 +296,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
if(dispatchStatus == Ice.DispatchStatus.DispatchUserException && _rollbackOnUserException)
{
- ctx.rollbackOnly();
+ ctx.rollback();
}
if(dispatchStatus == Ice.DispatchStatus.DispatchAsync)
{
@@ -314,7 +306,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
}
catch(RuntimeException ex)
{
- ctx.rollbackOnly();
+ ctx.rollback();
throw ex;
}
finally
@@ -329,7 +321,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
}
catch(RuntimeException ex)
{
- ctx.rollbackOnly();
+ ctx.rollback();
throw ex;
}
}
@@ -404,13 +396,13 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
do
{
- ctx = _dbEnv.getOrCreateCurrent(null);
+ ctx = _dbEnv.createCurrent();
try
{
try
{
- TransactionalEvictorContextI.ServantHolder sh = ctx.createServantHolder(current, store, _useNonmutating);
+ TransactionalEvictorContext.ServantHolder sh = ctx.createServantHolder(current, store, _useNonmutating);
if(sh.servant() == null)
{
@@ -422,7 +414,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
Ice.DispatchStatus dispatchStatus = sh.servant().ice_dispatch(request, ctx);
if(dispatchStatus == Ice.DispatchStatus.DispatchUserException && _rollbackOnUserException)
{
- ctx.rollbackOnly();
+ ctx.rollback();
}
if(dispatchStatus == Ice.DispatchStatus.DispatchAsync)
{
@@ -432,12 +424,13 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
}
catch(RuntimeException ex)
{
- ctx.rollbackOnly();
+ ctx.rollback();
throw ex;
}
finally
{
sh.release();
+ ctx.commit();
}
}
catch(DeadlockException ex)
@@ -445,21 +438,19 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
ctx.deadlockException();
throw ex;
}
- catch(RuntimeException ex)
- {
- ctx.rollbackOnly();
- throw ex;
- }
finally
{
- ctx.complete();
+ ctx.rollback();
}
}
catch(DeadlockException ex)
{
tryAgain = true;
}
-
+ finally
+ {
+ _dbEnv.setCurrentTransaction(null);
+ }
} while(tryAgain);
}
}
@@ -513,7 +504,7 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
storeMapCopy = new java.util.HashMap(_storeMap);
}
- com.sleepycat.db.Transaction tx = beforeQuery();
+ TransactionI tx = beforeQuery();
java.util.Iterator p = storeMapCopy.entrySet().iterator();
while(p.hasNext())
@@ -562,17 +553,17 @@ class TransactionalEvictorI extends EvictorI implements TransactionalEvictor
}
}
- protected com.sleepycat.db.Transaction
+ protected TransactionI
beforeQuery()
{
- TransactionalEvictorContextI ctx = _dbEnv.getCurrent();
- com.sleepycat.db.Transaction tx = null;
+ TransactionalEvictorContext ctx = _dbEnv.getCurrent();
+ TransactionI tx = null;
if(ctx != null)
{
- tx = ctx.transaction().dbTxn();
+ tx = ctx.transaction();
if(tx == null)
{
- throw new DatabaseException(_errorPrefix + "invalid TransactionalEvictorContext");
+ throw new DatabaseException(_errorPrefix + "inactive transaction");
}
}