Search in sources :

Example 1 with LocalIndexFile

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile in project jackrabbit-oak by apache.

the class IndexCopier method successfullyDeleted.

private void successfullyDeleted(LocalIndexFile file, boolean fileExisted) {
    LocalIndexFile failedToDeleteFile = failedToDeleteFiles.remove(file.getKey());
    if (failedToDeleteFile != null) {
        log.debug("Deleted : {}", failedToDeleteFile.deleteLog());
    }
    if (fileExisted) {
        garbageCollectedSize.addAndGet(file.getSize());
        deletedFileCount.incrementAndGet();
    }
}
Also used : LocalIndexFile(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile)

Example 2 with LocalIndexFile

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile in project jackrabbit-oak by apache.

the class IndexCopier method deleteFile.

public boolean deleteFile(Directory dir, String fileName, boolean copiedFromRemote) {
    LocalIndexFile file = new LocalIndexFile(dir, fileName, DirectoryUtils.getFileLength(dir, fileName), copiedFromRemote);
    boolean successFullyDeleted = false;
    try {
        boolean fileExisted = false;
        if (dir.fileExists(fileName)) {
            fileExisted = true;
            dir.deleteFile(fileName);
        }
        successfullyDeleted(file, fileExisted);
        successFullyDeleted = true;
    } catch (IOException e) {
        failedToDelete(file);
        log.debug("Error occurred while removing deleted file {} from Local {}. " + "Attempt would be made to delete it on next run ", fileName, dir, e);
    }
    return successFullyDeleted;
}
Also used : LocalIndexFile(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile) IOException(java.io.IOException)

Example 3 with LocalIndexFile

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile in project jackrabbit-oak by apache.

the class IndexCopier method failedToDelete.

private void failedToDelete(LocalIndexFile file) {
    //Limit the size on best effort basis
    if (failedToDeleteFiles.size() < MAX_FAILURE_ENTRIES) {
        LocalIndexFile failedToDeleteFile = failedToDeleteFiles.putIfAbsent(file.getKey(), file);
        if (failedToDeleteFile == null) {
            failedToDeleteFile = file;
        }
        failedToDeleteFile.incrementAttemptToDelete();
    } else {
        log.warn("Not able to delete {}. Currently more than {} file with total size {} are pending delete.", file.deleteLog(), failedToDeleteFiles.size(), getGarbageSize());
    }
}
Also used : LocalIndexFile(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile)

Example 4 with LocalIndexFile

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile in project jackrabbit-oak by apache.

the class IndexCopierTest method failureInDelete.

@Test
public void failureInDelete() throws Exception {
    final Set<String> testFiles = new HashSet<String>();
    Directory baseDir = new CloseSafeDir() {

        @Override
        public void deleteFile(String name) throws IOException {
            if (testFiles.contains(name)) {
                throw new IOException("Not allowed to delete " + name);
            }
            super.deleteFile(name);
        }
    };
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
    IndexCopier c1 = new RAMIndexCopier(baseDir, sameThreadExecutor(), getWorkDir());
    Directory r1 = new RAMDirectory();
    byte[] t1 = writeFile(r1, "t1");
    byte[] t2 = writeFile(r1, "t2");
    Directory w1 = c1.wrapForRead("/foo", defn, r1, INDEX_DATA_CHILD_NAME);
    readAndAssert(w1, "t1", t1);
    readAndAssert(w1, "t2", t2);
    // t1 and t2 should now be present in local (base dir which back local)
    assertTrue(baseDir.fileExists("t1"));
    assertTrue(baseDir.fileExists("t2"));
    Directory r2 = new CloseSafeDir();
    copy(r1, r2);
    r2.deleteFile("t1");
    Directory w2 = c1.wrapForRead("/foo", defn, r2, INDEX_DATA_CHILD_NAME);
    //Close would trigger removal of file which are not present in remote
    testFiles.add("t1");
    w2.close();
    assertEquals(1, c1.getFailedToDeleteFiles().size());
    LocalIndexFile testFile = c1.getFailedToDeleteFiles().values().iterator().next();
    assertEquals(1, testFile.getDeleteAttemptCount());
    assertEquals(IOUtils.humanReadableByteCount(t1.length), c1.getGarbageSize());
    assertEquals(1, c1.getGarbageDetails().length);
    Directory w3 = c1.wrapForRead("/foo", defn, r2, INDEX_DATA_CHILD_NAME);
    w3.close();
    assertEquals(2, testFile.getDeleteAttemptCount());
    //Now let the file to be deleted
    testFiles.clear();
    Directory w4 = c1.wrapForRead("/foo", defn, r2, INDEX_DATA_CHILD_NAME);
    w4.close();
    //No pending deletes left
    assertEquals(0, c1.getFailedToDeleteFiles().size());
}
Also used : IOException(java.io.IOException) LocalIndexFile(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile) RAMDirectory(org.apache.lucene.store.RAMDirectory) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory) Test(org.junit.Test)

Aggregations

LocalIndexFile (org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile)4 IOException (java.io.IOException)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 HashSet (java.util.HashSet)1 Directory (org.apache.lucene.store.Directory)1 FilterDirectory (org.apache.lucene.store.FilterDirectory)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 Test (org.junit.Test)1