Author: frm Date: Wed Oct 12 14:38:22 2016 New Revision: 1764475 URL: http://svn.apache.org/viewvc?rev=1764475&view=rev Log: OAK-4883 - Register a BlobGCMBean on standby instances
Contribution by Timothee Maret. Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStore.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStore.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStore.java?rev=1764475&r1=1764474&r2=1764475&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStore.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStore.java Wed Oct 12 14:38:22 2016 @@ -72,6 +72,15 @@ import org.slf4j.LoggerFactory; */ public class SegmentNodeStore implements NodeStore, Observable { + private static final Closeable NOOP = new Closeable() { + + @Override + public void close() throws IOException { + // This method was intentionally left blank. + } + + }; + public static class SegmentNodeStoreBuilder { private static final Logger LOG = LoggerFactory.getLogger(SegmentNodeStoreBuilder.class); @@ -89,6 +98,8 @@ public class SegmentNodeStore implements private boolean isCreated; + private boolean dispatchChanges = true; + private SegmentNodeStoreBuilder( @Nonnull Revisions revisions, @Nonnull SegmentReader reader, @@ -101,6 +112,12 @@ public class SegmentNodeStore implements } @Nonnull + public SegmentNodeStoreBuilder dispatchChanges(boolean dispatchChanges) { + this.dispatchChanges = dispatchChanges; + return this; + } + + @Nonnull public SegmentNodeStore build() { checkState(!isCreated); isCreated = true; @@ -188,7 +205,11 @@ public class SegmentNodeStore implements this.writer = builder.writer; this.blobStore = builder.blobStore; this.head = new AtomicReference<SegmentNodeState>(reader.readHeadState(revisions)); - this.changeDispatcher = new ChangeDispatcher(getRoot()); + if (builder.dispatchChanges) { + this.changeDispatcher = new ChangeDispatcher(getRoot()); + } else { + this.changeDispatcher = null; + } } void setMaximumBackoff(long max) { @@ -228,13 +249,16 @@ public class SegmentNodeStore implements SegmentNodeState state = reader.readHeadState(revisions); if (!state.getRecordId().equals(head.get().getRecordId())) { head.set(state); - changeDispatcher.contentChanged(state.getChildNode(ROOT), null); + contentChanged(state.getChildNode(ROOT), null); } } @Override public Closeable addObserver(Observer observer) { - return changeDispatcher.addObserver(observer); + if (changeDispatcher != null) { + return changeDispatcher.addObserver(observer); + } + return NOOP; } @Override @Nonnull @@ -509,7 +533,7 @@ public class SegmentNodeStore implements refreshHead(); if (revisions.setHead(before.getRecordId(), after.getRecordId())) { head.set(after); - changeDispatcher.contentChanged(after.getChildNode(ROOT), info); + contentChanged(after.getChildNode(ROOT), info); refreshHead(); return true; } else { @@ -626,4 +650,10 @@ public class SegmentNodeStore implements this.checkpointsLockWaitTime = checkpointsLockWaitTime; } + private void contentChanged(NodeState root, CommitInfo info) { + if (changeDispatcher != null) { + changeDispatcher.contentChanged(root, info); + } + } + } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java?rev=1764475&r1=1764474&r2=1764475&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java Wed Oct 12 14:38:22 2016 @@ -335,18 +335,16 @@ public class SegmentNodeStoreService ext } private synchronized void registerNodeStore() throws IOException { - if (registerSegmentStore()) { - if (toBoolean(property(STANDBY), false)) { - return; - } - - if (registerSegmentNodeStore()) { - Dictionary<String, Object> props = new Hashtable<String, Object>(); - props.put(Constants.SERVICE_PID, SegmentNodeStore.class.getName()); - props.put("oak.nodestore.description", new String[]{"nodeStoreType=segment"}); - storeRegistration = context.getBundleContext().registerService(NodeStore.class.getName(), this, props); - } + if (!registerSegmentStore()) { + return; } + if (toBoolean(property(STANDBY), false)) { + return; + } + Dictionary<String, Object> props = new Hashtable<String, Object>(); + props.put(Constants.SERVICE_PID, SegmentNodeStore.class.getName()); + props.put("oak.nodestore.description", new String[] {"nodeStoreType=segment"}); + storeRegistration = context.getBundleContext().registerService(NodeStore.class.getName(), this, props); } private boolean registerSegmentStore() throws IOException { @@ -483,34 +481,19 @@ public class SegmentNodeStoreService ext "FileStore statistics" )); - // Register a factory service to expose the FileStore - - providerRegistration = context.getBundleContext().registerService(SegmentStoreProvider.class.getName(), this, null); - - return true; - } - - private SegmentGCOptions newGCOptions() { - boolean pauseCompaction = toBoolean(property(PAUSE_COMPACTION), PAUSE_DEFAULT); - int retryCount = toInteger(property(COMPACTION_RETRY_COUNT), RETRY_COUNT_DEFAULT); - int forceTimeout = toInteger(property(COMPACTION_FORCE_TIMEOUT), FORCE_TIMEOUT_DEFAULT); - - byte gainThreshold = getGainThreshold(); - long sizeDeltaEstimation = toLong(property(COMPACTION_SIZE_DELTA_ESTIMATION), SIZE_DELTA_ESTIMATION_DEFAULT); - - return new SegmentGCOptions(pauseCompaction, gainThreshold, retryCount, forceTimeout) - .setGcSizeDeltaEstimation(sizeDeltaEstimation); - } + // register segment node store - private boolean registerSegmentNodeStore() throws IOException { Dictionary<?, ?> properties = context.getProperties(); name = String.valueOf(properties.get(NAME)); final long blobGcMaxAgeInSecs = toLong(property(PROP_BLOB_GC_MAX_AGE), DEFAULT_BLOB_GC_MAX_AGE); - OsgiWhiteboard whiteboard = new OsgiWhiteboard(context.getBundleContext()); - - segmentNodeStore = SegmentNodeStoreBuilders.builder(store).build(); + SegmentNodeStore.SegmentNodeStoreBuilder segmentNodeStoreBuilder = + SegmentNodeStoreBuilders.builder(store); + if (toBoolean(property(STANDBY), false)) { + segmentNodeStoreBuilder.dispatchChanges(false); + } + segmentNodeStore = segmentNodeStoreBuilder.build(); observerTracker = new ObserverTracker(segmentNodeStore); observerTracker.start(context.getBundleContext()); @@ -550,7 +533,7 @@ public class SegmentNodeStoreService ext if (blobStore instanceof BlobTrackingStore) { final long trackSnapshotInterval = toLong(property(PROP_BLOB_SNAPSHOT_INTERVAL), - DEFAULT_BLOB_SNAPSHOT_INTERVAL); + DEFAULT_BLOB_SNAPSHOT_INTERVAL); String root = property(DIRECTORY); if (Strings.isNullOrEmpty(root)) { root = "repository"; @@ -561,8 +544,8 @@ public class SegmentNodeStoreService ext trackingStore.getTracker().close(); } ((BlobTrackingStore) blobStore).addTracker( - new BlobIdTracker(root, repoId, trackSnapshotInterval, (SharedDataStore) - blobStore)); + new BlobIdTracker(root, repoId, trackSnapshotInterval, (SharedDataStore) + blobStore)); } } @@ -585,9 +568,26 @@ public class SegmentNodeStoreService ext } log.info("SegmentNodeStore initialized"); + + // Register a factory service to expose the FileStore + + providerRegistration = context.getBundleContext().registerService(SegmentStoreProvider.class.getName(), this, null); + return true; } + private SegmentGCOptions newGCOptions() { + boolean pauseCompaction = toBoolean(property(PAUSE_COMPACTION), PAUSE_DEFAULT); + int retryCount = toInteger(property(COMPACTION_RETRY_COUNT), RETRY_COUNT_DEFAULT); + int forceTimeout = toInteger(property(COMPACTION_FORCE_TIMEOUT), FORCE_TIMEOUT_DEFAULT); + + byte gainThreshold = getGainThreshold(); + long sizeDeltaEstimation = toLong(property(COMPACTION_SIZE_DELTA_ESTIMATION), SIZE_DELTA_ESTIMATION_DEFAULT); + + return new SegmentGCOptions(pauseCompaction, gainThreshold, retryCount, forceTimeout) + .setGcSizeDeltaEstimation(sizeDeltaEstimation); + } + private void unregisterNodeStore() { new CompositeRegistration(registrations).unregister(); if (providerRegistration != null) {