Search in sources :

Example 6 with LSMComponentFileReferences

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

the class LSMBTreeWithBuddyFileManager method getTransactionFileReferenceForCommit.

@Override
public LSMComponentFileReferences getTransactionFileReferenceForCommit() throws HyracksDataException {
    FilenameFilter transactionFilter;
    File dir = new File(baseDir);
    String[] files = dir.list(transactionFileNameFilter);
    if (files.length == 0) {
        return null;
    }
    if (files.length != 1) {
        throw new HyracksDataException("More than one transaction lock found:" + files.length);
    } else {
        transactionFilter = getTransactionFileFilter(true);
        String txnFileName = dir.getPath() + File.separator + files[0];
        // get the actual transaction files
        files = dir.list(transactionFilter);
        if (files.length < 3) {
            throw new HyracksDataException("LSM Btree with buddy transaction has less than 3 files :" + files.length);
        }
        try {
            Files.delete(Paths.get(txnFileName));
        } catch (IOException e) {
            throw new HyracksDataException("Failed to delete transaction lock :" + txnFileName);
        }
    }
    File bTreeFile = null;
    File buddyBTreeFile = null;
    File bloomFilterFile = null;
    for (String fileName : files) {
        if (fileName.endsWith(BTREE_STRING)) {
            bTreeFile = new File(dir.getPath() + File.separator + fileName);
        } else if (fileName.endsWith(BUDDY_BTREE_STRING)) {
            buddyBTreeFile = new File(dir.getPath() + File.separator + fileName);
        } else if (fileName.endsWith(BLOOM_FILTER_STRING)) {
            bloomFilterFile = new File(dir.getPath() + File.separator + fileName);
        } else {
            throw new HyracksDataException("unrecognized file found = " + fileName);
        }
    }
    FileReference bTreeFileRef = ioManager.resolveAbsolutePath(bTreeFile.getAbsolutePath());
    FileReference buddyBTreeFileRef = ioManager.resolveAbsolutePath(buddyBTreeFile.getAbsolutePath());
    FileReference bloomFilterFileRef = ioManager.resolveAbsolutePath(bloomFilterFile.getAbsolutePath());
    return new LSMComponentFileReferences(bTreeFileRef, buddyBTreeFileRef, bloomFilterFileRef);
}
Also used : FilenameFilter(java.io.FilenameFilter) IOException(java.io.IOException) FileReference(org.apache.hyracks.api.io.FileReference) File(java.io.File) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 7 with LSMComponentFileReferences

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

the class LSMIndexFileManagerTest method cleanInvalidFilesTest.

public void cleanInvalidFilesTest(IOManager ioManager) throws InterruptedException, IOException {
    String dirPath = ioManager.getIODevices().get(DEFAULT_IO_DEVICE_ID).getMount() + sep + "lsm_tree" + simpleDateFormat.format(new Date()) + sep;
    File f = new File(dirPath);
    f.mkdirs();
    FileReference file = ioManager.resolveAbsolutePath(f.getAbsolutePath());
    ILSMIndexFileManager fileManager = new TestLsmIndexFileManager(ioManager, fileMapProvider, file);
    fileManager.createDirs();
    List<FileReference> flushFiles = new ArrayList<>();
    List<FileReference> allFiles = new ArrayList<>();
    int numFileNames = 100;
    long sleepTime = 5;
    // Generate a bunch of flush files.
    for (int i = 0; i < numFileNames; i++) {
        LSMComponentFileReferences relFlushFileRefs = fileManager.getRelFlushFileReference();
        flushFiles.add(relFlushFileRefs.getInsertIndexFileReference());
        Thread.sleep(sleepTime);
    }
    allFiles.addAll(flushFiles);
    // Simulate merging some of the flush files.
    // Merge range 0 to 4.
    FileReference mergeFile1 = simulateMerge(fileManager, flushFiles.get(0), flushFiles.get(4));
    allFiles.add(mergeFile1);
    // Merge range 5 to 9.
    FileReference mergeFile2 = simulateMerge(fileManager, flushFiles.get(5), flushFiles.get(9));
    allFiles.add(mergeFile2);
    // Merge range 10 to 19.
    FileReference mergeFile3 = simulateMerge(fileManager, flushFiles.get(10), flushFiles.get(19));
    allFiles.add(mergeFile3);
    // Merge range 20 to 29.
    FileReference mergeFile4 = simulateMerge(fileManager, flushFiles.get(20), flushFiles.get(29));
    allFiles.add(mergeFile4);
    // Merge range 50 to 79.
    FileReference mergeFile5 = simulateMerge(fileManager, flushFiles.get(50), flushFiles.get(79));
    allFiles.add(mergeFile5);
    // Simulate merging of merge files.
    FileReference mergeFile6 = simulateMerge(fileManager, mergeFile1, mergeFile2);
    allFiles.add(mergeFile6);
    FileReference mergeFile7 = simulateMerge(fileManager, mergeFile3, mergeFile4);
    allFiles.add(mergeFile7);
    // Create all files and set delete on exit for all files.
    for (FileReference fileRef : allFiles) {
        fileRef.getFile().createNewFile();
        fileRef.getFile().deleteOnExit();
    }
    // Populate expected valid flush files.
    List<String> expectedValidFiles = new ArrayList<>();
    for (int i = 30; i < 50; i++) {
        expectedValidFiles.add(flushFiles.get(i).getFile().getName());
    }
    for (int i = 80; i < 100; i++) {
        expectedValidFiles.add(flushFiles.get(i).getFile().getName());
    }
    // Populate expected valid merge files.
    expectedValidFiles.add(mergeFile5.getFile().getName());
    expectedValidFiles.add(mergeFile6.getFile().getName());
    expectedValidFiles.add(mergeFile7.getFile().getName());
    // Sort expected files.
    Collections.sort(expectedValidFiles, fileManager.getFileNameComparator());
    // Pass null and a dummy component finalizer. We don't test for physical consistency in this test.
    List<LSMComponentFileReferences> lsmComonentFileReference = fileManager.cleanupAndGetValidFiles();
    // Check actual files against expected files.
    assertEquals(expectedValidFiles.size(), lsmComonentFileReference.size());
    for (int i = 0; i < expectedValidFiles.size(); i++) {
        assertEquals(expectedValidFiles.get(i), lsmComonentFileReference.get(i).getInsertIndexFileReference().getFile().getName());
    }
    // Make sure invalid files were removed from the IODevices.
    ArrayList<String> remainingFiles = new ArrayList<>();
    File dir = new File(dirPath);
    FilenameFilter filter = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return !name.startsWith(".");
        }
    };
    String[] files = dir.list(filter);
    for (String aFilePath : files) {
        File aFile = new File(aFilePath);
        remainingFiles.add(aFile.getName());
    }
    Collections.sort(remainingFiles, fileManager.getFileNameComparator());
    // Check actual files in directory against expected files.
    assertEquals(expectedValidFiles.size(), remainingFiles.size());
    for (int i = 0; i < expectedValidFiles.size(); i++) {
        assertEquals(expectedValidFiles.get(i), remainingFiles.get(i));
    }
}
Also used : ILSMIndexFileManager(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexFileManager) ArrayList(java.util.ArrayList) TestLsmIndexFileManager(org.apache.hyracks.storage.am.lsm.common.component.TestLsmIndexFileManager) Date(java.util.Date) FilenameFilter(java.io.FilenameFilter) FileReference(org.apache.hyracks.api.io.FileReference) File(java.io.File) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)

Example 8 with LSMComponentFileReferences

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

the class LSMBTreeFileManager method getTransactionFileReferenceForCommit.

@Override
public LSMComponentFileReferences getTransactionFileReferenceForCommit() throws HyracksDataException {
    FilenameFilter transactionFilter;
    File dir = new File(baseDir);
    String[] files = dir.list(transactionFileNameFilter);
    if (files.length == 0) {
        return null;
    }
    if (files.length != 1) {
        throw new HyracksDataException("More than one transaction lock found:" + files.length);
    } else {
        transactionFilter = getTransactionFileFilter(true);
        String txnFileName = dir.getPath() + File.separator + files[0];
        // get the actual transaction files
        files = dir.list(transactionFilter);
        if (files.length < 2) {
            throw new HyracksDataException("LSM Btree transaction has less than 2 files :" + files.length);
        }
        try {
            Files.delete(Paths.get(txnFileName));
        } catch (IOException e) {
            throw new HyracksDataException("Failed to delete transaction lock :" + txnFileName);
        }
    }
    File bTreeFile = null;
    File bloomFilterFile = null;
    for (String fileName : files) {
        if (fileName.endsWith(BTREE_STRING)) {
            bTreeFile = new File(dir.getPath() + File.separator + fileName);
        } else if (fileName.endsWith(BLOOM_FILTER_STRING)) {
            bloomFilterFile = new File(dir.getPath() + File.separator + fileName);
        } else {
            throw new HyracksDataException("unrecognized file found = " + fileName);
        }
    }
    FileReference bTreeFileRef = ioManager.resolveAbsolutePath(bTreeFile.getAbsolutePath());
    FileReference bloomFilterFileRef = ioManager.resolveAbsolutePath(bloomFilterFile.getAbsolutePath());
    return new LSMComponentFileReferences(bTreeFileRef, null, bloomFilterFileRef);
}
Also used : FilenameFilter(java.io.FilenameFilter) IOException(java.io.IOException) FileReference(org.apache.hyracks.api.io.FileReference) File(java.io.File) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 9 with LSMComponentFileReferences

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

Example 10 with LSMComponentFileReferences

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

the class ExternalBTreeWithBuddy method getMergeTargetFileName.

protected LSMComponentFileReferences getMergeTargetFileName(List<ILSMComponent> mergingDiskComponents) throws HyracksDataException {
    BTree firstTree = ((LSMBTreeWithBuddyDiskComponent) mergingDiskComponents.get(0)).getBTree();
    BTree lastTree = ((LSMBTreeWithBuddyDiskComponent) mergingDiskComponents.get(mergingDiskComponents.size() - 1)).getBTree();
    FileReference firstFile = firstTree.getFileReference();
    FileReference lastFile = lastTree.getFileReference();
    LSMComponentFileReferences fileRefs = fileManager.getRelMergeFileReference(firstFile.getFile().getName(), lastFile.getFile().getName());
    return fileRefs;
}
Also used : BTree(org.apache.hyracks.storage.am.btree.impls.BTree) FileReference(org.apache.hyracks.api.io.FileReference) 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