Search in sources :

Example 16 with LSMComponentFileReferences

use of org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences in project asterixdb by apache.

the class ExternalBTreeWithBuddy method commitTransaction.

@Override
public void commitTransaction() throws HyracksDataException {
    LSMComponentFileReferences componentFileRefrences = fileManager.getTransactionFileReferenceForCommit();
    LSMBTreeWithBuddyDiskComponent component = null;
    if (componentFileRefrences != null) {
        component = createDiskComponent(componentFactory, componentFileRefrences.getInsertIndexFileReference(), componentFileRefrences.getDeleteIndexFileReference(), componentFileRefrences.getBloomFilterFileReference(), false);
    }
    ((ExternalIndexHarness) getLsmHarness()).addTransactionComponents(component);
}
Also used : ExternalIndexHarness(org.apache.hyracks.storage.am.lsm.common.impls.ExternalIndexHarness) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)

Example 17 with LSMComponentFileReferences

use of org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences 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));
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) LSMTreeIndexAccessor(org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor) ILSMIndexOperationContext(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)

Example 18 with LSMComponentFileReferences

use of org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences in project asterixdb by apache.

the class LSMBTreeFileManager method cleanupAndGetValidFiles.

@Override
public List<LSMComponentFileReferences> cleanupAndGetValidFiles() throws HyracksDataException {
    List<LSMComponentFileReferences> validFiles = new ArrayList<>();
    ArrayList<ComparableFileName> allBTreeFiles = new ArrayList<>();
    ArrayList<ComparableFileName> allBloomFilterFiles = new ArrayList<>();
    // create transaction filter <to hide transaction files>
    FilenameFilter transactionFilter = getTransactionFileFilter(false);
    // Gather files
    // List of valid BTree files.
    cleanupAndGetValidFilesInternal(getCompoundFilter(transactionFilter, btreeFilter), btreeFactory, allBTreeFiles);
    HashSet<String> btreeFilesSet = new HashSet<>();
    for (ComparableFileName cmpFileName : allBTreeFiles) {
        int index = cmpFileName.fileName.lastIndexOf(SPLIT_STRING);
        btreeFilesSet.add(cmpFileName.fileName.substring(0, index));
    }
    if (hasBloomFilter) {
        validateFiles(btreeFilesSet, allBloomFilterFiles, getCompoundFilter(transactionFilter, bloomFilterFilter), null);
        // Sanity check.
        if (allBTreeFiles.size() != allBloomFilterFiles.size()) {
            throw new HyracksDataException("Unequal number of valid BTree and bloom filter files found. Aborting cleanup.");
        }
    }
    // Trivial cases.
    if (allBTreeFiles.isEmpty() || hasBloomFilter && allBloomFilterFiles.isEmpty()) {
        return validFiles;
    }
    // Special case: sorting is not required
    if (allBTreeFiles.size() == 1 && (!hasBloomFilter || allBloomFilterFiles.size() == 1)) {
        validFiles.add(new LSMComponentFileReferences(allBTreeFiles.get(0).fileRef, null, hasBloomFilter ? allBloomFilterFiles.get(0).fileRef : null));
        return validFiles;
    }
    // Sorts files names from earliest to latest timestamp.
    Collections.sort(allBTreeFiles);
    if (hasBloomFilter) {
        Collections.sort(allBloomFilterFiles);
    }
    List<ComparableFileName> validComparableBTreeFiles = new ArrayList<>();
    ComparableFileName lastBTree = allBTreeFiles.get(0);
    validComparableBTreeFiles.add(lastBTree);
    List<ComparableFileName> validComparableBloomFilterFiles = null;
    ComparableFileName lastBloomFilter = null;
    if (hasBloomFilter) {
        validComparableBloomFilterFiles = new ArrayList<>();
        lastBloomFilter = allBloomFilterFiles.get(0);
        validComparableBloomFilterFiles.add(lastBloomFilter);
    }
    ComparableFileName currentBTree = null;
    ComparableFileName currentBloomFilter = null;
    for (int i = 1; i < allBTreeFiles.size(); i++) {
        currentBTree = allBTreeFiles.get(i);
        if (hasBloomFilter) {
            currentBloomFilter = allBloomFilterFiles.get(i);
        }
        // Current start timestamp is greater than last stop timestamp.
        if (currentBTree.interval[0].compareTo(lastBTree.interval[1]) > 0 && (!hasBloomFilter || currentBloomFilter.interval[0].compareTo(lastBloomFilter.interval[1]) > 0)) {
            validComparableBTreeFiles.add(currentBTree);
            lastBTree = currentBTree;
            if (hasBloomFilter) {
                validComparableBloomFilterFiles.add(currentBloomFilter);
                lastBloomFilter = currentBloomFilter;
            }
        } else if (currentBTree.interval[0].compareTo(lastBTree.interval[0]) >= 0 && currentBTree.interval[1].compareTo(lastBTree.interval[1]) <= 0 && (!hasBloomFilter || (currentBloomFilter.interval[0].compareTo(lastBloomFilter.interval[0]) >= 0 && currentBloomFilter.interval[1].compareTo(lastBloomFilter.interval[1]) <= 0))) {
            // Invalid files are completely contained in last interval.
            File invalidBTreeFile = new File(currentBTree.fullPath);
            invalidBTreeFile.delete();
            if (hasBloomFilter) {
                File invalidBloomFilterFile = new File(currentBloomFilter.fullPath);
                invalidBloomFilterFile.delete();
            }
        } else {
            // This scenario should not be possible.
            throw new HyracksDataException("Found LSM files with overlapping but not contained timetamp intervals.");
        }
    }
    // Sort valid files in reverse lexicographical order, such that newer
    // files come first.
    Collections.sort(validComparableBTreeFiles, recencyCmp);
    Iterator<ComparableFileName> btreeFileIter = validComparableBTreeFiles.iterator();
    Iterator<ComparableFileName> bloomFilterFileIter = null;
    if (hasBloomFilter) {
        Collections.sort(validComparableBloomFilterFiles, recencyCmp);
        bloomFilterFileIter = validComparableBloomFilterFiles.iterator();
    }
    ComparableFileName cmpBTreeFileName = null;
    ComparableFileName cmpBloomFilterFileName = null;
    while (btreeFileIter.hasNext() && (hasBloomFilter ? bloomFilterFileIter.hasNext() : true)) {
        cmpBTreeFileName = btreeFileIter.next();
        if (hasBloomFilter) {
            cmpBloomFilterFileName = bloomFilterFileIter.next();
        }
        validFiles.add(new LSMComponentFileReferences(cmpBTreeFileName.fileRef, null, hasBloomFilter ? cmpBloomFilterFileName.fileRef : null));
    }
    return validFiles;
}
Also used : ArrayList(java.util.ArrayList) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) FilenameFilter(java.io.FilenameFilter) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences) File(java.io.File) HashSet(java.util.HashSet)

Example 19 with LSMComponentFileReferences

use of org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences in project asterixdb by apache.

the class LSMBTree method createDiskComponent.

protected LSMBTreeDiskComponent createDiskComponent(LSMBTreeDiskComponentFactory factory, FileReference btreeFileRef, FileReference bloomFilterFileRef, boolean createComponent) throws HyracksDataException {
    // Create new BTree instance.
    LSMBTreeDiskComponent component = factory.createComponent(new LSMComponentFileReferences(btreeFileRef, null, bloomFilterFileRef));
    // BTree will be closed during cleanup of merge().
    if (createComponent) {
        component.getBTree().create();
    }
    component.getBTree().activate();
    if (hasBloomFilter) {
        if (createComponent) {
            component.getBloomFilter().create();
        }
        component.getBloomFilter().activate();
    }
    if (component.getLSMComponentFilter() != null && !createComponent) {
        getFilterManager().readFilter(component.getLSMComponentFilter(), component.getBTree());
    }
    return component;
}
Also used : LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)

Aggregations

LSMComponentFileReferences (org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)19 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)10 File (java.io.File)8 FilenameFilter (java.io.FilenameFilter)7 FileReference (org.apache.hyracks.api.io.FileReference)6 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)6 ArrayList (java.util.ArrayList)5 BTree (org.apache.hyracks.storage.am.btree.impls.BTree)5 HashSet (java.util.HashSet)4 IOException (java.io.IOException)3 BloomFilter (org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilter)3 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)3 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)3 ILSMIndexOperationContext (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext)2 ExternalIndexHarness (org.apache.hyracks.storage.am.lsm.common.impls.ExternalIndexHarness)2 LSMTreeIndexAccessor (org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor)2 Date (java.util.Date)1 ILSMIndexFileManager (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexFileManager)1 TestLsmIndexFileManager (org.apache.hyracks.storage.am.lsm.common.component.TestLsmIndexFileManager)1 RTree (org.apache.hyracks.storage.am.rtree.impls.RTree)1