if (db.getId().equals(ID_DB_ID) ||
db.getId().equals(NAME_DB_ID)) {
envImpl.logMapTreeRoot();
} else {
Locker locker = new AutoTxn(envImpl, new TransactionConfig());
CursorImpl cursor = new CursorImpl(idDatabase, locker);
boolean operationOk = false;
try {
DatabaseEntry keyDbt =
new DatabaseEntry(db.getId().getBytes());
MapLN mapLN = null;
/*
* Retry indefinitely in the face of lock timeouts since the
* lock on the MapLN is only supposed to be held for short
* periods.
*/
while (true) {
try {
boolean searchOk = (cursor.searchAndPosition
(keyDbt, new DatabaseEntry(),
SearchMode.SET, LockType.WRITE) &
CursorImpl.FOUND) != 0;
if (!searchOk) {
throw new DatabaseException(
"can't find database " + db.getId());
}
mapLN = (MapLN)
cursor.getCurrentLNAlreadyLatched(LockType.WRITE);
assert mapLN != null; /* Should be locked. */
} catch (DeadlockException DE) {
cursor.close();
locker.operationEnd(false);
locker = new AutoTxn(envImpl, new TransactionConfig());
cursor = new CursorImpl(idDatabase, locker);
continue;
} finally {
cursor.releaseBINs();
}
break;
}
RewriteMapLN writeMapLN = new RewriteMapLN(cursor);
mapLN.getDatabase().getTree().withRootLatched(writeMapLN);
operationOk = true;
} finally {
if (cursor != null) {
cursor.close();
}
locker.operationEnd(operationOk);
}
}
}