in transaction-client/src/main/java/org/apache/omid/tso/client/MockTSOClient.java [114:152]
public TSOFuture<Long> commit(long transactionId, Set<? extends CellId> cells) {
synchronized (conflictMap) {
SettableFuture<Long> f = SettableFuture.create();
if (transactionId < lwm.get()) {
f.setException(new AbortException());
return new ForwardingTSOFuture<>(f);
}
if (!hasConflictsWithFences(transactionId, cells) &&
!hasConflictsWithCommittedTransactions(transactionId, cells)) {
long commitTimestamp = timestampGenerator.incrementAndGet();
for (CellId c : cells) {
int index = Math.abs((int) (c.getCellId() % CONFLICT_MAP_SIZE));
long oldVal = conflictMap[index];
conflictMap[index] = commitTimestamp;
long curLwm = lwm.get();
while (oldVal > curLwm) {
if (lwm.compareAndSet(curLwm, oldVal)) {
break;
}
curLwm = lwm.get();
}
}
f.set(commitTimestamp);
try {
commitTable.addCommittedTransaction(transactionId, commitTimestamp);
commitTable.updateLowWatermark(lwm.get());
commitTable.flush();
} catch (IOException ioe) {
f.setException(ioe);
}
} else {
f.setException(new AbortException());
}
return new ForwardingTSOFuture<>(f);
}
}