-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7612 from lutovich/3.0-safer-tx-termination
Safer KTI termination
- Loading branch information
Showing
12 changed files
with
573 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
community/kernel/src/main/java/org/neo4j/kernel/api/KernelTransactionHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.api; | ||
|
||
import org.neo4j.kernel.api.exceptions.Status; | ||
import org.neo4j.kernel.api.security.AccessMode; | ||
import org.neo4j.kernel.impl.api.Kernel; | ||
|
||
/** | ||
* View of a {@link KernelTransaction} that provides a limited set of actions against the transaction. | ||
*/ | ||
public interface KernelTransactionHandle | ||
{ | ||
/** | ||
* The id of the last transaction that was committed to the store when the underlying transaction started. | ||
* | ||
* @return the committed transaction id. | ||
*/ | ||
long lastTransactionIdWhenStarted(); | ||
|
||
/** | ||
* The timestamp of the last transaction that was committed to the store when the underlying transaction started. | ||
* | ||
* @return the timestamp value obtained with {@link System#currentTimeMillis()}. | ||
*/ | ||
long lastTransactionTimestampWhenStarted(); | ||
|
||
/** | ||
* The start time of the underlying transaction. I.e. basically {@link System#currentTimeMillis()} when user | ||
* called {@link Kernel#newTransaction(KernelTransaction.Type, AccessMode)}. | ||
* | ||
* @return the transaction start time. | ||
*/ | ||
long localStartTime(); | ||
|
||
/** | ||
* Check if the underlying transaction is open. | ||
* | ||
* @return {@code true} if the underlying transaction ({@link KernelTransaction#close()} was not called), | ||
* {@code false} otherwise. | ||
*/ | ||
boolean isOpen(); | ||
|
||
/** | ||
* Mark the underlying transaction for termination. | ||
* | ||
* @param reason the reason for termination. | ||
*/ | ||
void markForTermination( Status reason ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...kernel/src/main/java/org/neo4j/kernel/impl/api/KernelTransactionImplementationHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.api; | ||
|
||
import org.neo4j.kernel.api.KernelTransactionHandle; | ||
import org.neo4j.kernel.api.exceptions.Status; | ||
|
||
/** | ||
* A {@link KernelTransactionHandle} that wraps the given {@link KernelTransactionImplementation}. | ||
* This handle knows that {@link KernelTransactionImplementation}s can be reused and represents a single logical | ||
* transaction. This means that methods like {@link #markForTermination(Status)} can only terminate running | ||
* transaction this handle was created for. | ||
*/ | ||
class KernelTransactionImplementationHandle implements KernelTransactionHandle | ||
{ | ||
private final long txReuseCount; | ||
private final long lastTransactionIdWhenStarted; | ||
private final long lastTransactionTimestampWhenStarted; | ||
private final long localStartTime; | ||
private final KernelTransactionImplementation tx; | ||
|
||
KernelTransactionImplementationHandle( KernelTransactionImplementation tx ) | ||
{ | ||
this.txReuseCount = tx.getReuseCount(); | ||
this.lastTransactionIdWhenStarted = tx.lastTransactionIdWhenStarted(); | ||
this.lastTransactionTimestampWhenStarted = tx.lastTransactionTimestampWhenStarted(); | ||
this.localStartTime = tx.localStartTime(); | ||
this.tx = tx; | ||
} | ||
|
||
@Override | ||
public long lastTransactionIdWhenStarted() | ||
{ | ||
return lastTransactionIdWhenStarted; | ||
} | ||
|
||
@Override | ||
public long lastTransactionTimestampWhenStarted() | ||
{ | ||
return lastTransactionTimestampWhenStarted; | ||
} | ||
|
||
@Override | ||
public long localStartTime() | ||
{ | ||
return localStartTime; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() | ||
{ | ||
return tx.isOpen() && txReuseCount == tx.getReuseCount(); | ||
} | ||
|
||
@Override | ||
public void markForTermination( Status reason ) | ||
{ | ||
tx.markForTermination( txReuseCount, reason ); | ||
} | ||
|
||
@Override | ||
public boolean equals( Object o ) | ||
{ | ||
if ( this == o ) | ||
{ | ||
return true; | ||
} | ||
if ( o == null || getClass() != o.getClass() ) | ||
{ | ||
return false; | ||
} | ||
KernelTransactionImplementationHandle that = (KernelTransactionImplementationHandle) o; | ||
return txReuseCount == that.txReuseCount && tx.equals( that.tx ); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return 31 * (int) (txReuseCount ^ (txReuseCount >>> 32)) + tx.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "KernelTransactionImplementationHandle{txReuseCount=" + txReuseCount + ", tx=" + tx + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.