From 0c80fd9311430702dd629154000c284afa4e5a07 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Thu, 4 Jul 2024 22:45:40 +0530 Subject: [PATCH] OAK-10921 : extracted out common code --- .../oak/plugins/document/VersionGCTest.java | 3 +- .../document/VersionGarbageCollectorIT.java | 74 +++---------------- 2 files changed, 10 insertions(+), 67 deletions(-) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java index ecc7ac0fd8d..f0184c7921c 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java @@ -190,8 +190,7 @@ public void cancelMustNotUpdateLastOldestTimeStamp() throws Exception { 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( diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java index e44f49ccab0..e2696fd0fcb 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java @@ -1480,78 +1480,19 @@ private Iterator 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 gcRef = Atomics.newReference(); - final VersionGCSupport gcSupport = new VersionGCSupport(store1.getDocumentStore()) { - - @Override - public Iterable getModifiedDocs(long fromModified, long toModified, int limit, @NotNull String fromId, - final @NotNull Set includePaths, final @NotNull Set 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(); @@ -1580,14 +1521,17 @@ public void resetFullGCFromOakRunWhileRunning() throws Exception { store1.runBackgroundOperations(); final AtomicReference gcRef = Atomics.newReference(); - final VersionGCSupport gcSupport = new VersionGCSupport(store1.getDocumentStore()) { @Override public Iterable getModifiedDocs(long fromModified, long toModified, int limit, @NotNull String fromId, final @NotNull Set includePaths, final @NotNull Set 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); } };