boolean 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 = marshalKey(ident, _communicator, _encoding); com.sleepycat.db.DatabaseEntry dbValue = marshalValue(objectRecord, _communicator, _encoding, _keepStats); if (_sampleServant != null && !objectRecord.servant.ice_id().equals(_sampleServant.ice_id())) { String msg = _evictor.errorPrefix() + "Attempting to save a '" + objectRecord.servant.ice_id() + "' servant in a database of '" + _sampleServant.ice_id() + "' servants"; throw new DatabaseException(msg); } for (; ; ) { try { return _db.putNoOverwrite(tx, dbKey, dbValue) == com.sleepycat.db.OperationStatus.SUCCESS; } catch (com.sleepycat.db.DeadlockException dx) { if (_evictor.deadlockWarning()) { _communicator .getLogger() .warning( "Deadlock in Freeze.ObjectStore.update while updating Db \"" + _evictor.filename() + "/" + _dbName + "\""); } if (tx != null) { throw new DeadlockException( _evictor.errorPrefix() + "Db.putNoOverwrite: " + dx.getMessage(), transaction, dx); } // // Otherwise retry // } catch (com.sleepycat.db.DatabaseException dx) { throw new DatabaseException( _evictor.errorPrefix() + "Db.putNoOverwrite: " + dx.getMessage(), dx); } } }
boolean 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"); } } com.sleepycat.db.DatabaseEntry dbKey = marshalKey(ident, _communicator, _encoding); // // Keep 0 length since we're not interested in the data // com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); dbValue.setPartial(true); for (; ; ) { try { com.sleepycat.db.OperationStatus err = _db.get(tx, dbKey, dbValue, null); if (err == com.sleepycat.db.OperationStatus.SUCCESS) { return true; } else if (err == com.sleepycat.db.OperationStatus.NOTFOUND) { return false; } else { throw new DatabaseException(); } } catch (com.sleepycat.db.DeadlockException dx) { if (_evictor.deadlockWarning()) { _communicator .getLogger() .warning( "Deadlock in Freeze.ObjectStore.dhHasObject while reading " + "Db \"" + _evictor.filename() + "/" + _dbName + "\""); } if (tx != null) { throw new DeadlockException( _evictor.errorPrefix() + "Db.get: " + dx.getMessage(), transaction, dx); } // // Otherwise try again // } catch (com.sleepycat.db.DatabaseException dx) { throw new DatabaseException(_evictor.errorPrefix() + "Db.get: " + dx.getMessage(), dx); } } }
// // Load a servant from the database using the given transaction; this servant // is NOT cached in the ObjectStore associated cache // 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() + "inactive transaction"); } com.sleepycat.db.DatabaseEntry dbKey = marshalKey(ident, _communicator, _encoding); com.sleepycat.db.DatabaseEntry dbValue = new com.sleepycat.db.DatabaseEntry(); try { com.sleepycat.db.OperationStatus rs = _db.get(tx, dbKey, dbValue, null); if (rs == com.sleepycat.db.OperationStatus.NOTFOUND) { return null; } else if (rs != com.sleepycat.db.OperationStatus.SUCCESS) { assert false; throw new DatabaseException(); } } catch (com.sleepycat.db.DeadlockException dx) { if (_evictor.deadlockWarning()) { _communicator .getLogger() .warning( "Deadlock in Freeze.ObjectStore.load while reading Db \"" + _evictor.filename() + "/" + _dbName + "\""); } throw new DeadlockException( _evictor.errorPrefix() + "Db.get: " + dx.getMessage(), transaction, dx); } catch (com.sleepycat.db.DatabaseException dx) { throw new DatabaseException(_evictor.errorPrefix() + "Db.get: " + dx.getMessage(), dx); } ObjectRecord rec = unmarshalValue(dbValue, _communicator, _encoding, _keepStats); _evictor.initialize(ident, _facet, rec.servant); return rec; }
boolean 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 = marshalKey(ident, _communicator, _encoding); for (; ; ) { try { return _db.delete(tx, dbKey) == com.sleepycat.db.OperationStatus.SUCCESS; } catch (com.sleepycat.db.DeadlockException dx) { if (_evictor.deadlockWarning()) { _communicator .getLogger() .warning( "Deadlock in Freeze.ObjectStore.remove while updating Db \"" + _evictor.filename() + "/" + _dbName + "\""); } if (tx != null) { throw new DeadlockException( _evictor.errorPrefix() + "Db.delete: " + dx.getMessage(), transaction, dx); } // // Otherwise retry // } catch (com.sleepycat.db.DatabaseException dx) { throw new DatabaseException(_evictor.errorPrefix() + "Db.delete: " + dx.getMessage(), dx); } } }
protected Ice.Identity[] untypedFindFirst(byte[] k, int firstN) { EvictorI.DeactivateController deactivateController = _store.evictor().deactivateController(); deactivateController.lock(); try { com.sleepycat.db.DatabaseEntry key = new com.sleepycat.db.DatabaseEntry(k); // // When we have a custom-comparison function, Berkeley DB returns // the key on-disk (when it finds one). We disable this behavior: // (ref Oracle SR 5925672.992) // // In DB > 5.1.x we can not set DB_DBT_PARTIAL in the key Dbt when calling // getSearchKey. // if (com.sleepycat.db.Environment.getVersionMajor() < 5 || (com.sleepycat.db.Environment.getVersionMajor() == 5 && com.sleepycat.db.Environment.getVersionMinor() <= 1)) { key.setPartial(true); } 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.setPartial(true); Ice.Communicator communicator = _store.communicator(); Ice.EncodingVersion encoding = _store.encoding(); TransactionI transaction = _store.evictor().beforeQuery(); com.sleepycat.db.Transaction tx = transaction == null ? null : transaction.dbTxn(); java.util.List<Ice.Identity> identities; for (; ; ) { com.sleepycat.db.SecondaryCursor dbc = null; identities = new java.util.ArrayList<Ice.Identity>(); try { // // Move to the first record // dbc = _db.openSecondaryCursor(tx, null); boolean first = true; boolean found; do { 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, communicator, encoding); identities.add(ident); first = false; } } while ((firstN <= 0 || identities.size() < firstN) && found); break; // for(;;) } 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 + "\""); } if (tx != null) { throw new DeadlockException( _store.evictor().errorPrefix() + "Db.cursor: " + dx.getMessage(), transaction, dx); } // // Otherwise retry // } catch (com.sleepycat.db.DatabaseException dx) { throw new DatabaseException( _store.evictor().errorPrefix() + "Db.cursor: " + dx.getMessage(), dx); } finally { if (dbc != null) { try { dbc.close(); } catch (com.sleepycat.db.DeadlockException dx) { if (tx != null) { throw new DeadlockException( _store.evictor().errorPrefix() + "Db.cursor: " + dx.getMessage(), transaction, dx); } } catch (com.sleepycat.db.DatabaseException dx) { // // Ignored // } } } } if (identities.size() != 0) { Ice.Identity[] result = new Ice.Identity[identities.size()]; return identities.toArray(result); } else { return new Ice.Identity[0]; } } finally { deactivateController.unlock(); } }
protected int untypedCount(byte[] k) { EvictorI.DeactivateController deactivateController = _store.evictor().deactivateController(); deactivateController.lock(); try { com.sleepycat.db.DatabaseEntry key = new com.sleepycat.db.DatabaseEntry(k); // // When we have a custom-comparison function, Berkeley DB returns // the key on-disk (when it finds one). We disable this behavior: // (ref Oracle SR 5925672.992) // // In DB > 5.1.x we can not set DB_DBT_PARTIAL in the key Dbt when calling // getSearchKey. // if (com.sleepycat.db.Environment.getVersionMajor() < 5 || (com.sleepycat.db.Environment.getVersionMajor() == 5 && com.sleepycat.db.Environment.getVersionMinor() <= 1)) { key.setPartial(true); } com.sleepycat.db.DatabaseEntry value = new com.sleepycat.db.DatabaseEntry(); // // dlen is 0, so we should not retrieve any value // value.setPartial(true); TransactionI transaction = _store.evictor().beforeQuery(); com.sleepycat.db.Transaction tx = transaction == null ? null : transaction.dbTxn(); for (; ; ) { com.sleepycat.db.Cursor dbc = null; try { dbc = _db.openCursor(tx, null); if (dbc.getSearchKey(key, value, null) == com.sleepycat.db.OperationStatus.SUCCESS) { return dbc.count(); } else { return 0; } } 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 + "\""); } if (tx != null) { throw new DeadlockException( _store.evictor().errorPrefix() + "Db.cursor: " + dx.getMessage(), transaction, dx); } // // Otherwise retry // } catch (com.sleepycat.db.DatabaseException dx) { throw new DatabaseException( _store.evictor().errorPrefix() + "Db.cursor: " + dx.getMessage(), dx); } finally { if (dbc != null) { try { dbc.close(); } catch (com.sleepycat.db.DeadlockException dx) { if (tx != null) { throw new DeadlockException( _store.evictor().errorPrefix() + "Db.cursor: " + dx.getMessage(), transaction, dx); } } catch (com.sleepycat.db.DatabaseException dx) { // // Ignored // } } } } } finally { deactivateController.unlock(); } }