[
https://issues.apache.org/jira/browse/SOLR-8323?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15267426#comment-15267426
]
ASF GitHub Bot commented on SOLR-8323:
--------------------------------------
Github user dragonsinth commented on the pull request:
https://github.com/apache/lucene-solr/pull/32#issuecomment-216351404
BTW, here's an implementation of waitForState() that does the work on the
calling thread. This passes your tests:
```
public void waitForState(final String collection, long wait, TimeUnit
unit, CollectionStatePredicate predicate)
throws InterruptedException, TimeoutException {
long stop = System.nanoTime() + unit.toNanos(wait);
if (predicate.matches(this.liveNodes,
clusterState.getCollectionOrNull(collection))) {
return;
}
LinkedBlockingQueue<Pair<Set<String>, DocCollection>> queue = new
LinkedBlockingQueue<>();
CollectionStateWatcher watcher = new CollectionStateWatcher() {
@Override
public void onStateChanged(Set<String> liveNodes, DocCollection
collectionState) {
queue.add(new Pair<>(liveNodes, collectionState));
registerCollectionStateWatcher(collection, this);
}
};
registerCollectionStateWatcher(collection, watcher);
try {
while (true) {
Pair<Set<String>, DocCollection> pair = queue.poll(stop -
System.nanoTime(), TimeUnit.NANOSECONDS);
if (pair == null) {
throw new TimeoutException();
}
if (predicate.matches(pair.getKey(), pair.getValue())) {
return;
}
}
} finally {
removeCollectionStateWatcher(collection, watcher);
}
}
```
One thing I noticed in writing this is that it's uncertain whether you'll
miss any states or not. I kind of like the idea that you could have your
watcher return true or false to decide whether to keep watching, as it would
ensure we could get all updates without missing any.
> Add CollectionWatcher API to ZkStateReader
> ------------------------------------------
>
> Key: SOLR-8323
> URL: https://issues.apache.org/jira/browse/SOLR-8323
> Project: Solr
> Issue Type: Improvement
> Affects Versions: master
> Reporter: Alan Woodward
> Assignee: Alan Woodward
> Attachments: SOLR-8323.patch, SOLR-8323.patch, SOLR-8323.patch,
> SOLR-8323.patch
>
>
> An API to watch for changes to collection state would be a generally useful
> thing, both internally and for client use.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]