DocumentNodeStore implements NodeStore, RevisionContext, Observable, Clusterable, NodeStateDiffer { boolean updateClusterState() { boolean hasChanged = false; Set<Integer> clusterIds = Sets.newHashSet(); for (ClusterNodeInfoDocument doc : ClusterNodeInfoDocument.all(nonLeaseCheckingStore)) { int cId = doc.getClusterId(); clusterIds.add(cId); ClusterNodeInfoDocument old = clusterNodes.get(cId); if (old != null && !old.isActive() && !doc.isActive()) { continue; } clusterNodes.put(cId, doc); if (old == null || old.isActive() != doc.isActive()) { hasChanged = true; } } hasChanged |= clusterNodes.keySet().retainAll(clusterIds); return hasChanged; } DocumentNodeStore(DocumentNodeStoreBuilder<?> builder); void dispose(); @NotNull DocumentStore getDocumentStore(); void setAsyncDelay(int delay); int getAsyncDelay(); void setMaxBackOffMillis(int time); int getMaxBackOffMillis(); int getChangeSetMaxItems(); void setChangeSetMaxItems(int changeSetMaxItems); int getChangeSetMaxDepth(); void setChangeSetMaxDepth(int changeSetMaxDepth); @NotNull ClusterNodeInfo getClusterInfo(); CacheStats getNodeCacheStats(); CacheStats getNodeChildrenCacheStats(); @NotNull Iterable<CacheStats> getDiffCacheStats(); Cache<PathRev, DocumentNodeState> getNodeCache(); Cache<NamePathRev, DocumentNodeState.Children> getNodeChildrenCache(); Predicate<Path> getNodeCachePredicate(); int getPendingWriteCount(); boolean isDisableBranches(); @NotNull PropertyState createPropertyState(String name, String value); @Nullable DocumentNodeState getNode(@NotNull final Path path,
                                     @NotNull final RevisionVector rev); BundlingConfigHandler getBundlingConfigHandler(); @Override boolean compare(@NotNull final AbstractDocumentNodeState node,
                           @NotNull final AbstractDocumentNodeState base,
                           @NotNull NodeStateDiff diff); @Override Closeable addObserver(Observer observer); @NotNull @Override DocumentNodeState getRoot(); @NotNull @Override NodeState merge(@NotNull NodeBuilder builder,
                           @NotNull CommitHook commitHook,
                           @NotNull CommitInfo info); @NotNull @Override NodeState rebase(@NotNull NodeBuilder builder); @Override NodeState reset(@NotNull NodeBuilder builder); @Override @NotNull BlobStoreBlob createBlob(InputStream inputStream); @Override Blob getBlob(@NotNull String reference); Blob getBlobFromBlobId(String blobId); @NotNull @Override String checkpoint(long lifetime, @NotNull Map<String, String> properties); @NotNull @Override String checkpoint(long lifetime); @NotNull @Override Map<String, String> checkpointInfo(@NotNull String checkpoint); @NotNull @Override Iterable<String> checkpoints(); @Nullable @Override NodeState retrieve(@NotNull String checkpoint); @Override boolean release(@NotNull String checkpoint); @Override UnmergedBranches getBranches(); @Override UnsavedModifications getPendingModifications(); @Override int getClusterId(); @Override @NotNull RevisionVector getHeadRevision(); @Override @NotNull Revision newRevision(); @Override @NotNull Clock getClock(); @Override String getCommitValue(@NotNull Revision changeRevision,
                                 @NotNull NodeDocument doc); void runBackgroundOperations(); @Nullable MarkSweepGarbageCollector createBlobGarbageCollector(long blobGcMaxAgeInSecs, String repositoryId,
        Whiteboard whiteboard, StatisticsProvider statisticsProvider); DocumentNodeStoreMBean getMBean(); BlobStore getBlobStore(); Iterator<ReferencedBlob> getReferencedBlobsIterator(); DiffCache getDiffCache(); Checkpoints getCheckpoints(); @NotNull VersionGarbageCollector getVersionGarbageCollector(); @NotNull JournalGarbageCollector getJournalGarbageCollector(); @NotNull LastRevRecoveryAgent getLastRevRecoveryAgent(); @Override String getInstanceId(); @Override String getVisibilityToken(); @Override boolean isVisible(@NotNull String visibilityToken, long maxWaitMillis); DocumentNodeStoreStatsCollector getStatsCollector(); DocumentNodeStateCache getNodeStateCache(); void setNodeStateCache(DocumentNodeStateCache nodeStateCache); JournalPropertyHandlerFactory getJournalPropertyHandlerFactory(); static final FormatVersion VERSION; static final List<String> META_PROP_NAMES; static final String SYS_PROP_DISABLE_JOURNAL; }
@Test public void updateClusterState() { DocumentStore docStore = new MemoryDocumentStore(); DocumentNodeStore ns1 = builderProvider.newBuilder().setAsyncDelay(0) .setClusterId(1).setDocumentStore(docStore) .getNodeStore(); int cId1 = ns1.getClusterId(); DocumentNodeStore ns2 = builderProvider.newBuilder().setAsyncDelay(0) .setClusterId(2).setDocumentStore(docStore) .getNodeStore(); int cId2 = ns2.getClusterId(); ns1.updateClusterState(); ns2.updateClusterState(); assertEquals(0, ns1.getMBean().getInactiveClusterNodes().length); assertEquals(0, ns2.getMBean().getInactiveClusterNodes().length); assertEquals(2, ns1.getMBean().getActiveClusterNodes().length); assertEquals(2, ns2.getMBean().getActiveClusterNodes().length); ns1.dispose(); ns2.updateClusterState(); String[] inactive = ns2.getMBean().getInactiveClusterNodes(); String[] active = ns2.getMBean().getActiveClusterNodes(); assertEquals(1, inactive.length); assertTrue(inactive[0].startsWith(cId1 + "=")); assertEquals(1, active.length); assertTrue(active[0].startsWith(cId2 + "=")); }