Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11248 : reapply changes of #1845 (which got reverted in #1853) #1864

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
Expand Down Expand Up @@ -668,29 +669,8 @@ protected void deactivate() {
journalPropertyHandlerFactory.stop();
}

if (prefetchFeature != null) {
prefetchFeature.close();
}

if (docStoreThrottlingFeature != null) {
docStoreThrottlingFeature.close();
}

if (cancelInvalidationFeature != null) {
cancelInvalidationFeature.close();
}

if (docStoreFullGCFeature != null) {
docStoreFullGCFeature.close();
}

if (docStoreEmbeddedVerificationFeature != null) {
docStoreEmbeddedVerificationFeature.close();
}

if (prevNoPropCacheFeature != null) {
prevNoPropCacheFeature.close();
}
closeFeatures(prefetchFeature, docStoreThrottlingFeature, cancelInvalidationFeature, docStoreFullGCFeature,
docStoreEmbeddedVerificationFeature, prevNoPropCacheFeature);

unregisterNodeStore();
}
Expand Down Expand Up @@ -796,6 +776,19 @@ protected void unbindNodeStateCache(DocumentNodeStateCache nodeStateCache) {
}
}

/**
* Closes the given varargs of features.
* <p>
* This method iterates over the provided varargs of features and closes each one
* that is not null.
* </p>
*
* @param features a varargs of {@link Feature} objects to be closed.
*/
private void closeFeatures(@NotNull final Feature... features) {
Arrays.stream(features).filter(Objects::nonNull).forEach(Feature::close);
}

private void unregisterNodeStore() {
deactivationTimestamp = System.currentTimeMillis();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.jackrabbit.guava.common.collect.Maps;
import com.mongodb.MongoClient;

Expand All @@ -32,6 +34,7 @@
import org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyService;
import org.apache.jackrabbit.oak.plugins.document.spi.lease.LeaseFailureHandler;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.spi.toggle.Feature;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
import org.apache.sling.testing.mock.osgi.MockOsgi;
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
Expand All @@ -46,6 +49,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -357,6 +361,19 @@ public void recoveryDelayMillisMinute() {
doRecoveryDelayMillis(60000);
}

@Test
public void closeFeatures() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
Feature feature1 = mock(Feature.class);
Feature feature2 = mock(Feature.class);
Feature feature3 = mock(Feature.class);
Feature feature4 = mock(Feature.class);

// successful invocation would return null
assertNull(MethodUtils.invokeMethod(service, true, "closeFeatures",
new Object[]{feature1, feature2, null, feature3, feature4},
new Class[]{Feature[].class}));
}

private void doRecoveryDelayMillis(long recoveryDelayMillis) {
Map<String, Object> config = newConfig(repoHome);
config.put("recoveryDelayMillis", recoveryDelayMillis);
Expand Down
Loading