Skip to content

Commit

Permalink
2.1.13: Reduce Sync on rollback if not required
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWiemer committed Oct 7, 2024
1 parent 9f24d08 commit a8b7abb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
############################
# JACIS VERSION:
############################
version=2.1.12
version=2.1.13
#=format for release: 2.1.25
#=format for snapshot: 2.0.26-2023-01-01 (on the way to 2.0.26)
#
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/org/jacis/container/JacisContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,34 @@ protected boolean hasStoreWithPendingDirtyCheck() {
return false;
}

protected boolean hasAnyTransactionListenersNeedingSynchronousExecution() {
protected boolean hasAnyTransactionListenersNeedingSynchronousExecutionForPrepare() {
for (JacisTransactionListener txListener : txListeners) {
if (txListener.isSynchronizedExcecutionRequired()) {
if (txListener.isSynchronizedExcecutionRequiredForPrepare()) {
return true;
}
}
return false;
}

protected boolean hasAnyTransactionListenersNeedingSynchronousExecutionForCommit() {
for (JacisTransactionListener txListener : txListeners) {
if (txListener.isSynchronizedExcecutionRequiredForCommit()) {
return true;
}
}
return false;
}

protected boolean hasAnyTransactionListenersNeedingSynchronousExecutionForRollback() {
for (JacisTransactionListener txListener : txListeners) {
if (txListener.isSynchronizedExcecutionRequiredForRollback()) {
return true;
}
}
return false;
}


/**
* Prepare the transaction represented by the passed transaction handle.
* Note that this method usually is only called internally.
Expand All @@ -479,7 +498,7 @@ protected boolean hasAnyTransactionListenersNeedingSynchronousExecution() {
public void internalPrepare(JacisTransactionHandle transaction) {
boolean executeSynchronized = hasAnyUpdatesPendingForTx() // if any store has updated entries we need to synchronize
|| hasStoreWithPendingDirtyCheck() // if any store has a dirty check pending (may causing updated entries) we need to synchronize
|| hasAnyTransactionListenersNeedingSynchronousExecution(); // if any transaction listener requires sync. execution we need to synchronize
|| hasAnyTransactionListenersNeedingSynchronousExecutionForPrepare(); // if any transaction listener requires sync. execution we need to synchronize
if (executeSynchronized) {
transactionDemarcationLock.writeLock().lock();
}
Expand Down Expand Up @@ -556,7 +575,7 @@ public <R> R computeGlobalAtomic(Supplier<R> atomicOperation) { // Execute a glo
public void internalCommit(JacisTransactionHandle transaction) { // NO-API
boolean executeSynchronized = hasAnyUpdatesPendingForTx() // if any store has updated entries we need to synchronize
|| hasStoreWithPendingDirtyCheck() // if any store has a dirty check pending (may causing updated entries) we need to synchronize
|| hasAnyTransactionListenersNeedingSynchronousExecution(); // if any transaction listener requires sync. execution we need to synchronize
|| hasAnyTransactionListenersNeedingSynchronousExecutionForCommit(); // if any transaction listener requires sync. execution we need to synchronize
if (executeSynchronized) {
transactionDemarcationLock.writeLock().lock();
}
Expand Down Expand Up @@ -607,7 +626,7 @@ public void internalCommit(JacisTransactionHandle transaction) { // NO-API
*/
public void internalRollback(JacisTransactionHandle transaction) { // NO-API
boolean executeSynchronized = hasAnyUpdatesPendingForTx() // if any store has updated entries we need to synchronize (dirty check can be ignored here)
|| hasAnyTransactionListenersNeedingSynchronousExecution(); // if any transaction listener requires sync. execution we need to synchronize
|| hasAnyTransactionListenersNeedingSynchronousExecutionForRollback(); // if any transaction listener requires sync. execution we need to synchronize
if (executeSynchronized) {
transactionDemarcationLock.writeLock().lock();
}
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/org/jacis/plugin/JacisTransactionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,34 @@
public interface JacisTransactionListener {

/**
* @return if this transaction listener has to be executed synchronized together with the prepare / commit / rollback.
* @return if this transaction listener has to be executed synchronized together with the prepare / commit / rollback (for callbacks on prepare / commit).
*/
default boolean isSynchronizedExcecutionRequired() {
return true;
}

/**
* @return if this transaction listener has to be executed synchronized together with the prepare / commit / rollback (for callbacks on prepare).
*/
default boolean isSynchronizedExcecutionRequiredForPrepare() {
return isSynchronizedExcecutionRequired();
}

/**
* @return if this transaction listener has to be executed synchronized together with the prepare / commit / rollback (for callbacks on commit).
*/
default boolean isSynchronizedExcecutionRequiredForCommit() {
return isSynchronizedExcecutionRequired();
}

/**
* @return if this transaction listener has to be executed synchronized together with the prepare / commit / rollback (for callbacks on rollback).
* Note: Usually on rollback the callbacks do nothing (no changes) and therefore no synchronization is required.
*/
default boolean isSynchronizedExcecutionRequiredForRollback() {
return false;
}

/**
* Callback method called before the prepare phase of a transaction is executed for the stores of the container.
*
Expand All @@ -40,7 +62,7 @@ default void beforePrepare(JacisContainer container, JacisTransactionHandle tx)

/**
* Callback method called after the prepare phase of a transaction is executed for the stores of the container.
*
*
* @param container Reference to the corresponding container instance.
* @param tx Handle for the transaction for which the callback method is invoked.
*/
Expand All @@ -50,7 +72,7 @@ default void afterPrepare(JacisContainer container, JacisTransactionHandle tx) {

/**
* Callback method called before the commit phase of a transaction is executed for the stores of the container.
*
*
* @param container Reference to the corresponding container instance.
* @param tx Handle for the transaction for which the callback method is invoked.
*/
Expand All @@ -60,7 +82,7 @@ default void beforeCommit(JacisContainer container, JacisTransactionHandle tx) {

/**
* Callback method called after the commit phase of a transaction is executed for the stores of the container.
*
*
* @param container Reference to the corresponding container instance.
* @param tx Handle for the transaction for which the callback method is invoked.
*/
Expand All @@ -70,7 +92,7 @@ default void afterCommit(JacisContainer container, JacisTransactionHandle tx) {

/**
* Callback method called before a rollback for a transaction is executed for the stores of the container.
*
*
* @param container Reference to the corresponding container instance.
* @param tx Handle for the transaction for which the callback method is invoked.
*/
Expand All @@ -80,7 +102,7 @@ default void beforeRollback(JacisContainer container, JacisTransactionHandle tx)

/**
* Callback method called after a rollback for a transaction is executed for the stores of the container.
*
*
* @param container Reference to the corresponding container instance.
* @param tx Handle for the transaction for which the callback method is invoked.
*/
Expand Down

0 comments on commit a8b7abb

Please sign in to comment.