* See [SR #10203] for a description of the bug that existed before
* this change.
*/
/* Create the first version of DupCountLN and log it. (Entry 1). */
Locker locker = cursor.getLocker();
int startingCount = locker.createdNode(existingLN.getNodeId()) ? 0 : 1;
DupCountLN dupCountLN = new DupCountLN(startingCount);
long firstDupCountLNLsn =
dupCountLN.logProvisional(env, database.getId(),
key, DbLsn.NULL_LSN);
/* Make the duplicate root and DBIN. */
duplicateRoot = new DIN(database,
existingKey, // idkey
maxDupTreeEntriesPerNode,
key, // dup key
new ChildReference
(dupCountLN, key, firstDupCountLNLsn),
2); // level
duplicateRoot.latch();
duplicateRoot.setIsRoot(true);
duplicateBin = new DBIN(database,
existingKey, // idkey
maxDupTreeEntriesPerNode,
key, // dup key
1); // level
duplicateBin.latch();
/*
* Attach the existing LN child to the duplicate BIN. Since this is a
* newly created BIN, insertEntry will be successful.
*/
ChildReference newExistingLNRef = new ChildReference
(existingLN, existingKey, bin.getLsn(index), bin.getState(index));
boolean insertOk = duplicateBin.insertEntry(newExistingLNRef);
assert insertOk;
try {
/* Entry 2: DBIN. */
long dbinLsn = duplicateBin.logProvisional
(logManager, duplicateRoot);
inMemoryINs.add(duplicateBin);
/* Attach the duplicate BIN to the duplicate IN root. */
duplicateRoot.setEntry(0, duplicateBin, duplicateBin.getKey(0),
dbinLsn, duplicateBin.getState(0));
/* Entry 3: DIN */
long dinLsn = duplicateRoot.log(logManager);
inMemoryINs.add(duplicateRoot);
/*
* Now that the DIN is logged, we've created a duplicate tree that
* holds the single, preexisting LN. We can safely create the non
* provisional LNs that pertain to this insert -- the new LN and
* the new DupCountLN.
*
* We request a lock while holding latches which is usually
* forbidden, but safe in this case since we know it will be
* immediately granted (we just created dupCountLN above).
*/
LockResult lockResult = locker.lock
(dupCountLN.getNodeId(), LockType.WRITE, database);
lockResult.setAbortLsn(firstDupCountLNLsn, false);
dupCountLN.setDupCount(2);
long dupCountLsn = dupCountLN.log(env, database.getId(), key,