diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2011-02-18 17:38:13 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2011-02-18 17:38:13 +0000 |
commit | 8d1436ef524965d67dc7085c34a9fd3f03f7a33c (patch) | |
tree | f41463abd2894280654398a2c61a52f561b8115c /src/main/java/com/amazon | |
parent | b130cf0025af0070c38d36e6d4b6902188ade9a0 (diff) |
Add BDB verify support.
Diffstat (limited to 'src/main/java/com/amazon')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java | 3 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java | 68 |
2 files changed, 71 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java index eb10042..0793f97 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -19,6 +19,7 @@ package com.amazon.carbonado.repo.sleepycat;
import java.io.File;
+import java.io.PrintStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Map;
@@ -640,6 +641,8 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn> setAutoShutdownEnabled(true);
}
+ abstract boolean verify(PrintStream out) throws Exception;
+
abstract IsolationLevel selectIsolationLevel(Transaction parent, IsolationLevel level);
abstract Txn txn_begin(Txn parent, IsolationLevel level) throws Exception;
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java index 2a7a931..4df17f5 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java @@ -22,6 +22,7 @@ import java.lang.reflect.Constructor; import java.io.File;
import java.io.IOException;
+import java.io.PrintStream;
import java.util.Collection;
import java.util.HashMap;
@@ -173,6 +174,73 @@ public final class BDBRepositoryBuilder extends AbstractRepositoryBuilder { return repo;
}
+ /**
+ * Opens the BDB environment, checks if it is corrupt, and then closes it.
+ * Only one process should open the environment for verification. Expect it
+ * to take a long time.
+ *
+ * @param out optional stream to capture any verfication errors
+ * @return true if environment passes verification
+ */
+ public boolean verify(PrintStream out) throws RepositoryException {
+ final StorableCodecFactory codecFactory = mStorableCodecFactory;
+ final String name = mName;
+ final boolean readOnly = mReadOnly;
+ final boolean runCheckpointer = mRunCheckpointer;
+ final boolean runDeadlockDetector = mRunDeadlockDetector;
+ final boolean isPrivate = mPrivate;
+
+ if (mName == null) {
+ // Allow a dummy name for verification.
+ mName = "BDB verification";
+ }
+
+ if (mStorableCodecFactory == null) {
+ mStorableCodecFactory = new CompressedStorableCodecFactory(mCompressionMap);
+ }
+
+ mReadOnly = true;
+ mRunCheckpointer = false;
+ mRunDeadlockDetector = false;
+
+ try {
+ assertReady();
+
+ File homeFile = getEnvironmentHomeFile();
+ if (!homeFile.exists()) {
+ throw new RepositoryException
+ ("Environment home directory does not exist: " + homeFile);
+ }
+
+ AtomicReference<Repository> rootRef = new AtomicReference<Repository>();
+ BDBRepository repo;
+
+ try {
+ repo = getRepositoryConstructor().newInstance(rootRef, this);
+ } catch (Exception e) {
+ ThrowUnchecked.fireFirstDeclaredCause(e, RepositoryException.class);
+ // Not reached.
+ return false;
+ }
+
+ rootRef.set(repo);
+
+ try {
+ return repo.verify(out);
+ } catch (Exception e) {
+ throw repo.toRepositoryException(e);
+ } finally {
+ repo.close();
+ }
+ } finally {
+ mName = name;
+ mStorableCodecFactory = codecFactory;
+ mReadOnly = readOnly;
+ mRunCheckpointer = runCheckpointer;
+ mRunDeadlockDetector = runDeadlockDetector;
+ }
+ }
+
public String getName() {
return mName;
}
|