summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2010-05-27 13:35:59 -0400
committerBernard Normier <bernard@zeroc.com>2010-05-27 13:35:59 -0400
commit1ba56ce2d905543d1f98fbe7a1adfb79da7839b1 (patch)
tree618aac6ab46c980ac0d8e14e237e3c77854d8bc7
parentmore CHANGES fixes for 4515 (diff)
downloadice-1ba56ce2d905543d1f98fbe7a1adfb79da7839b1.tar.bz2
ice-1ba56ce2d905543d1f98fbe7a1adfb79da7839b1.tar.xz
ice-1ba56ce2d905543d1f98fbe7a1adfb79da7839b1.zip
Fixed bug #4697
-rw-r--r--CHANGES4
-rw-r--r--java/src/Freeze/MapInternal/Index.java59
-rw-r--r--java/src/Freeze/MapInternal/MapI.java113
-rw-r--r--java/test/Freeze/dbmap/Client.java41
4 files changed, 129 insertions, 88 deletions
diff --git a/CHANGES b/CHANGES
index ae7419afb42..135d6d22f1e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -87,6 +87,10 @@ Java Changes
callback facility, applications should derive their classes from
Ice.Callback.
+- The size method on a Freeze.Map and on the value of an indexed
+ submap now use the current transaction associated with the
+ connection, if any.
+
C# Changes
==========
diff --git a/java/src/Freeze/MapInternal/Index.java b/java/src/Freeze/MapInternal/Index.java
index fb611f57f70..93e1721ec35 100644
--- a/java/src/Freeze/MapInternal/Index.java
+++ b/java/src/Freeze/MapInternal/Index.java
@@ -252,45 +252,50 @@ public abstract class Index<K, V, I>
{
for(;;)
{
- com.sleepycat.db.Cursor dbc = null;
try
{
- dbc = _db.openCursor(null, null);
- if(dbc.getSearchKey(dbKey, dbValue, null) == com.sleepycat.db.OperationStatus.SUCCESS)
+ com.sleepycat.db.Cursor dbc = null;
+ try
{
- return dbc.count();
+ dbc = _db.openCursor(_map.connection().dbTxn(), null);
+ if(dbc.getSearchKey(dbKey, dbValue, null) == com.sleepycat.db.OperationStatus.SUCCESS)
+ {
+ return dbc.count();
+ }
+ else
+ {
+ return 0;
+ }
}
- else
+ finally
{
- return 0;
+ if(dbc != null)
+ {
+ dbc.close();
+ }
}
}
catch(com.sleepycat.db.DeadlockException dx)
{
- if(_trace.deadlockWarning)
+ if(_map.connection().dbTxn() != null)
{
- _trace.logger.warning("Deadlock in Freeze.MapIndex.count while iterating over index \"" +
- _dbName + "\"; retrying...");
+ DeadlockException ex = new DeadlockException(
+ _trace.errorPrefix + "Dbc.count: " + dx.getMessage(), _map.connection().currentTransaction());
+ ex.initCause(dx);
+ throw ex;
}
-
- //
- // Retry
- //
- }
- finally
- {
- if(dbc != null)
+ else
{
- try
- {
- dbc.close();
- }
- catch(com.sleepycat.db.DeadlockException dx)
+
+ if(_trace.deadlockWarning)
{
- //
- // Ignored
- //
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.Index.count while iterating over index \"" +
+ _dbName + "\"; retrying...");
}
+
+ //
+ // Retry
+ //
}
}
}
@@ -419,7 +424,7 @@ public abstract class Index<K, V, I>
if(_trace.level >= 2)
{
- _trace.logger.trace("Freeze.MapIndex", "checking key in Db \"" + _dbName + "\"");
+ _trace.logger.trace("Freeze.MapInternal.Index", "checking key in Db \"" + _dbName + "\"");
}
for(;;)
@@ -442,7 +447,7 @@ public abstract class Index<K, V, I>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.MapIndex.containsKey while " + "reading Db \"" +
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.Index.containsKey while " + "reading Db \"" +
_dbName + "\"; retrying...");
}
//
diff --git a/java/src/Freeze/MapInternal/MapI.java b/java/src/Freeze/MapInternal/MapI.java
index b7afe4b136a..f0d1b4c9831 100644
--- a/java/src/Freeze/MapInternal/MapI.java
+++ b/java/src/Freeze/MapInternal/MapI.java
@@ -66,7 +66,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(trace.level >= 1)
{
- trace.logger.trace("Freeze.Map", "Recreating \"" + dbName + "\"");
+ trace.logger.trace("Freeze.MapInternal.MapI", "Recreating \"" + dbName + "\"");
}
Transaction tx = connection.currentTransaction();
@@ -92,7 +92,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(trace.level >= 2)
{
- trace.logger.trace("Freeze.Map", "Removing all existing indices for \"" + dbName + "\"");
+ trace.logger.trace("Freeze.MapInternal.MapI", "Removing all existing indices for \"" + dbName + "\"");
}
CatalogIndexList catalogIndexList = new CatalogIndexList(connection, Util.catalogIndexListName(), true);
@@ -122,7 +122,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(trace.level >= 2)
{
- trace.logger.trace("Freeze.Map", "Renaming \"" + dbName + "\" to \"" + oldDbName + "\"");
+ trace.logger.trace("Freeze.MapInternal.MapI", "Renaming \"" + dbName + "\" to \"" + oldDbName + "\"");
}
connection.dbEnv().getEnv().renameDatabase(txn, dbName, null, oldDbName);
@@ -137,7 +137,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(trace.level >= 2)
{
- trace.logger.trace("Freeze.Map", "Writing contents of \"" + oldDbName + "\" to fresh \"" +
+ trace.logger.trace("Freeze.MapInternal.MapI", "Writing contents of \"" + oldDbName + "\" to fresh \"" +
dbName + "\"");
}
@@ -164,7 +164,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(trace.level >= 2)
{
- trace.logger.trace("Freeze.Map", "Transfer complete; removing \"" + oldDbName + "\"");
+ trace.logger.trace("Freeze.MapInternal.MapI", "Transfer complete; removing \"" + oldDbName + "\"");
}
connection.dbEnv().getEnv().removeDatabase(txn, oldDbName, null);
@@ -188,7 +188,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(trace.deadlockWarning)
{
- trace.logger.warning("Deadlock in Freeze.Map.recreate on Db \"" + dbName + "\"; retrying ...");
+ trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.recreate on Db \"" + dbName + "\"; retrying ...");
}
//
@@ -348,7 +348,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_trace.level >= 1)
{
- _trace.logger.trace("Freeze.Map", "destroying \"" + _dbName + "\"");
+ _trace.logger.trace("Freeze.MapInternal.MapI", "destroying \"" + _dbName + "\"");
}
closeDb();
@@ -400,7 +400,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.destroy on Db \"" + _dbName + "\"; retrying...");
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.destroy on Db \"" + _dbName + "\"; retrying...");
}
//
@@ -687,39 +687,46 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + _dbName + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + _dbName + "\" is closed";
throw ex;
}
- //
- // The number of records cannot be cached and then adjusted by
- // the member functions since the map would no longer work in
- // the presence of transactions - if a record is added (and
- // the size adjusted) and the transaction aborted then the
- // cached map size() would be incorrect.
- //
-
- //
- // TODO: DB_FAST_STAT doesn't seem to do what the
- // documentation says...
- //
- try
- {
- 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.DatabaseException e)
+ for(;;)
{
- DatabaseException ex = new DatabaseException();
- ex.initCause(e);
- ex.message = _trace.errorPrefix + "Db.stat: " + e.getMessage();
- throw ex;
+
+ try
+ {
+ com.sleepycat.db.BtreeStats s = (com.sleepycat.db.BtreeStats)_db.db().getStats(_connection.dbTxn(), null);
+ return s.getNumKeys();
+ }
+ catch(com.sleepycat.db.DeadlockException e)
+ {
+ if(_connection.dbTxn() != null)
+ {
+ DeadlockException ex = new DeadlockException(
+ _trace.errorPrefix + "Db.getStats: " + e.getMessage(), _connection.currentTransaction());
+ ex.initCause(e);
+ throw ex;
+ }
+ else
+ {
+ if(_trace.deadlockWarning)
+ {
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.size while " + "reading Db \"" + _dbName +
+ "\"; retrying...");
+ }
+ //
+ // Try again
+ //
+ }
+ }
+ catch(com.sleepycat.db.DatabaseException e)
+ {
+ DatabaseException ex = new DatabaseException();
+ ex.initCause(e);
+ ex.message = _trace.errorPrefix + "Db.getStats: " + e.getMessage();
+ throw ex;
+ }
}
}
@@ -767,7 +774,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.containsValue while " + "iterating over Db \"" +
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.containsValue while " + "iterating over Db \"" +
_dbName + "\"; retrying...");
}
@@ -795,7 +802,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + _dbName + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + _dbName + "\" is closed";
throw ex;
}
@@ -807,7 +814,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_trace.level >= 2)
{
- _trace.logger.trace("Freeze.Map", "checking key in Db \"" + _dbName + "\"");
+ _trace.logger.trace("Freeze.MapInternal.MapI", "checking key in Db \"" + _dbName + "\"");
}
for(;;)
@@ -830,7 +837,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.containsKey while " + "reading Db \"" + _dbName +
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.containsKey while " + "reading Db \"" + _dbName +
"\"; retrying...");
}
//
@@ -908,7 +915,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + _dbName + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + _dbName + "\" is closed";
throw ex;
}
@@ -934,7 +941,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.clear on Db \"" + _dbName + "\"; retrying...");
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.clear on Db \"" + _dbName + "\"; retrying...");
}
//
@@ -1135,7 +1142,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db.db() == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + dbName() + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + dbName() + "\" is closed";
throw ex;
}
@@ -1275,7 +1282,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + _dbName + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + _dbName + "\" is closed";
throw ex;
}
@@ -1284,7 +1291,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_trace.level >= 2)
{
- _trace.logger.trace("Freeze.Map", "writing value in Db \"" + _dbName + "\"");
+ _trace.logger.trace("Freeze.MapInternal.MapI", "writing value in Db \"" + _dbName + "\"");
}
com.sleepycat.db.Transaction txn = _connection.dbTxn();
@@ -1313,7 +1320,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.putImpl while " + "writing into Db \"" +
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.putImpl while " + "writing into Db \"" +
_dbName + "\"; retrying...");
}
@@ -1338,13 +1345,13 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + _dbName + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + _dbName + "\" is closed";
throw ex;
}
if(_trace.level >= 2)
{
- _trace.logger.trace("Freeze.Map", "deleting value from Db \"" + _dbName + "\"");
+ _trace.logger.trace("Freeze.MapInternal.MapI", "deleting value from Db \"" + _dbName + "\"");
}
com.sleepycat.db.Transaction txn = _connection.dbTxn();
@@ -1373,7 +1380,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.removeImpl while " + "writing into Db \"" +
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.removeImpl while " + "writing into Db \"" +
_dbName + "\"; retrying...");
}
@@ -1398,7 +1405,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_db == null)
{
DatabaseException ex = new DatabaseException();
- ex.message = _trace.errorPrefix + "\"" + _dbName + "\" has been closed";
+ ex.message = _trace.errorPrefix + "\"" + _dbName + "\" is closed";
throw ex;
}
@@ -1406,7 +1413,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
if(_trace.level >= 2)
{
- _trace.logger.trace("Freeze.Map", "reading value from Db \"" + _dbName + "\"");
+ _trace.logger.trace("Freeze.MapInternal.MapI", "reading value from Db \"" + _dbName + "\"");
}
for(;;)
@@ -1436,7 +1443,7 @@ public abstract class MapI<K, V> extends java.util.AbstractMap<K, V>
{
if(_trace.deadlockWarning)
{
- _trace.logger.warning("Deadlock in Freeze.Map.getImpl while " + "reading Db \"" + _dbName +
+ _trace.logger.warning("Deadlock in Freeze.MapInternal.MapI.getImpl while " + "reading Db \"" + _dbName +
"\"; retrying...");
}
diff --git a/java/test/Freeze/dbmap/Client.java b/java/test/Freeze/dbmap/Client.java
index f0fefc39bf9..8d6b1efb182 100644
--- a/java/test/Freeze/dbmap/Client.java
+++ b/java/test/Freeze/dbmap/Client.java
@@ -296,7 +296,12 @@ public class Client
test(count == 1); // Opened by keys.remove()
Transaction tx = connection.beginTransaction();
+
+ test(keys.size() == alphabet.length());
test(keys.remove((byte)'a') == true);
+
+ // Verify that size is transactional
+ test(keys.size() == alphabet.length() - 1);
test(keys.remove((byte)'a') == false);
tx.commit();
test(m.containsKey((byte)'a') == false);
@@ -1093,6 +1098,7 @@ public class Client
// fastRemove
//
sub = sm.headMap(first, true);
+
Ice.Identity id = sub.get(first);
test(sub.fastRemove(first) == true);
test(sub.fastRemove(first) == false);
@@ -1114,6 +1120,31 @@ public class Client
NavigableMap<String, java.util.Set<java.util.Map.Entry<Integer, Ice.Identity>>> isub = null;
isub = sm.mapForCategory();
+
+ {
+ Transaction tx = connection.beginTransaction();
+
+ Ice.Identity id = sm.get(sm.firstKey());
+ int sz = isub.get(id.category).size();
+ test(sz > 0);
+
+
+ test(sm.fastRemove(sm.firstKey()) == true);
+
+
+ if(sz == 1)
+ {
+ test(isub.get(id.category) == null);
+ }
+ else
+ {
+ // System.out.println("Check size within tx");
+ test(isub.get(id.category).size() == sz -1);
+ }
+ tx.rollback();
+ test(isub.get(id.category).size() == sz);
+ }
+
final String first = isub.firstKey();
final String last = isub.lastKey();
@@ -1383,15 +1414,10 @@ public class Client
{
NavigableMap<Integer, Ice.Identity> dmap = sm.descendingMap();
- //
- // testSortedMap is memory intensive test, so we force garbage
- // collection before run the test.
- //
- System.gc();
+
testSortedMap(dmap, false);
- System.gc();
testSortedMap(dmap.descendingMap(), true); // Ascending submap.
- System.gc();
+
}
int finc, tinc; // Inclusive flags
@@ -2145,7 +2171,6 @@ public class Client
}
}
- System.gc();
System.exit(status);
}
}