use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.
the class SegmentFactory method hasExternalBlobReferences.
@Override
public boolean hasExternalBlobReferences() throws IOException {
Builder builder = FileStore.builder(new File(dir, "segmentstore"));
builder.withMaxFileSize(256);
builder.withMemoryMapping(false);
FileStore fs;
try {
fs = builder.buildReadOnly();
} catch (InvalidFileStoreVersionException e) {
throw new IOException(e);
}
try {
fs.getTracker().collectBlobReferences(new ReferenceCollector() {
@Override
public void addReference(String reference, @Nullable String nodeId) {
// see java.nio.file.FileVisitor
throw new ExternalBlobFound();
}
});
return false;
} catch (ExternalBlobFound e) {
return true;
} finally {
fs.close();
}
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.
the class DataStoreCheckCommand method retrieveBlobReferences.
private static void retrieveBlobReferences(GarbageCollectableBlobStore blobStore, BlobReferenceRetriever marker, File marked) throws IOException {
final BufferedWriter writer = Files.newWriter(marked, Charsets.UTF_8);
final AtomicInteger count = new AtomicInteger();
boolean threw = true;
try {
final Joiner delimJoiner = Joiner.on(DELIM).skipNulls();
final GarbageCollectableBlobStore finalBlobStore = blobStore;
System.out.println("Starting dump of blob references");
Stopwatch watch = createStarted();
marker.collectReferences(new ReferenceCollector() {
@Override
public void addReference(String blobId, String nodeId) {
try {
Iterator<String> idIter = finalBlobStore.resolveChunks(blobId);
while (idIter.hasNext()) {
String id = delimJoiner.join(idIter.next(), nodeId);
count.getAndIncrement();
writeAsLine(writer, id, true);
}
} catch (Exception e) {
throw new RuntimeException("Error in retrieving references", e);
}
}
});
writer.flush();
sort(marked, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]);
}
});
System.out.println(count.get() + " blob references found");
System.out.println("Finished in " + watch.elapsed(TimeUnit.SECONDS) + " seconds");
threw = false;
} finally {
close(writer, threw);
}
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.
the class ExternalBlobIT method testNullBlobId.
@Test
public void testNullBlobId() throws Exception {
FileDataStore fds = createFileDataStore();
DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
nodeStore = getNodeStore(dbs);
NodeBuilder nb = nodeStore.getRoot().builder();
NodeBuilder cb = nb.child("hello");
cb.setProperty("blob1", createBlob(Segment.MEDIUM_LIMIT - 1));
int noOfBlobs = 4000;
for (int i = 0; i < noOfBlobs; i++) {
cb.setProperty("blob" + i, createBlob(Segment.MEDIUM_LIMIT + 1));
}
cb.setProperty("anotherBlob2", createBlob(Segment.MEDIUM_LIMIT + 1));
cb.setProperty("anotherBlob3", createBlob(Segment.MEDIUM_LIMIT + 1));
nodeStore.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
final List<String> refrences = Lists.newArrayList();
store.collectBlobReferences(new ReferenceCollector() {
@Override
public void addReference(String reference, String nodeId) {
assertNotNull(reference);
refrences.add(reference);
}
});
assertEquals(noOfBlobs + 2, refrences.size());
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.
the class CompactionAndCleanupIT method randomAccessFileConcurrentReadAndLength.
@Test
public void randomAccessFileConcurrentReadAndLength() throws Exception {
final FileStore fileStore = fileStoreBuilder(getFileStoreFolder()).withGCOptions(defaultGCOptions().setRetainedGenerations(2)).withMaxFileSize(1).withMemoryMapping(false).build();
final SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
ExecutorService executorService = newFixedThreadPool(300);
final AtomicInteger counter = new AtomicInteger();
final ReferenceCollector dummyCollector = new ReferenceCollector() {
@Override
public void addReference(String reference, String nodeId) {
// do nothing
}
};
try {
Callable<Void> concurrentWriteTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
NodeBuilder builder = nodeStore.getRoot().builder();
builder.setProperty("blob-" + counter.getAndIncrement(), createBlob(nodeStore, 25 * 25));
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
fileStore.flush();
return null;
}
};
Callable<Void> concurrentCleanupTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
fileStore.cleanup();
return null;
}
};
Callable<Void> concurrentReferenceCollector = new Callable<Void>() {
@Override
public Void call() throws Exception {
fileStore.collectBlobReferences(dummyCollector);
return null;
}
};
List<Future<?>> results = newArrayList();
for (int i = 0; i < 100; i++) {
results.add(executorService.submit(concurrentWriteTask));
results.add(executorService.submit(concurrentCleanupTask));
results.add(executorService.submit(concurrentReferenceCollector));
}
for (Future<?> result : results) {
assertNull(result.get());
}
} finally {
new ExecutorCloser(executorService).close();
fileStore.close();
}
}
Aggregations