summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/indexed
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2012-11-28 00:50:54 +0000
committerBrian S. O'Neill <bronee@gmail.com>2012-11-28 00:50:54 +0000
commit341e3975fefdf5e2fb9a62cdf762af7738657ee6 (patch)
treec3558c277db94886da9f59c88161fe10f3ad4188 /src/main/java/com/amazon/carbonado/repo/indexed
parent6ba986731d5f9f35fd6a9f63d61cbd8288a9c12c (diff)
ReplicatedRepository resync no longer creates a for-update transaction on the master.
Pass transaction to trigger, allowing it to change modes.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java3
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/IndexesTrigger.java13
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java b/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java
index 7a1073d..bcb866b 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java
@@ -75,7 +75,8 @@ class DerivedIndexesTrigger<S extends Storable, D extends Storable> extends Trig
}
@Override
- public Object beforeDelete(S storable) throws PersistException {
+ public Object beforeDelete(Transaction txn, S storable) throws PersistException {
+ txn.setForUpdate(true);
try {
if (storable.copy().tryLoad()) {
return createDependentIndexEntries(storable);
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexesTrigger.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexesTrigger.java
index fc8a18a..67f29e8 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexesTrigger.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexesTrigger.java
@@ -24,6 +24,7 @@ import com.amazon.carbonado.CorruptEncodingException;
import com.amazon.carbonado.FetchException;
import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Storable;
+import com.amazon.carbonado.Transaction;
import com.amazon.carbonado.Trigger;
import com.amazon.carbonado.UniqueConstraintException;
@@ -63,7 +64,11 @@ class IndexesTrigger<S extends Storable> extends Trigger<S> {
}
@Override
- public Object beforeUpdate(S storable) throws PersistException {
+ public Object beforeUpdate(Transaction txn, S storable) throws PersistException {
+ // Ensure old storable is loaded with an upgradable lock, allowing
+ // update to proceed without deadlock.
+ txn.setForUpdate(true);
+
// Return old storable for afterUpdate.
S copy = (S) storable.copy();
try {
@@ -88,7 +93,11 @@ class IndexesTrigger<S extends Storable> extends Trigger<S> {
}
@Override
- public Object beforeDelete(S storable) throws PersistException {
+ public Object beforeDelete(Transaction txn, S storable) throws PersistException {
+ // Ensure old storable is loaded with an upgradable lock, allowing
+ // delete to proceed without deadlock.
+ txn.setForUpdate(true);
+
// Delete index entries referenced by existing storable.
S copy = (S) storable.copy();
try {