in src/main/java/com/googlesource/gerrit/plugins/validation/dfsrefdb/zookeeper/ZkSharedRefDatabase.java [151:174]
public <T> boolean compareAndPut(
Project.NameKey project, String refName, T expectedValue, T newValue)
throws GlobalRefDbSystemError {
final DistributedAtomicValue distributedRefValue =
new DistributedAtomicValue(client, pathFor(project, refName), retryPolicy);
try {
if (expectedValue == null && refNotInZk(project, refName)) {
return distributedRefValue.initialize(writeGeneric(newValue));
}
final AtomicValue<byte[]> newDistributedValue =
distributedRefValue.compareAndSet(writeGeneric(expectedValue), writeGeneric(newValue));
return newDistributedValue.succeeded();
} catch (Exception e) {
String message =
String.format(
"Error trying to perform CAS of generic value at path %s", pathFor(project, refName));
logger.atWarning().withCause(e).log(message);
throw new GlobalRefDbSystemError(message, e);
}
}