use of org.apache.hyracks.storage.am.lsm.btree.tuples.LSMBTreeTupleReference in project asterixdb by apache.
the class LSMBTree method insert.
private boolean insert(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException {
LSMBTreePointSearchCursor searchCursor = ctx.getInsertSearchCursor();
IIndexCursor memCursor = ctx.getMemCursor();
RangePredicate predicate = (RangePredicate) ctx.getSearchPredicate();
predicate.setHighKey(tuple);
predicate.setLowKey(tuple);
if (needKeyDupCheck) {
// first check the inmemory component
ctx.getCurrentMutableBTreeAccessor().search(memCursor, predicate);
try {
if (memCursor.hasNext()) {
memCursor.next();
LSMBTreeTupleReference lsmbtreeTuple = (LSMBTreeTupleReference) memCursor.getTuple();
if (!lsmbtreeTuple.isAntimatter()) {
throw HyracksDataException.create(ErrorCode.DUPLICATE_KEY);
} else {
memCursor.close();
ctx.getCurrentMutableBTreeAccessor().upsertIfConditionElseInsert(tuple, AntimatterAwareTupleAcceptor.INSTANCE);
return true;
}
}
} finally {
memCursor.close();
}
// TODO: Can we just remove the above code that search the mutable
// component and do it together with the search call below? i.e. instead
// of passing false to the lsmHarness.search(), we pass true to include
// the mutable component?
// the key was not in the inmemory component, so check the disk
// components
// This is a hack to avoid searching the current active mutable component twice. It is critical to add it back once the search is over.
ILSMComponent firstComponent = ctx.getComponentHolder().remove(0);
search(ctx, searchCursor, predicate);
try {
if (searchCursor.hasNext()) {
throw HyracksDataException.create(ErrorCode.DUPLICATE_KEY);
}
} finally {
searchCursor.close();
// Add the current active mutable component back
ctx.getComponentHolder().add(0, firstComponent);
}
}
ctx.getCurrentMutableBTreeAccessor().upsertIfConditionElseInsert(tuple, AntimatterAwareTupleAcceptor.INSTANCE);
return true;
}
Aggregations