/* We need to descend down into a duplicate tree. */
DIN duplicateRoot = null;
boolean duplicateRootIsLatched = false;
DBIN duplicateBin = null;
BIN bin = (BIN) in;
boolean binIsLatched = true;
try {
int index = bin.findEntry(mainKey, false, true);
if (index >= 0) {
Node node = null;
if (!bin.isEntryKnownDeleted(index)) {
/*
* If fetchTarget returns null, a deleted LN was cleaned.
*/
node = bin.fetchTarget(index);
}
if (node == null) {
bin.releaseLatch();
binIsLatched = false;
return null;
}
if (node.containsDuplicates()) {
/* It's a duplicate tree. */
duplicateRoot = (DIN) node;
duplicateRoot.latch(CacheMode.UNCHANGED);
duplicateRootIsLatched = true;
bin.releaseLatch();
binIsLatched = false;
duplicateBin = (DBIN) tree.searchSubTree
(duplicateRoot, dupKey, SearchType.NORMAL, -1, null,
CacheMode.UNCHANGED);
duplicateRootIsLatched = false;
return duplicateBin;
} else {
/* We haven't migrated to a duplicate tree yet. */
return bin;
}
} else {
bin.releaseLatch();
binIsLatched = false;
return null;
}
} catch (DatabaseException DBE) {
if (bin != null &&
binIsLatched) {
bin.releaseLatch();
}
if (duplicateRoot != null &&
duplicateRootIsLatched) {
duplicateRoot.releaseLatch();