in src/main/java/com/googlesource/gerrit/plugins/validation/dfsrefdb/zookeeper/ZkSharedRefDatabase.java [119:148]
public boolean compareAndPut(Project.NameKey projectName, Ref oldRef, ObjectId newRefValue)
throws GlobalRefDbSystemError {
final DistributedAtomicValue distributedRefValue =
new DistributedAtomicValue(client, pathFor(projectName, oldRef.getName()), retryPolicy);
try {
if ((oldRef.getObjectId() == null || oldRef.getObjectId().equals(ObjectId.zeroId()))
&& refNotInZk(projectName, oldRef)) {
return distributedRefValue.initialize(writeObjectId(newRefValue));
}
final ObjectId newValue = newRefValue == null ? ObjectId.zeroId() : newRefValue;
final AtomicValue<byte[]> newDistributedValue =
distributedRefValue.compareAndSet(
writeObjectId(oldRef.getObjectId()), writeObjectId(newValue));
if (!newDistributedValue.succeeded() && refNotInZk(projectName, oldRef)) {
return distributedRefValue.initialize(writeObjectId(newRefValue));
}
return newDistributedValue.succeeded();
} catch (Exception e) {
logger.atWarning().withCause(e).log(
"Error trying to perform CAS at path %s", pathFor(projectName, oldRef.getName()));
throw new GlobalRefDbSystemError(
String.format(
"Error trying to perform CAS at path %s", pathFor(projectName, oldRef.getName())),
e);
}
}