Skip to content

Commit

Permalink
OAK-10921 : extracted out common code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh Kumar committed Jul 4, 2024
1 parent 34554df commit 9f6680c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ public void cancelMustNotUpdateLastOldestTimeStamp() throws Exception {
// ensure a canceled GC doesn't update that versionGC SETTINGS entry
Document statusAfter = store.find(Collection.SETTINGS, "versionGC");
if (statusBefore == null) {
// fullGC values had been added, so it won't be null
assertNotNull(statusAfter);
assertNull(statusAfter.get(lastOldestTimeStampProp));
assertNull(statusAfter);
} else {
assertNotNull(statusAfter);
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,78 +1480,19 @@ private Iterator<NodeDocument> candidates(long fromModified, long toModified, in
// OAK-10921
@Test
public void resetGCFromOakRunWhileRunning() throws Exception {

// if we reset fullGC from any external source while GC is running,
// it should not update the fullGC variables.

//1. Create nodes with properties
NodeBuilder b1 = store1.getRoot().builder();

// Add property to node & save
for (int i = 0; i < 5; i++) {
b1.child("z"+i).setProperty("prop", "foo", STRING);
}
store1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
store1.runBackgroundOperations();

// enable the full gc flag
writeField(gc, "fullGCEnabled", true, true);
long maxAge = 1; //hours
long delta = MINUTES.toMillis(10);
//1. Go past GC age and check no GC done as nothing deleted
clock.waitUntil(getCurrentTimestamp() + maxAge);
VersionGCStats stats = gc(gc, maxAge, HOURS);
assertStatsCountsZero(stats);

//Remove property
NodeBuilder b2 = store1.getRoot().builder();
for (int i = 0; i < 5; i++) {
b2.getChildNode("z"+i).removeProperty("prop");
}
store1.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
store1.runBackgroundOperations();

final AtomicReference<VersionGarbageCollector> gcRef = Atomics.newReference();
final VersionGCSupport gcSupport = new VersionGCSupport(store1.getDocumentStore()) {

@Override
public Iterable<NodeDocument> getModifiedDocs(long fromModified, long toModified, int limit, @NotNull String fromId,
final @NotNull Set<String> includePaths, final @NotNull Set<String> excludePaths) {
// reset fullGC variables externally while GC is running
gcRef.get().reset();
return super.getModifiedDocs(fromModified, toModified, limit, fromId, includePaths, excludePaths);
}
};

gcRef.set(new VersionGarbageCollector(store1, gcSupport, true, false, false, 3));

//3. Check that deleted property does get collected post maxAge
clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge*2) + delta);

Document document = store1.getDocumentStore().find(SETTINGS, SETTINGS_COLLECTION_ID);
assert document != null;
assertNotNull(document.get(SETTINGS_COLLECTION_FULL_GC_TIMESTAMP_PROP));
assertNotNull(document.get(SETTINGS_COLLECTION_FULL_GC_DOCUMENT_ID_PROP));

stats = gcRef.get().gc(maxAge*2, HOURS);

document = store1.getDocumentStore().find(SETTINGS, SETTINGS_COLLECTION_ID);
assertEquals(5, stats.updatedFullGCDocsCount);
assertEquals(5, stats.deletedPropsCount);
assertEquals(MIN_ID_VALUE, stats.oldestModifiedDocId);

// 4. verify that fullGC variables are not updated after resetting them
assert document != null;
assertNull(document.get(SETTINGS_COLLECTION_FULL_GC_TIMESTAMP_PROP));
assertNull(document.get(SETTINGS_COLLECTION_FULL_GC_DOCUMENT_ID_PROP));
resetFullGCExternally(false);
}

@Test
public void resetFullGCFromOakRunWhileRunning() throws Exception {

// if we reset fullGC from any external source while GC is running,
// it should not update the fullGC variables.
resetFullGCExternally(true);
}

private void resetFullGCExternally(final boolean resetFullGCOnly) throws Exception {
//1. Create nodes with properties
NodeBuilder b1 = store1.getRoot().builder();

Expand Down Expand Up @@ -1580,14 +1521,17 @@ public void resetFullGCFromOakRunWhileRunning() throws Exception {
store1.runBackgroundOperations();

final AtomicReference<VersionGarbageCollector> gcRef = Atomics.newReference();

final VersionGCSupport gcSupport = new VersionGCSupport(store1.getDocumentStore()) {

@Override
public Iterable<NodeDocument> getModifiedDocs(long fromModified, long toModified, int limit, @NotNull String fromId,
final @NotNull Set<String> includePaths, final @NotNull Set<String> excludePaths) {
// reset fullGC variables externally while GC is running
gcRef.get().resetFullGC();
if (resetFullGCOnly) {
gcRef.get().resetFullGC();
} else {
gcRef.get().reset();
}
return super.getModifiedDocs(fromModified, toModified, limit, fromId, includePaths, excludePaths);
}
};
Expand Down

0 comments on commit 9f6680c

Please sign in to comment.