From 8d1436ef524965d67dc7085c34a9fd3f03f7a33c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 18 Feb 2011 17:38:13 +0000 Subject: Add BDB verify support. --- .../carbonado/repo/sleepycat/BDBRepository.java | 3 + .../repo/sleepycat/BDBRepositoryBuilder.java | 68 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) (limited to 'src/main/java/com') 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 extends AbstractRepository 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 rootRef = new AtomicReference(); + 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; } -- cgit v1.2.3