use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector in project jackrabbit-oak by apache.
the class RevisionsCommand method bootstrapVGC.
private VersionGarbageCollector bootstrapVGC(RevisionsOptions options, Closer closer) throws IOException {
DocumentMK.Builder builder = createDocumentMKBuilder(options, closer);
if (builder == null) {
System.err.println("revisions mode only available for DocumentNodeStore");
System.exit(1);
}
// create a VersionGCSupport while builder is read-write
VersionGCSupport gcSupport = createVersionGCSupport(builder);
// check for matching format version
FormatVersion version = versionOf(gcSupport.getDocumentStore());
if (!DocumentNodeStore.VERSION.equals(version)) {
System.err.println("Incompatible versions. This oak-run is " + DocumentNodeStore.VERSION + ", while the store is " + version);
System.exit(1);
}
// set it read-only before the DocumentNodeStore is created
// this prevents the DocumentNodeStore from writing a new
// clusterId to the clusterNodes and nodes collections
builder.setReadOnlyMode();
// create a version GC that operates on a read-only DocumentNodeStore
// and a GC support with a writable DocumentStore
VersionGarbageCollector gc = createVersionGC(builder.getNodeStore(), gcSupport);
VersionGCOptions gcOptions = gc.getOptions();
gcOptions = gcOptions.withDelayFactor(options.getDelay());
if (options.runOnce()) {
gcOptions = gcOptions.withMaxIterations(1);
}
if (options.getLimit() >= 0) {
gcOptions = gcOptions.withCollectLimit(options.getLimit());
}
gc.setOptions(gcOptions);
return gc;
}
use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector in project jackrabbit-oak by apache.
the class RevisionsCommand method reset.
private void reset(RevisionsOptions options, Closer closer) throws IOException {
VersionGarbageCollector gc = bootstrapVGC(options, closer);
System.out.println("resetting recommendations and statistics");
gc.reset();
}
use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector in project jackrabbit-oak by apache.
the class RevisionsCommand method collect.
private void collect(final RevisionsOptions options, Closer closer) throws IOException {
VersionGarbageCollector gc = bootstrapVGC(options, closer);
ExecutorService executor = Executors.newSingleThreadExecutor();
final Semaphore finished = new Semaphore(0);
try {
if (options.isContinuous()) {
// collect until shutdown hook is called
final AtomicBoolean running = new AtomicBoolean(true);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Detected QUIT signal.");
System.out.println("Stopping Revision GC...");
running.set(false);
finished.acquireUninterruptibly();
System.out.println("Stopped Revision GC.");
}
}));
while (running.get()) {
long lastRun = System.currentTimeMillis();
collectOnce(gc, options, executor);
waitWhile(running, lastRun + 5000);
}
} else {
collectOnce(gc, options, executor);
}
} finally {
finished.release();
executor.shutdownNow();
}
}
use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector in project jackrabbit-oak by apache.
the class DataStoreTrackerGCTest method init.
public DataStoreState init(DocumentNodeStore s, int idStart) throws Exception {
NodeBuilder a = s.getRoot().builder();
int number = 10;
int maxDeleted = 5;
// track the number of the assets to be deleted
List<Integer> processed = Lists.newArrayList();
Random rand = new Random(47);
for (int i = idStart; i < idStart + maxDeleted; i++) {
int n = rand.nextInt(number);
if (!processed.contains(idStart + n)) {
processed.add(idStart + n);
}
}
DataStoreState state = new DataStoreState();
for (int i = idStart; i < idStart + number; i++) {
Blob b = s.createBlob(randomStream(i, 16516));
Iterator<String> idIter = ((GarbageCollectableBlobStore) s.getBlobStore()).resolveChunks(b.toString());
while (idIter.hasNext()) {
String chunk = idIter.next();
state.blobsAdded.add(chunk);
if (!processed.contains(i)) {
state.blobsPresent.add(chunk);
}
}
a.child("c" + i).setProperty("x", b);
// Add a duplicated entry
if (i == idStart) {
a.child("cdup").setProperty("x", b);
}
}
s.merge(a, INSTANCE, EMPTY);
a = s.getRoot().builder();
for (int id : processed) {
a.child("c" + id).remove();
s.merge(a, INSTANCE, EMPTY);
}
// minutes
long maxAge = 10;
// 1. Go past GC age and check no GC done as nothing deleted
clock.waitUntil(clock.getTime() + MINUTES.toMillis(maxAge));
VersionGarbageCollector vGC = s.getVersionGarbageCollector();
VersionGarbageCollector.VersionGCStats stats = vGC.gc(0, MILLISECONDS);
return state;
}
use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector in project jackrabbit-oak by apache.
the class DataStoreTrackerGCTest method addNodeSpecialChars.
private HashSet<String> addNodeSpecialChars(DocumentNodeStore ds) throws Exception {
List<String> specialCharSets = Lists.newArrayList("q\\%22afdg\\%22", "a\nbcd", "a\n\rabcd", "012\\efg");
HashSet<String> set = new HashSet<String>();
NodeBuilder a = ds.getRoot().builder();
int toBeDeleted = 0;
for (int i = 0; i < specialCharSets.size(); i++) {
Blob b = ds.createBlob(randomStream(i, 18432));
NodeBuilder n = a.child("cspecial" + i);
n.child(specialCharSets.get(i)).setProperty("x", b);
Iterator<String> idIter = ((GarbageCollectableBlobStore) ds.getBlobStore()).resolveChunks(b.toString());
List<String> ids = Lists.newArrayList(idIter);
if (toBeDeleted != i) {
set.addAll(ids);
}
}
ds.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// Delete one node again
a = ds.getRoot().builder();
a.child("cspecial" + 0).remove();
ds.merge(a, INSTANCE, EMPTY);
// minutes
long maxAge = 10;
// 1. Go past GC age and check no GC done as nothing deleted
clock.waitUntil(clock.getTime() + MINUTES.toMillis(maxAge));
VersionGarbageCollector vGC = ds.getVersionGarbageCollector();
VersionGarbageCollector.VersionGCStats stats = vGC.gc(0, MILLISECONDS);
return set;
}
Aggregations