summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2004-12-02 23:18:51 +0000
committerBernard Normier <bernard@zeroc.com>2004-12-02 23:18:51 +0000
commit7e5b25f64e832a9659dc054eef2935284c795a5a (patch)
tree4f9f3ce6eb8ec88d3455b8a07998ed4ab575ce9e /java/src
parentbzip2 fix (diff)
downloadice-7e5b25f64e832a9659dc054eef2935284c795a5a.tar.bz2
ice-7e5b25f64e832a9659dc054eef2935284c795a5a.tar.xz
ice-7e5b25f64e832a9659dc054eef2935284c795a5a.zip
Freeze catalogs
Diffstat (limited to 'java/src')
-rwxr-xr-xjava/src/Freeze/ConnectionI.java30
-rw-r--r--java/src/Freeze/EvictorI.java39
-rw-r--r--java/src/Freeze/Index.java2
-rw-r--r--java/src/Freeze/Map.java12
-rw-r--r--java/src/Freeze/ObjectStore.java135
-rwxr-xr-xjava/src/Freeze/SharedDb.java283
-rw-r--r--java/src/Freeze/SharedDbEnv.java281
-rwxr-xr-xjava/src/Freeze/TransactionI.java2
-rw-r--r--java/src/Freeze/Util.java22
9 files changed, 454 insertions, 352 deletions
diff --git a/java/src/Freeze/ConnectionI.java b/java/src/Freeze/ConnectionI.java
index 74a0c4ab417..294b5f9665e 100755
--- a/java/src/Freeze/ConnectionI.java
+++ b/java/src/Freeze/ConnectionI.java
@@ -88,42 +88,31 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection
}
}
- _dbEnv = null;
- if(_dbEnvHolder != null)
+ if(_dbEnv != null)
{
try
{
- _dbEnvHolder.close();
+ _dbEnv.close();
}
finally
{
- _dbEnvHolder = null;
+ _dbEnv = null;
}
}
}
- ConnectionI(Ice.Communicator communicator, String envName)
+ ConnectionI(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv)
{
_communicator = communicator;
- _dbEnvHolder = SharedDbEnv.get(communicator, envName);
- _dbEnv = _dbEnvHolder;
+ _dbEnv = SharedDbEnv.get(communicator, envName, dbEnv);
_envName = envName;
_trace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Map");
_txTrace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Transaction");
+
Ice.Properties properties = _communicator.getProperties();
-
_deadlockWarning = properties.getPropertyAsInt("Freeze.Warn.Deadlocks") > 0;
- _closeInFinalizeWarning = properties.getPropertyAsIntWithDefault("Freeze.Warn.CloseInFinalize", 1) > 0;
- }
-
- ConnectionI(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv)
- {
- _communicator = communicator;
- _dbEnv = dbEnv;
- _envName = envName;
- _trace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Map");
- _txTrace = _communicator.getProperties().getPropertyAsInt("Freeze.Trace.Transaction");
+ _closeInFinalizeWarning = properties.getPropertyAsIntWithDefault("Freeze.Warn.CloseInFinalize", 1) > 0;
}
//
@@ -174,7 +163,7 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection
}
}
- com.sleepycat.db.DbEnv
+ SharedDbEnv
dbEnv()
{
return _dbEnv;
@@ -217,8 +206,7 @@ class ConnectionI extends Ice.LocalObjectImpl implements Connection
}
private Ice.Communicator _communicator;
- private SharedDbEnv _dbEnvHolder;
- private com.sleepycat.db.DbEnv _dbEnv;
+ private SharedDbEnv _dbEnv;
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 f7aead42857..b3aa1aaef8d 100644
--- a/java/src/Freeze/EvictorI.java
+++ b/java/src/Freeze/EvictorI.java
@@ -210,13 +210,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
_adapter = adapter;
_communicator = adapter.getCommunicator();
_initializer = initializer;
-
- _dbEnvHolder = SharedDbEnv.get(_communicator, envName);
- _dbEnv = _dbEnvHolder;
_filename = filename;
_createDb = createDb;
-
- init(envName, indices);
+ init(envName, null, indices);
}
public
@@ -228,17 +224,18 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
_adapter = adapter;
_communicator = adapter.getCommunicator();
_initializer = initializer;
-
- _dbEnv = dbEnv;
_filename = filename;
_createDb = createDb;
-
- init(envName, indices);
+ init(envName, dbEnv, indices);
}
private void
- init(String envName, Index[] indices)
+ init(String envName, com.sleepycat.db.DbEnv 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;
@@ -1441,12 +1438,17 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
store.close();
}
- if(_dbEnvHolder != null)
+ if(_dbEnv != null)
{
- _dbEnvHolder.close();
- _dbEnvHolder = null;
+ try
+ {
+ _dbEnv.close();
+ }
+ finally
+ {
+ _dbEnv = null;
+ }
}
- _dbEnv = null;
}
finally
{
@@ -1689,7 +1691,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
try
{
- com.sleepycat.db.DbTxn tx = _dbEnv.txnBegin(null, 0);
+ com.sleepycat.db.DbTxn tx = _dbEnv.getEnv().txnBegin(null, 0);
if(_txTrace >= 1)
{
@@ -1844,7 +1846,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
return _communicator;
}
- final com.sleepycat.db.DbEnv
+ final SharedDbEnv
dbEnv()
{
return _dbEnv;
@@ -2063,7 +2065,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
try
{
- db = new com.sleepycat.db.Db(_dbEnv, 0);
+ 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);
@@ -2204,8 +2206,7 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable
private final ServantInitializer _initializer;
- private SharedDbEnv _dbEnvHolder;
- private com.sleepycat.db.DbEnv _dbEnv;
+ private SharedDbEnv _dbEnv;
private final String _filename;
private final boolean _createDb;
diff --git a/java/src/Freeze/Index.java b/java/src/Freeze/Index.java
index 33b79307651..9df2db70955 100644
--- a/java/src/Freeze/Index.java
+++ b/java/src/Freeze/Index.java
@@ -286,7 +286,7 @@ public abstract class Index implements com.sleepycat.db.DbSecondaryKeyCreate
assert(txn != null);
_store = store;
- _db= new com.sleepycat.db.Db(_store.evictor().dbEnv(), 0);
+ _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;
diff --git a/java/src/Freeze/Map.java b/java/src/Freeze/Map.java
index 2f0e6efce06..bfdec6fe2a0 100644
--- a/java/src/Freeze/Map.java
+++ b/java/src/Freeze/Map.java
@@ -12,13 +12,13 @@ package Freeze;
public abstract class Map extends java.util.AbstractMap
{
public
- Map(Connection connection, String dbName, boolean createDb)
+ Map(Connection connection, String dbName, String key, String value, boolean createDb)
{
_connection = (ConnectionI) connection;
_errorPrefix = "Freeze DB DbEnv(\"" + _connection.envName() + "\") Db(\"" + dbName + "\"): ";
_trace = _connection.trace();
- init(null, dbName, createDb);
+ init(null, dbName, key, value, createDb);
}
protected
@@ -30,9 +30,9 @@ public abstract class Map extends java.util.AbstractMap
}
protected void
- init(Freeze.Map.Index[] indices, String dbName, boolean createDb)
+ init(Freeze.Map.Index[] indices, String dbName, String key, String value, boolean createDb)
{
- _db = Freeze.SharedDb.get(_connection, dbName, indices, createDb);
+ _db = Freeze.SharedDb.get(_connection, dbName, key, value, indices, createDb);
_token = _connection.registerMap(this);
}
@@ -721,7 +721,7 @@ public abstract class Map extends java.util.AbstractMap
assert(txn != null);
assert(_db == null);
- _db = new com.sleepycat.db.Db(_connection.dbEnv(), 0);
+ _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;
@@ -879,7 +879,7 @@ public abstract class Map extends java.util.AbstractMap
//
// Start transaction
//
- txn = _connection.dbEnv().txnBegin(null, 0);
+ txn = _connection.dbEnv().getEnv().txnBegin(null, 0);
_txn = txn;
if(_connection.txTrace() >= 1)
diff --git a/java/src/Freeze/ObjectStore.java b/java/src/Freeze/ObjectStore.java
index 28118d62e26..9691d0d6bff 100644
--- a/java/src/Freeze/ObjectStore.java
+++ b/java/src/Freeze/ObjectStore.java
@@ -31,98 +31,89 @@ class ObjectStore implements IceUtil.Store
_dbName = facet;
}
- com.sleepycat.db.DbTxn txn = null;
- com.sleepycat.db.DbEnv dbEnv = evictor.dbEnv();
-
- String txnId = null;
+ Connection connection = Util.createConnection(_communicator, evictor.dbEnv().getEnvName());
try
- {
- _db = new com.sleepycat.db.Db(dbEnv, 0);
+ {
+ Catalog catalog = new Catalog(connection, Util.catalogName(), true);
+ CatalogData catalogData = (CatalogData)catalog.get(evictor.filename());
- txn = dbEnv.txnBegin(null, 0);
-
- if(evictor.txTrace() >= 1)
+ if(catalogData != null && catalogData.evictor == false)
{
- txnId = Long.toHexString((txn.id() & 0x7FFFFFFF) + 0x80000000L);
-
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "started transaction " +
- txnId + " to open Db");
+ DatabaseException ex = new DatabaseException();
+ ex.message = _evictor.errorPrefix() + evictor.filename() + " is not an evictor database";
+ throw ex;
}
+ com.sleepycat.db.DbEnv dbEnv = evictor.dbEnv().getEnv();
- //
- // 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);
+ try
+ {
+ _db = new com.sleepycat.db.Db(dbEnv, 0);
+
+ Transaction tx = connection.beginTransaction();
+ com.sleepycat.db.DbTxn txn = Util.getTxn(tx);
-
- java.util.Iterator p = _indices.iterator();
- while(p.hasNext())
+ //
+ // 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);
+
+
+ java.util.Iterator p = _indices.iterator();
+ while(p.hasNext())
+ {
+ Index index = (Index) p.next();
+ index.associate(this, txn, createDb, populateEmptyIndices);
+ }
+
+ if(catalogData == null)
+ {
+ catalogData = new CatalogData();
+ catalogData.evictor = true;
+ catalog.put(evictor.filename(), catalogData);
+ }
+
+ tx.commit();
+ }
+ catch(java.io.FileNotFoundException dx)
{
- Index index = (Index) p.next();
- index.associate(this, txn, createDb, populateEmptyIndices);
+ NotFoundException ex = new NotFoundException();
+ ex.initCause(dx);
+ ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
+ throw ex;
}
-
- com.sleepycat.db.DbTxn toCommit = txn;
- txn = null;
- toCommit.commit(0);
-
- if(evictor.txTrace() >= 1)
+ catch(com.sleepycat.db.DbException dx)
{
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "committed transaction " +
- txnId);
+ DatabaseException ex = new DatabaseException();
+ ex.initCause(dx);
+ ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
+ throw ex;
}
-
- }
- catch(java.io.FileNotFoundException dx)
- {
- NotFoundException ex = new NotFoundException();
- ex.initCause(dx);
- ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
- throw ex;
- }
- catch(com.sleepycat.db.DbException dx)
- {
- DatabaseException ex = new DatabaseException();
- ex.initCause(dx);
- ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
- throw ex;
- }
- finally
- {
- if(txn != null)
+ finally
{
- try
- {
- txn.abort();
-
- if(evictor.txTrace() >= 1)
+ Transaction tx = connection.currentTransaction();
+ if(tx != null)
+ {
+ try
{
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "rolled back transaction " +
- txnId);
+ tx.rollback();
}
- }
- catch(com.sleepycat.db.DbException dx)
- {
- if(evictor.txTrace() >= 1)
+ catch(DatabaseException de)
{
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "failed to rollback transaction " +
- txnId + ": " + dx.getMessage());
}
-
}
}
}
+ finally
+ {
+ connection.close();
+ }
}
protected void
diff --git a/java/src/Freeze/SharedDb.java b/java/src/Freeze/SharedDb.java
index 3cca7191680..9c3b448fc7b 100755
--- a/java/src/Freeze/SharedDb.java
+++ b/java/src/Freeze/SharedDb.java
@@ -12,43 +12,88 @@ package Freeze;
class SharedDb extends com.sleepycat.db.Db
{
public static SharedDb
- get(ConnectionI connection, String dbName, Map.Index[] indices, boolean createDb)
+ get(ConnectionI connection, String dbName, String key, String value,
+ Map.Index[] indices, boolean createDb)
{
- MapKey key = new MapKey(connection.envName(), connection.communicator(), dbName);
+ MapKey mapKey = new MapKey(connection.envName(), connection.communicator(), dbName);
+
+ if(dbName.equals(Util.catalogName()))
+ {
+ //
+ // We don't want to lock the _map to retrieve the catalog
+ //
+ SharedDb result = connection.dbEnv().getCatalog();
+ checkTypes(result, key, value);
+ result._refCount++;
+ return result;
+ }
synchronized(_map)
{
- SharedDb result = (SharedDb) _map.get(key);
+ SharedDb result = (SharedDb)_map.get(mapKey);
if(result == null)
{
try
{
- result = new SharedDb(key, connection, indices, createDb);
+ result = new SharedDb(mapKey, key, value, connection, indices, createDb);
}
catch(com.sleepycat.db.DbException dx)
{
DatabaseException ex = new DatabaseException();
ex.initCause(dx);
- ex.message = errorPrefix(key) + "creation: " + dx.getMessage();
+ ex.message = errorPrefix(mapKey) + "creation: " + dx.getMessage();
throw ex;
}
- Object previousValue = _map.put(key, result);
+ Object previousValue = _map.put(mapKey, result);
assert(previousValue == null);
}
else
{
+ checkTypes(result, key, value);
result.connectIndices(indices);
result._refCount++;
}
return result;
}
}
-
+
+ public static SharedDb
+ openCatalog(SharedDbEnv dbEnv)
+ {
+ MapKey mapKey = new MapKey(dbEnv.getEnvName(), dbEnv.getCommunicator(), Util.catalogName());
+
+ synchronized(_map)
+ {
+ SharedDb result = (SharedDb)_map.get(mapKey);
+ if(result != null)
+ {
+ DatabaseException ex = new DatabaseException();
+ ex.message = errorPrefix(mapKey) + "Catalog already opened";
+ throw ex;
+ }
+
+ try
+ {
+ result = new SharedDb(mapKey, dbEnv.getEnv());
+ }
+ catch(com.sleepycat.db.DbException dx)
+ {
+ DatabaseException ex = new DatabaseException();
+ ex.initCause(dx);
+ ex.message = errorPrefix(mapKey) + "creation: " + dx.getMessage();
+ throw ex;
+ }
+ Object previousValue = _map.put(mapKey, result);
+ assert(previousValue == null);
+ return result;
+ }
+ }
+
public String
dbName()
{
- return _key.dbName;
+ return _mapKey.dbName;
}
public void
@@ -61,12 +106,12 @@ class SharedDb extends com.sleepycat.db.Db
//
// Remove from map
//
- Object value = _map.remove(_key);
+ Object value = _map.remove(_mapKey);
assert(value == this);
if(_trace >= 1)
{
- _key.communicator.getLogger().trace("Freeze.Map", "closing Db \"" + _key.dbName + "\"");
+ _mapKey.communicator.getLogger().trace("Freeze.Map", "closing Db \"" + _mapKey.dbName + "\"");
}
//
@@ -83,7 +128,7 @@ class SharedDb extends com.sleepycat.db.Db
{
DatabaseException ex = new DatabaseException();
ex.initCause(dx);
- ex.message = errorPrefix(_key) + "close: " + dx.getMessage();
+ ex.message = errorPrefix(_mapKey) + "close: " + dx.getMessage();
throw ex;
}
}
@@ -96,113 +141,152 @@ class SharedDb extends com.sleepycat.db.Db
assert(_refCount == 0);
}
- private SharedDb(MapKey key, ConnectionI connection, Map.Index[] indices,
+ private SharedDb(MapKey mapKey, String key, String value,
+ ConnectionI connection, Map.Index[] indices,
boolean createDb) throws com.sleepycat.db.DbException
{
- super(connection.dbEnv(), 0);
- _key = key;
+ super(connection.dbEnv().getEnv(), 0);
+ _mapKey = mapKey;
_indices = indices;
_trace = connection.trace();
- com.sleepycat.db.DbTxn txn = null;
-
- String txnId = null;
+ Connection catalogConnection = Util.createConnection(_mapKey.communicator, connection.dbEnv().getEnvName());
try
{
- txn = connection.dbEnv().txnBegin(null, 0);
-
- if(connection.txTrace() >= 1)
+ Catalog catalog = new Catalog(catalogConnection, Util.catalogName(), true);
+ CatalogData catalogData = (CatalogData) catalog.get(_mapKey.dbName);
+ if(catalogData != null)
{
- txnId = Long.toHexString((txn.id() & 0x7FFFFFFF) + 0x80000000L);
-
- _key.communicator.getLogger().trace
- ("Freeze.Map", errorPrefix(_key) + "started transaction " +
- txnId + " to open Db \"" + _key.dbName + "\"");
+ if(catalogData.evictor)
+ {
+ DatabaseException ex = new DatabaseException();
+
+ ex.message = errorPrefix(_mapKey) + "is not an evictor";
+ throw ex;
+ }
+ _key = catalogData.key;
+ _value = catalogData.value;
+ checkTypes(this, key, value);
}
-
- int flags = 0;
-
- if(createDb)
+ else
{
- flags |= com.sleepycat.db.Db.DB_CREATE;
+ _key = key;
+ _value = value;
}
-
- if(_trace >= 1)
+
+ try
{
- _key.communicator.getLogger().trace("Freeze.Map", "opening Db \"" + _key.dbName + "\"");
- }
-
- open(txn, key.dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0);
+ Transaction tx = catalogConnection.beginTransaction();
+ com.sleepycat.db.DbTxn txn = Util.getTxn(tx);
- if(_indices != null)
- {
- for(int i = 0; i < _indices.length; ++i)
+ int flags = 0;
+
+ if(createDb)
{
- _indices[i].associate(key.dbName, this, txn, 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);
+
+ if(_indices != null)
+ {
+ for(int i = 0; i < _indices.length; ++i)
+ {
+ _indices[i].associate(mapKey.dbName, this, txn, createDb);
+ }
}
- }
-
- com.sleepycat.db.DbTxn toCommit = txn;
- txn = null;
- toCommit.commit(0);
- if(connection.txTrace() >= 1)
+ if(catalogData == null)
+ {
+ catalogData = new CatalogData();
+ catalogData.evictor = false;
+ catalogData.key = key;
+ catalogData.value = value;
+ catalog.put(_mapKey.dbName, catalogData);
+ }
+
+ tx.commit();
+
+ //
+ // TODO: FREEZE_DB_MODE
+ //
+ }
+ catch(java.io.FileNotFoundException dx)
{
- _key.communicator.getLogger().trace
- ("Freeze.Map", errorPrefix(_key) + "committed transaction " +
- txnId);
+ cleanupIndices();
+ NotFoundException ex = new NotFoundException();
+ ex.initCause(dx);
+ ex.message = errorPrefix(_mapKey) + "Db.open: " + dx.getMessage();
+ throw ex;
}
-
- //
- // TODO: FREEZE_DB_MODE
- //
- }
- catch(java.io.FileNotFoundException dx)
- {
- cleanupIndices();
- NotFoundException ex = new NotFoundException();
- ex.initCause(dx);
- ex.message = errorPrefix(_key) + "Db.open: " + dx.getMessage();
- throw ex;
- }
- catch(com.sleepycat.db.DbException dx)
- {
- cleanupIndices();
- DatabaseException ex = new DatabaseException();
- ex.initCause(dx);
- ex.message = errorPrefix(_key) + "Db.open: " + dx.getMessage();
- throw ex;
- }
- finally
- {
- if(txn != null)
+ catch(com.sleepycat.db.DbException dx)
{
- try
+ cleanupIndices();
+ DatabaseException ex = new DatabaseException();
+ ex.initCause(dx);
+ ex.message = errorPrefix(_mapKey) + "Db.open: " + dx.getMessage();
+ throw ex;
+ }
+ finally
+ {
+ Transaction tx = catalogConnection.currentTransaction();
+ if(tx != null)
{
- txn.abort();
-
- if(connection.txTrace() >= 1)
+ try
{
- _key.communicator.getLogger().trace
- ("Freeze.Map", errorPrefix(_key) + "rolled back transaction " + txnId);
+ tx.rollback();
}
- }
- catch(com.sleepycat.db.DbException dx)
- {
- if(connection.txTrace() >= 1)
+ catch(DatabaseException de)
{
- _key.communicator.getLogger().trace
- ("Freeze.Map", errorPrefix(_key) + "failed to roll back transaction " +
- txnId + ": " + dx.getMessage());
}
}
}
}
+ finally
+ {
+ catalogConnection.close();
+ }
_refCount = 1;
}
+ private SharedDb(MapKey mapKey, com.sleepycat.db.DbEnv dbEnv) throws com.sleepycat.db.DbException
+ {
+ super(dbEnv, 0);
+ _mapKey = mapKey;
+ _key = "string";
+ _value = "::Freeze::CatalogData";
+
+ if(_trace >= 1)
+ {
+ _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;
+
+ try
+ {
+ open(null, mapKey.dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0);
+ }
+ catch(java.io.FileNotFoundException dx)
+ {
+ //
+ // This should never happen
+ //
+ NotFoundException ex = new NotFoundException();
+ ex.initCause(dx);
+ ex.message = errorPrefix(_mapKey) + "Db.open: " + dx.getMessage();
+ throw ex;
+ }
+ _refCount = 1;
+ }
+
private void
connectIndices(Map.Index[] indices)
{
@@ -231,6 +315,25 @@ class SharedDb extends com.sleepycat.db.Db
}
+ private static void
+ checkTypes(SharedDb sharedDb, String key, String value)
+ {
+ if(!key.equals(sharedDb._key))
+ {
+ DatabaseException ex = new DatabaseException();
+ 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;
+ throw ex;
+ }
+ }
+
private static String
errorPrefix(MapKey k)
{
@@ -245,6 +348,10 @@ class SharedDb extends com.sleepycat.db.Db
MapKey(String envName, Ice.Communicator communicator, String dbName)
{
+ assert(envName != null);
+ assert(communicator != null);
+ assert(dbName != null);
+
this.envName = envName;
this.communicator = communicator;
this.dbName = dbName;
@@ -271,7 +378,9 @@ class SharedDb extends com.sleepycat.db.Db
}
}
- private MapKey _key;
+ private MapKey _mapKey;
+ private String _key;
+ private String _value;
private int _refCount = 0;
private int _trace;
private Map.Index[] _indices;
diff --git a/java/src/Freeze/SharedDbEnv.java b/java/src/Freeze/SharedDbEnv.java
index 05ba1032efe..3b76ca23921 100644
--- a/java/src/Freeze/SharedDbEnv.java
+++ b/java/src/Freeze/SharedDbEnv.java
@@ -9,10 +9,10 @@
package Freeze;
-class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbErrorHandler, Runnable
+class SharedDbEnv implements com.sleepycat.db.DbErrorHandler, Runnable
{
public static SharedDbEnv
- get(Ice.Communicator communicator, String envName)
+ get(Ice.Communicator communicator, String envName, com.sleepycat.db.DbEnv dbEnv)
{
MapKey key = new MapKey(envName, communicator);
@@ -23,7 +23,7 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
{
try
{
- result = new SharedDbEnv(key);
+ result = new SharedDbEnv(key, dbEnv);
}
catch(com.sleepycat.db.DbException dx)
{
@@ -56,6 +56,18 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
return _key.communicator;
}
+ public com.sleepycat.db.DbEnv
+ getEnv()
+ {
+ return _dbEnv;
+ }
+
+ public SharedDb
+ getCatalog()
+ {
+ return _catalog;
+ }
+
public void
close()
{
@@ -80,16 +92,29 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
for(;;)
{
- try
- {
- _thread.join();
- break;
- }
- catch(InterruptedException ex)
+ if(_thread != null)
{
+ try
+ {
+ _thread.join();
+ _thread = null;
+ break;
+ }
+ catch(InterruptedException ex)
+ {
+ }
}
}
+ //
+ // Release catalog
+ //
+ if(_catalog != null)
+ {
+ _catalog.close();
+ _catalog = null;
+ }
+
if(_trace >= 1)
{
_key.communicator.getLogger().trace
@@ -102,7 +127,7 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
//
try
{
- super.close(0);
+ _dbEnv.close(0);
}
catch(com.sleepycat.db.DbException dx)
{
@@ -116,39 +141,6 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
}
- synchronized public void
- deleteOldLogs()
- {
- try
- {
- String[] list = logArchive(com.sleepycat.db.Db.DB_ARCH_ABS);
-
- if(list != null)
- {
- for(int i = 0; i < list.length; i++)
- {
- //
- // Remove each file
- //
- java.io.File file = new java.io.File(list[i]);
- boolean ok = file.delete();
- if(!ok)
- {
- _key.communicator.getLogger().warning(
- "could not delete file \"" + list[i] + "\"");
- }
- }
- }
- }
- catch(com.sleepycat.db.DbException dx)
- {
- DatabaseException ex = new DatabaseException();
- ex.initCause(dx);
- ex.message = errorPrefix(_key.envName) + "log_archive: " + dx.getMessage();
- throw ex;
- }
- }
-
public void
run()
{
@@ -182,7 +174,7 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
try
{
- txnCheckpoint(_kbyte, 0, 0);
+ _dbEnv.txnCheckpoint(_kbyte, 0, 0);
}
catch(com.sleepycat.db.DbException dx)
{
@@ -190,21 +182,6 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
"checkpoint on DbEnv \"" + _key.envName + "\" raised DbException: "
+ dx.getMessage());
}
-
- if(_autoDelete)
- {
- try
- {
- deleteOldLogs();
- }
- catch(DatabaseException ex)
- {
- _key.communicator.getLogger().warning(
- "checkpoint on DbEnv \"" + _key.envName + "\" raised DatabaseException: "
- + ex.getMessage());
- }
-
- }
}
}
@@ -221,99 +198,113 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
assert(_refCount == 0);
}
- private SharedDbEnv(MapKey key) throws com.sleepycat.db.DbException
+ private SharedDbEnv(MapKey key, com.sleepycat.db.DbEnv dbEnv) throws com.sleepycat.db.DbException
{
- super(0);
_key = key;
-
+ _dbEnv = dbEnv;
+ _ownDbEnv = (dbEnv == null);
+
Ice.Properties properties = key.communicator.getProperties();
_trace = properties.getPropertyAsInt("Freeze.Trace.DbEnv");
- if(_trace >= 1)
- {
- _key.communicator.getLogger().trace
- ("Freeze.DbEnv", "opening database environment \"" + _key.envName + "\"");
- }
-
- String propertyPrefix = "Freeze.DbEnv." + _key.envName;
-
- setErrorHandler(this);
-
- //
- // Deadlock detection
- //
- 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)
- {
- flags |= com.sleepycat.db.Db.DB_RECOVER_FATAL |
- com.sleepycat.db.Db.DB_CREATE;
- }
- else
- {
- flags |= com.sleepycat.db.Db. DB_RECOVER |
- com.sleepycat.db.Db.DB_CREATE;
- }
-
- if(properties.getPropertyAsIntWithDefault(
- propertyPrefix + ".DbPrivate", 1) != 0)
- {
- flags |= com.sleepycat.db.Db.DB_PRIVATE;
- }
-
- String dbHome = properties.getPropertyWithDefault(
- propertyPrefix + ".DbHome", _key.envName);
-
- //
- // TODO: FREEZE_DB_MODE
- //
-
- try
+ if(_ownDbEnv)
{
- open(dbHome, flags, 0);
- }
- catch(java.io.FileNotFoundException dx)
- {
- NotFoundException ex = new NotFoundException();
- ex.initCause(dx);
- ex.message = errorPrefix(_key.envName) + "open: " + dx.getMessage();
- throw ex;
- }
+ _dbEnv = new com.sleepycat.db.DbEnv(0);
- //
- // Default checkpoint period is every 120 seconds
- //
- _checkpointPeriod = properties.getPropertyAsIntWithDefault
- (propertyPrefix + ".CheckpointPeriod", 120) * 1000;
-
- _kbyte = properties.getPropertyAsIntWithDefault
- (propertyPrefix + ".PeriodicCheckpointMinSize", 0);
-
- _autoDelete = (properties.getPropertyAsIntWithDefault
- (propertyPrefix + ".OldLogsAutoDelete", 1) != 0);
-
-
- String threadName;
- String programName = properties.getProperty("Ice.ProgramName");
- if(programName.length() > 0)
- {
- threadName = programName + "-";
- }
- else
- {
- threadName = "";
+ 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)
+ {
+ flags |= com.sleepycat.db.Db.DB_RECOVER_FATAL |
+ com.sleepycat.db.Db.DB_CREATE;
+ }
+ else
+ {
+ flags |= com.sleepycat.db.Db. DB_RECOVER |
+ com.sleepycat.db.Db.DB_CREATE;
+ }
+
+ if(properties.getPropertyAsIntWithDefault(
+ propertyPrefix + ".DbPrivate", 1) != 0)
+ {
+ flags |= com.sleepycat.db.Db.DB_PRIVATE;
+ }
+
+ if(properties.getPropertyAsIntWithDefault
+ (propertyPrefix + ".OldLogsAutoDelete", 1) != 0)
+ {
+ flags |= com.sleepycat.db.Db.DB_LOG_AUTOREMOVE;
+ }
+
+ String dbHome = properties.getPropertyWithDefault(
+ propertyPrefix + ".DbHome", _key.envName);
+
+ //
+ // TODO: FREEZE_DB_MODE
+ //
+
+ try
+ {
+ _dbEnv.open(dbHome, flags, 0);
+ }
+ catch(java.io.FileNotFoundException dx)
+ {
+ NotFoundException ex = new NotFoundException();
+ ex.initCause(dx);
+ ex.message = errorPrefix(_key.envName) + "open: " + dx.getMessage();
+ throw ex;
+ }
+
+ //
+ // Default checkpoint period is every 120 seconds
+ //
+ _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)
+ {
+ threadName = programName + "-";
+ }
+ else
+ {
+ threadName = "";
+ }
+ threadName += "FreezeCheckpointThread(" + _key.envName + ")";
+
+
+ if(_checkpointPeriod > 0)
+ {
+ _thread = new Thread(this, threadName);
+ _thread.start();
+ }
}
- threadName += "FreezeCheckpointThread(" + _key.envName + ")";
-
- _thread = new Thread(this, threadName);
- _thread.start();
+ _catalog = SharedDb.openCatalog(this);
_refCount = 1;
}
@@ -356,12 +347,14 @@ class SharedDbEnv extends com.sleepycat.db.DbEnv implements com.sleepycat.db.DbE
}
private MapKey _key;
+ private com.sleepycat.db.DbEnv _dbEnv;
+ private boolean _ownDbEnv;
+ private SharedDb _catalog;
private int _refCount = 0;
private boolean _done = false;
private int _trace = 0;
private long _checkpointPeriod = 0;
private int _kbyte = 0;
- private boolean _autoDelete = false;
private Thread _thread;
//
diff --git a/java/src/Freeze/TransactionI.java b/java/src/Freeze/TransactionI.java
index 132838192e1..d1895a7952b 100755
--- a/java/src/Freeze/TransactionI.java
+++ b/java/src/Freeze/TransactionI.java
@@ -138,7 +138,7 @@ class TransactionI extends Ice.LocalObjectImpl implements Transaction
try
{
- _txn = _connection.dbEnv().txnBegin(null, 0);
+ _txn = _connection.dbEnv().getEnv().txnBegin(null, 0);
if(_txTrace >= 1)
{
diff --git a/java/src/Freeze/Util.java b/java/src/Freeze/Util.java
index 712ba11ebc2..a6be7e7516a 100644
--- a/java/src/Freeze/Util.java
+++ b/java/src/Freeze/Util.java
@@ -30,7 +30,7 @@ public class Util
public static Connection
createConnection(Ice.Communicator communicator, String envName)
{
- return new ConnectionI(communicator, envName);
+ return new ConnectionI(communicator, envName, null);
}
public static Connection
@@ -39,6 +39,25 @@ public class Util
return new ConnectionI(communicator, envName, dbEnv);
}
+ public static String catalogName()
+ {
+ return _catalogName;
+ }
+
+ public static com.sleepycat.db.DbTxn
+ getTxn(Transaction tx)
+ {
+ try
+ {
+ return ((TransactionI)tx).dbTxn();
+ }
+ catch(ClassCastException e)
+ {
+ return null;
+ }
+ }
+
+
public static synchronized FatalErrorCallback
registerFatalErrorCallback(FatalErrorCallback cb)
{
@@ -61,6 +80,7 @@ public class Util
}
+ private static String _catalogName = "__catalog";
private static FatalErrorCallback _fatalErrorCallback = null;
}