use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTree method deactivate.
@Override
public void deactivate(boolean flushOnExit) throws HyracksDataException {
if (!isActive) {
throw new HyracksDataException("Failed to deactivate the index since it is already deactivated.");
}
if (flushOnExit) {
BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(ioOpCallback);
cb.afterFinalize(LSMOperationType.FLUSH, null);
}
for (ILSMComponent c : diskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.deactivateCloseHandle();
bloomFilter.deactivate();
}
for (ILSMComponent c : secondDiskComponents) {
// Only deactivate non shared components (So components are not de-activated twice)
if (!diskComponents.contains(c)) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.deactivateCloseHandle();
bloomFilter.deactivate();
}
}
isActive = false;
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTree method clear.
// The clear method is not used anywhere in AsterixDB! we override it anyway
// to exit components first and deal with the two lists
@Override
public void clear() throws HyracksDataException {
if (!isActive) {
throw new HyracksDataException("Failed to clear the index since it is not activated.");
}
getLsmHarness().indexClear();
for (ILSMComponent c : diskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
component.getBloomFilter().deactivate();
component.getBTree().deactivate();
component.getBloomFilter().destroy();
component.getBTree().destroy();
// Remove from second list to avoid destroying twice
secondDiskComponents.remove(c);
}
for (ILSMComponent c : secondDiskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
component.getBloomFilter().deactivate();
component.getBTree().deactivate();
component.getBloomFilter().destroy();
component.getBTree().destroy();
}
diskComponents.clear();
secondDiskComponents.clear();
version = 0;
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTree method scheduleMerge.
// The only reason to override the following method is that it uses a different context object
// in addition, determining whether or not to keep deleted tuples is different here
@Override
public void scheduleMerge(ILSMIndexOperationContext ctx, ILSMIOOperationCallback callback) throws HyracksDataException {
ExternalBTreeOpContext opCtx = createOpContext(NoOpOperationCallback.INSTANCE, -1);
opCtx.setOperation(IndexOperation.MERGE);
List<ILSMComponent> mergingComponents = ctx.getComponentHolder();
boolean returnDeletedTuples = false;
if (version == 0) {
if (ctx.getComponentHolder().get(ctx.getComponentHolder().size() - 1) != diskComponents.get(diskComponents.size() - 1)) {
returnDeletedTuples = true;
}
} else {
if (ctx.getComponentHolder().get(ctx.getComponentHolder().size() - 1) != secondDiskComponents.get(secondDiskComponents.size() - 1)) {
returnDeletedTuples = true;
}
}
ITreeIndexCursor cursor = new LSMBTreeRangeSearchCursor(opCtx, returnDeletedTuples);
BTree firstBTree = ((LSMBTreeDiskComponent) mergingComponents.get(0)).getBTree();
BTree lastBTree = ((LSMBTreeDiskComponent) mergingComponents.get(mergingComponents.size() - 1)).getBTree();
FileReference firstFile = firstBTree.getFileReference();
FileReference lastFile = lastBTree.getFileReference();
LSMComponentFileReferences relMergeFileRefs = fileManager.getRelMergeFileReference(firstFile.getFile().getName(), lastFile.getFile().getName());
ILSMIndexAccessor accessor = new LSMTreeIndexAccessor(getLsmHarness(), opCtx, cursorFactory);
ioScheduler.scheduleOperation(new LSMBTreeMergeOperation(accessor, mergingComponents, cursor, relMergeFileRefs.getInsertIndexFileReference(), relMergeFileRefs.getBloomFilterFileReference(), callback, fileManager.getBaseDir()));
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTreeWithBuddy method activate.
@Override
public void activate() throws HyracksDataException {
if (isActive) {
throw new HyracksDataException("Failed to activate the index since it is already activated.");
}
if (diskComponents.size() == 0 && secondDiskComponents.size() == 0) {
//First time activation
List<LSMComponentFileReferences> validFileReferences;
validFileReferences = fileManager.cleanupAndGetValidFiles();
for (LSMComponentFileReferences lsmComonentFileReference : validFileReferences) {
LSMBTreeWithBuddyDiskComponent component;
component = createDiskComponent(componentFactory, lsmComonentFileReference.getInsertIndexFileReference(), lsmComonentFileReference.getDeleteIndexFileReference(), lsmComonentFileReference.getBloomFilterFileReference(), false);
diskComponents.add(component);
secondDiskComponents.add(component);
}
((ExternalIndexHarness) getLsmHarness()).indexFirstTimeActivated();
} else {
// components. It should also maintain the version pointer
for (ILSMComponent c : diskComponents) {
LSMBTreeWithBuddyDiskComponent component = (LSMBTreeWithBuddyDiskComponent) c;
BTree btree = component.getBTree();
BTree buddyBtree = component.getBuddyBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.activate();
buddyBtree.activate();
bloomFilter.activate();
}
for (ILSMComponent c : secondDiskComponents) {
// Only activate non shared components
if (!diskComponents.contains(c)) {
LSMBTreeWithBuddyDiskComponent component = (LSMBTreeWithBuddyDiskComponent) c;
BTree btree = component.getBTree();
BTree buddyBtree = component.getBuddyBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.activate();
buddyBtree.activate();
bloomFilter.activate();
}
}
}
isActive = true;
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent 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