summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/sleepycat
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-10-31 18:04:54 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-10-31 18:04:54 +0000
commit332cccc96e2a9014cbc1d614fedc35048315b53a (patch)
tree2c8d9f8ede7f1503cc023d0b662e7cf575376aa3 /src/main/java/com/amazon/carbonado/repo/sleepycat
parente009e8ea98d8c9c15e0a90a5085ac435093cb9ed (diff)
Cope with errors during resync.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/sleepycat')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
index 331c7b0..d8a3066 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
@@ -36,6 +36,7 @@ import com.amazon.carbonado.Storage;
import com.amazon.carbonado.SupportException;
import com.amazon.carbonado.Transaction;
import com.amazon.carbonado.Trigger;
+import com.amazon.carbonado.UniqueConstraintException;
import com.amazon.carbonado.capability.IndexInfo;
@@ -721,24 +722,35 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
}
info.setDatabaseName(getStorableType().getName());
- Transaction txn = repo.enterTopTransaction(IsolationLevel.READ_COMMITTED);
- txn.setForUpdate(true);
- try {
- if (!info.tryLoad()) {
- if (layout == null) {
- info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_NONE);
- } else {
- info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_STANDARD);
- }
- info.setCreationTimestamp(System.currentTimeMillis());
- info.setVersionNumber(0);
- if (!readOnly) {
- info.insert();
+ // Try to insert metadata up to three times.
+ for (int retryCount = 3;;) {
+ try {
+ Transaction txn = repo.enterTopTransaction(IsolationLevel.READ_COMMITTED);
+ txn.setForUpdate(true);
+ try {
+ if (!info.tryLoad()) {
+ if (layout == null) {
+ info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_NONE);
+ } else {
+ info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_STANDARD);
+ }
+ info.setCreationTimestamp(System.currentTimeMillis());
+ info.setVersionNumber(0);
+ if (!readOnly) {
+ info.insert();
+ }
+ }
+ txn.commit();
+ } finally {
+ txn.exit();
}
+ break;
+ } catch (UniqueConstraintException e) {
+ // This might be caused by a transient replication error. Retry
+ // a few times before throwing exception. Wait up to a second
+ // before each retry.
+ retryCount = e.backoff(e, retryCount, 1000);
}
- txn.commit();
- } finally {
- txn.exit();
}
return info;