ifesdjeen commented on code in PR #225:
URL: https://github.com/apache/cassandra-accord/pull/225#discussion_r2216027280
##########
accord-core/src/main/java/accord/utils/PersistentField.java:
##########
@@ -92,36 +92,43 @@ public synchronized AsyncResult<?> mergeAndUpdate(@Nonnull
Input inputValue)
private AsyncResult<?> mergeAndUpdate(@Nullable Input inputValue, @Nonnull
BiFunction<Input, Saved, Saved> merge)
{
Invariants.nonNull(merge, "merge cannot be null");
- AsyncResult.Settable<Void> result = AsyncResults.settable();
Saved startingValue = latestPending;
if (startingValue == null)
{
Invariants.require(pending.isEmpty());
startingValue = currentValue.get();
}
Saved newValue = merge.apply(inputValue, startingValue);
- this.latestPending = newValue;
- int id = ++nextId;
- pending.add(new Pending<>(id, newValue));
- AsyncResult<?> pendingWrite = persister.persist(inputValue, newValue);
- pendingWrite.invoke((success, fail) -> {
- synchronized (this)
- {
- complete.add(id);
- boolean upd = false;
- Saved latest = null;
- while (!complete.isEmpty() && pending.peek().id ==
complete.first())
+ if (persister.shouldPersist(inputValue, newValue))
+ {
+ this.latestPending = newValue;
+ int id = ++nextId;
+ pending.add(new Pending<>(id, newValue));
+
+ AsyncResult.Settable<Void> result = AsyncResults.settable();
+ AsyncResult<?> pendingWrite = persister.persist(inputValue,
newValue);
+ pendingWrite.invoke((success, fail) -> {
+ synchronized (this)
{
- latest = pending.poll().saving;
- complete.pollFirst();
- upd = true;
+ complete.add(id);
+ boolean upd = false;
+ Saved latest = null;
+ while (!complete.isEmpty() && pending.peek().id ==
complete.first())
+ {
+ latest = pending.poll().saving;
+ complete.pollFirst();
+ upd = true;
+ }
+ if (upd) set.accept(latest);
}
- if (upd) set.accept(latest);
result.setSuccess(null);
Review Comment:
here, the "biggest" change is that we set success outside synchronized block
to avoid callbacks being called in it by accident
##########
accord-core/src/main/java/accord/utils/PersistentField.java:
##########
@@ -104,24 +103,31 @@ private AsyncResult<?> mergeAndUpdate(@Nullable Input
inputValue, @Nonnull BiFun
int id = ++nextId;
pending.add(new Pending<>(id, newValue));
- AsyncResult<?> pendingWrite = persister.persist(inputValue, newValue);
- pendingWrite.invoke((success, fail) -> {
- synchronized (this)
- {
- complete.add(id);
- boolean upd = false;
- Saved latest = null;
- while (!complete.isEmpty() && pending.peek().id ==
complete.first())
+ if (persister.shouldPersist(inputValue, newValue))
+ {
+ AsyncResult.Settable<Void> result = AsyncResults.settable();
+ AsyncResult<?> pendingWrite = persister.persist(inputValue,
newValue);
+ pendingWrite.invoke((success, fail) -> {
+ synchronized (this)
{
- latest = pending.poll().saving;
- complete.pollFirst();
- upd = true;
+ complete.add(id);
+ boolean upd = false;
+ Saved latest = null;
+ while (!complete.isEmpty() && pending.peek().id ==
complete.first())
+ {
+ latest = pending.poll().saving;
+ complete.pollFirst();
+ upd = true;
+ }
+ if (upd) set.accept(latest);
+ result.setSuccess(null);
Review Comment:
here, the "biggest" change is that we set success outside synchronized block
to avoid callbacks being called there by accident
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]