提交 c245dccc authored 作者: Andrei Tokar's avatar Andrei Tokar

minimize synchronization on tx commit

上级 d8701908
...@@ -144,6 +144,11 @@ public class Transaction { ...@@ -144,6 +144,11 @@ public class Transaction {
*/ */
private Object blockingKey; private Object blockingKey;
/**
* Whether other transaction(s) are waiting for this to close.
*/
private volatile boolean notificationRequested;
Transaction(TransactionStore store, int transactionId, long sequenceNum, int status, Transaction(TransactionStore store, int transactionId, long sequenceNum, int status,
String name, long logId, int timeoutMillis, int ownerId, String name, long logId, int timeoutMillis, int ownerId,
...@@ -394,7 +399,9 @@ public class Transaction { ...@@ -394,7 +399,9 @@ public class Transaction {
try { try {
store.rollbackTo(this, logId, savepointId); store.rollbackTo(this, logId, savepointId);
} finally { } finally {
if (notificationRequested) {
notifyAllWaitingTransactions(); notifyAllWaitingTransactions();
}
long expectedState = composeState(STATUS_ROLLING_BACK, logId, hasRollback(lastState)); long expectedState = composeState(STATUS_ROLLING_BACK, logId, hasRollback(lastState));
long newState = composeState(STATUS_OPEN, savepointId, true); long newState = composeState(STATUS_OPEN, savepointId, true);
do { do {
...@@ -478,7 +485,7 @@ public class Transaction { ...@@ -478,7 +485,7 @@ public class Transaction {
void closeIt() { void closeIt() {
long lastState = setStatus(STATUS_CLOSED); long lastState = setStatus(STATUS_CLOSED);
store.store.deregisterVersionUsage(txCounter); store.store.deregisterVersionUsage(txCounter);
if(hasChanges(lastState) || hasRollback(lastState)) { if((hasChanges(lastState) || hasRollback(lastState)) && notificationRequested) {
notifyAllWaitingTransactions(); notifyAllWaitingTransactions();
} }
} }
...@@ -533,6 +540,7 @@ public class Transaction { ...@@ -533,6 +540,7 @@ public class Transaction {
private synchronized boolean waitForThisToEnd(int millis) { private synchronized boolean waitForThisToEnd(int millis) {
long until = System.currentTimeMillis() + millis; long until = System.currentTimeMillis() + millis;
notificationRequested = true;
long state; long state;
int status; int status;
while((status = getStatus(state = statusAndLogId.get())) != STATUS_CLOSED while((status = getStatus(state = statusAndLogId.get())) != STATUS_CLOSED
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论