From 332cccc96e2a9014cbc1d614fedc35048315b53a Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 31 Oct 2006 18:04:54 +0000 Subject: Cope with errors during resync. --- .../carbonado/repo/sleepycat/BDBStorage.java | 44 ++++++++++++++-------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/sleepycat') 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 implements Storage, 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; -- cgit v1.2.3