use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTree method destroy.
@Override
public void destroy() throws HyracksDataException {
if (isActive) {
throw new HyracksDataException("Failed to destroy the index since it is activated.");
}
for (ILSMComponent c : diskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
component.getBTree().destroy();
component.getBloomFilter().destroy();
// Remove from second list to avoid destroying twice
secondDiskComponents.remove(c);
}
for (ILSMComponent c : secondDiskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
component.getBTree().destroy();
component.getBloomFilter().destroy();
}
diskComponents.clear();
secondDiskComponents.clear();
fileManager.deleteDirs();
version = 0;
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTree method activate.
@Override
public synchronized 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) {
LSMBTreeDiskComponent component;
component = createDiskComponent(componentFactory, lsmComonentFileReference.getInsertIndexFileReference(), lsmComonentFileReference.getBloomFilterFileReference(), false);
diskComponents.add(component);
secondDiskComponents.add(component);
}
getLsmHarness().indexFirstTimeActivated();
} else {
// This index has been opened before
for (ILSMComponent c : diskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.activate();
bloomFilter.activate();
}
for (ILSMComponent c : secondDiskComponents) {
// Only activate non shared components
if (!diskComponents.contains(c)) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.activate();
bloomFilter.activate();
}
}
}
isActive = true;
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class ExternalBTreeWithBuddy method scheduleMerge.
@Override
public void scheduleMerge(ILSMIndexOperationContext ctx, ILSMIOOperationCallback callback) throws HyracksDataException {
ILSMIndexOperationContext bctx = createOpContext(NoOpOperationCallback.INSTANCE, 0);
bctx.setOperation(IndexOperation.MERGE);
List<ILSMComponent> mergingComponents = ctx.getComponentHolder();
ITreeIndexCursor cursor = new LSMBTreeWithBuddySortedCursor(bctx, buddyBTreeFields);
LSMComponentFileReferences relMergeFileRefs = getMergeTargetFileName(mergingComponents);
ILSMIndexAccessor accessor = new LSMTreeIndexAccessor(getLsmHarness(), bctx, opCtx -> new LSMBTreeWithBuddySearchCursor(opCtx, buddyBTreeFields));
// Since we have two lists of components, to tell whether we need to
// keep deleted tuples, we need to know
// which list to check against and we need to synchronize for this
boolean keepDeleteTuples = false;
if (version == 0) {
keepDeleteTuples = mergingComponents.get(mergingComponents.size() - 1) != diskComponents.get(diskComponents.size() - 1);
} else {
keepDeleteTuples = mergingComponents.get(mergingComponents.size() - 1) != secondDiskComponents.get(secondDiskComponents.size() - 1);
}
ioScheduler.scheduleOperation(new LSMBTreeWithBuddyMergeOperation(accessor, mergingComponents, cursor, relMergeFileRefs.getInsertIndexFileReference(), relMergeFileRefs.getDeleteIndexFileReference(), relMergeFileRefs.getBloomFilterFileReference(), callback, fileManager.getBaseDir(), keepDeleteTuples));
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class LSMBTreePointSearchCursor method open.
@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
LSMBTreeCursorInitialState lsmInitialState = (LSMBTreeCursorInitialState) initialState;
operationalComponents = lsmInitialState.getOperationalComponents();
lsmHarness = lsmInitialState.getLSMHarness();
searchCallback = lsmInitialState.getSearchOperationCallback();
predicate = (RangePredicate) lsmInitialState.getSearchPredicate();
numBTrees = operationalComponents.size();
if (rangeCursors == null || rangeCursors.length != numBTrees) {
// object creation: should be relatively low
rangeCursors = new BTreeRangeSearchCursor[numBTrees];
btreeAccessors = new BTreeAccessor[numBTrees];
}
includeMutableComponent = false;
for (int i = 0; i < numBTrees; i++) {
ILSMComponent component = operationalComponents.get(i);
BTree btree;
if (component.getType() == LSMComponentType.MEMORY) {
includeMutableComponent = true;
// No need for a bloom filter for the in-memory BTree.
if (rangeCursors[i] == null || rangeCursors[i].isBloomFilterAware()) {
// create a new one
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getLeafFrameFactory().createFrame();
rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
} else {
// reset
rangeCursors[i].reset();
}
btree = ((LSMBTreeMemoryComponent) component).getBTree();
} else {
if (rangeCursors[i] != null && rangeCursors[i].isBloomFilterAware()) {
// can re-use cursor
((BloomFilterAwareBTreePointSearchCursor) rangeCursors[i]).resetBloomFilter(((LSMBTreeDiskComponent) component).getBloomFilter());
rangeCursors[i].reset();
} else {
// create new cursor <should be relatively rare>
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getLeafFrameFactory().createFrame();
rangeCursors[i] = new BloomFilterAwareBTreePointSearchCursor(leafFrame, false, ((LSMBTreeDiskComponent) component).getBloomFilter());
}
btree = ((LSMBTreeDiskComponent) component).getBTree();
}
if (btreeAccessors[i] == null) {
btreeAccessors[i] = (BTreeAccessor) btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
} else {
// re-use
btreeAccessors[i].reset(btree, NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
}
}
nextHasBeenCalled = false;
foundTuple = false;
}
use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.
the class LSMRTreeDeletedKeysBTreeMergeCursor method open.
@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState;
cmp = lsmInitialState.getBTreeCmp();
operationalComponents = lsmInitialState.getOperationalComponents();
// We intentionally set the lsmHarness to null so that we don't call lsmHarness.endSearch() because we already do that when we merge r-trees.
lsmHarness = null;
int numBTrees = operationalComponents.size();
rangeCursors = new IIndexCursor[numBTrees];
RangePredicate btreePredicate = new RangePredicate(null, null, true, true, cmp, cmp);
IIndexAccessor[] btreeAccessors = new ITreeIndexAccessor[numBTrees];
for (int i = 0; i < numBTrees; i++) {
ILSMComponent component = operationalComponents.get(i);
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame();
rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
BTree btree = ((LSMRTreeDiskComponent) component).getBTree();
btreeAccessors[i] = btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
btreeAccessors[i].search(rangeCursors[i], btreePredicate);
}
setPriorityQueueComparator();
initPriorityQueue();
}
Aggregations