You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by GitBox <gi...@apache.org> on 2022/06/29 04:32:02 UTC
[GitHub] [incubator-pegasus] acelyc111 commented on a diff in pull request #1019: feat(java-client): Add hasNext() for PegasusScannerInterface
acelyc111 commented on code in PR #1019:
URL: https://github.com/apache/incubator-pegasus/pull/1019#discussion_r909186933
##########
java-client/src/main/java/org/apache/pegasus/client/PegasusScanner.java:
##########
@@ -88,9 +88,27 @@ public PegasusScanner(
_needCheckHash = needCheckHash;
_incomplete = false;
_fullScan = fullScan;
+ _nextItem = null;
+ }
+
+ public boolean hasNext() throws PException {
+ synchronized (_promisesLock) {
+ if (_nextItem != null) {
+ return true;
+ }
+ }
+ _nextItem = next();
Review Comment:
It's not thread safe in some cases since `_nextItem` will be overwritten.
```
time thread1 thread2
t1 hasNext hasNext
t2 _nextItem = a
t3 _nextItem = b
t4 next -> b
t5 next -> nullptr
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org