private void updateClusterState(boolean onlyLiveNodes) throws KeeperException, InterruptedException { // build immutable CloudInfo synchronized (getUpdateLock()) { List<String> liveNodes = zkClient.getChildren(LIVE_NODES_ZKNODE, null, true); Set<String> liveNodesSet = new HashSet<>(liveNodes); if (!onlyLiveNodes) { log.debug("Updating cloud state from ZooKeeper... "); clusterState = constructState(liveNodesSet, null); } else { log.debug("Updating live nodes from ZooKeeper... ({})", liveNodesSet.size()); clusterState = this.clusterState; clusterState.setLiveNodes(liveNodesSet); } } }
private void refreshAliases(AliasesManager watcher) throws KeeperException, InterruptedException { synchronized (getUpdateLock()) { constructState(Collections.emptySet()); zkClient.exists(ALIASES, watcher, true); } aliasesManager.update(); }
/** * Remove a watcher from a collection's watch list. * * This allows Zookeeper watches to be removed if there is no interest in the * collection. * * @param collection the collection * @param watcher the watcher */ public void removeCollectionStateWatcher(String collection, CollectionStateWatcher watcher) { AtomicBoolean reconstructState = new AtomicBoolean(false); collectionWatches.compute(collection, (k, v) -> { if (v == null) return null; v.stateWatchers.remove(watcher); if (v.canBeRemoved()) { watchedCollectionStates.remove(collection); lazyCollectionStates.put(collection, new LazyCollectionRef(collection)); reconstructState.set(true); return null; } return v; }); if (reconstructState.get()) { synchronized (getUpdateLock()) { constructState(Collections.emptySet()); } } }
if (reconstructState.get()) { synchronized (getUpdateLock()) { constructState(Collections.emptySet());
constructState(Collections.singleton(collection)); DocCollection newState = fetchCollectionState(collection, null); if (updateWatchedCollection(collection, newState)) { constructState(Collections.singleton(collection));
constructState(updatedCollections); this.legacyCollectionStates = emptyMap(); this.legacyClusterStateVersion = 0; constructState(Collections.emptySet());
/** * Forcibly refresh cluster state from ZK. Do this only to avoid race conditions because it's expensive. * * It is cheaper to call {@link #forceUpdateCollection(String)} on a single collection if you must. * * @lucene.internal */ public void forciblyRefreshAllClusterStateSlow() throws KeeperException, InterruptedException { synchronized (getUpdateLock()) { if (clusterState == null) { // Never initialized, just run normal initialization. createClusterStateWatchersAndUpdate(); return; } // No need to set watchers because we should already have watchers registered for everything. refreshCollectionList(null); refreshLiveNodes(null); refreshLegacyClusterState(null); // Need a copy so we don't delete from what we're iterating over. Collection<String> safeCopy = new ArrayList<>(watchedCollectionStates.keySet()); Set<String> updatedCollections = new HashSet<>(); for (String coll : safeCopy) { DocCollection newState = fetchCollectionState(coll, null); if (updateWatchedCollection(coll, newState)) { updatedCollections.add(coll); } } constructState(updatedCollections); } }
public Integer compareStateVersions(String coll, int version) { DocCollection collection = clusterState.getCollectionOrNull(coll); if (collection == null) return null; if (collection.getZNodeVersion() < version) { log.debug("Server older than client {}<{}", collection.getZNodeVersion(), version); DocCollection nu = getCollectionLive(this, coll); if (nu == null) return -1 ; if (nu.getZNodeVersion() > collection.getZNodeVersion()) { if (updateWatchedCollection(coll, nu)) { synchronized (getUpdateLock()) { constructState(Collections.singleton(coll)); } } collection = nu; } } if (collection.getZNodeVersion() == version) { return null; } log.debug("Wrong version from client [{}]!=[{}]", version, collection.getZNodeVersion()); return collection.getZNodeVersion(); }
this.clusterState = constructState(liveNodeSet, null);