tisonkun commented on code in PR #2064:
URL: https://github.com/apache/zookeeper/pull/2064#discussion_r1330458351
##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java:
##########
@@ -735,10 +735,18 @@ private String getParentPathAndValidate(String path)
throws BadArgumentsExceptio
}
private static int checkAndIncVersion(int currentVersion, int
expectedVersion, String path) throws KeeperException.BadVersionException {
- if (expectedVersion != -1 && expectedVersion != currentVersion) {
- throw new KeeperException.BadVersionException(path);
+ if (expectedVersion != -1) {
+ if (expectedVersion != currentVersion) {
+ throw new KeeperException.BadVersionException(path);
+ }
+ if (expectedVersion == -2) {
+ return 0;
+ } else {
+ return currentVersion + 1;
+ }
+ } else {
+ return currentVersion + 1;
Review Comment:
@kezhuw Perhaps we can directly align the proposed `checkAndIncVersion`?
I'd suggest:
```java
private static int checkAndIncVersion(int currentVersion, int
expectedVersion, String path) throws KeeperException.BadVersionException {
if (expectedVersion != -1 && expectedVersion != currentVersion) {
throw new KeeperException.BadVersionException(path);
}
// Skip increase the data version to -1 by jumping from -2 to 0.
Otherwise, the client will
// receive a new data version -1. Now if the client wants to check
the data version, it can
// only pass -1 as the next expected version, but -1 as the expected
version means do not
// check the data version. So the client is unable to express the
expected manner.
return currentVersion != -2 ? currentVersion + 1 : 0;
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]