From 6806b3a6fff3f236ae41ab741618b3ad51a64783 Mon Sep 17 00:00:00 2001 From: Tobias Holgers Date: Fri, 15 May 2009 23:52:35 +0000 Subject: Added methods for configuring checkpointThresholdKB, checkpointThresholdMinutes, and checksumEnabled. --- .../carbonado/repo/sleepycat/BDBRepository.java | 35 +++++------ .../repo/sleepycat/BDBRepositoryBuilder.java | 72 ++++++++++++++++++++-- 2 files changed, 82 insertions(+), 25 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 01e3668..1391c40 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -109,9 +109,6 @@ abstract class BDBRepository extends AbstractRepository private final BDBRepositoryBuilder.DatabaseHook mDatabaseHook; private final Map, Integer> mDatabasePageSizes; - final boolean mRunCheckpointer; - final boolean mRunDeadlockDetector; - final File mDataHome; final File mEnvHome; final String mSingleFileName; @@ -152,8 +149,6 @@ abstract class BDBRepository extends AbstractRepository mExTransformer = exTransformer; mTxnMgr = new BDBTransactionManager(mExTransformer, this); - mRunCheckpointer = !builder.getReadOnly() && builder.getRunCheckpointer(); - mRunDeadlockDetector = builder.getRunDeadlockDetector(); mStorableCodecFactory = builder.getStorableCodecFactory(); mPreShutdownHook = builder.getPreShutdownHook(); mPostShutdownHook = builder.getShutdownHook(); @@ -545,22 +540,31 @@ abstract class BDBRepository extends AbstractRepository } /** + * Start background tasks and enable auto shutdown. + * * @param checkpointInterval how often to run checkpoints, in milliseconds, - * or zero if never. Ignored if builder has checkpoints disabled. + * or zero if never. Ignored if repository is read only or builder has + * checkpoints disabled. * @param deadlockDetectorInterval how often to run deadlock detector, in - * milliseconds, or zero if never. + * milliseconds, or zero if never. Ignored if builder has deadlock detector + * disabled. + * @param builder containing additonal background task properties. */ - void start(long checkpointInterval, long deadlockDetectorInterval) { + void start(long checkpointInterval, long deadlockDetectorInterval, + BDBRepositoryBuilder builder) { getLog().info("Opened repository \"" + getName() + '"'); - if (mRunCheckpointer && checkpointInterval > 0) { - mCheckpointer = new Checkpointer(this, checkpointInterval); + if (!builder.getReadOnly() && builder.getRunCheckpointer() + && checkpointInterval > 0) { + mCheckpointer = new Checkpointer(this, checkpointInterval, + builder.getCheckpointThresholdKB(), + builder.getCheckpointThresholdMinutes()); mCheckpointer.start(); } else { mCheckpointer = null; } - if (mRunDeadlockDetector && deadlockDetectorInterval > 0) { + if (builder.getRunDeadlockDetector() && deadlockDetectorInterval > 0) { mDeadlockDetector = new DeadlockDetector(this, deadlockDetectorInterval); mDeadlockDetector.start(); } else { @@ -659,15 +663,6 @@ abstract class BDBRepository extends AbstractRepository private boolean mInProgress; private long mSuspendUntil = Long.MIN_VALUE; - /** - * - * @param repository outer class - * @param sleepInterval milliseconds to sleep before running checkpoint - */ - Checkpointer(BDBRepository repository, long sleepInterval) { - this(repository, sleepInterval, 1024, 5); - } - /** * * @param repository outer class 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 9301f28..f3ea993 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java @@ -104,7 +104,10 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { private boolean mRunFullRecovery; private boolean mRunCheckpointer = true; private int mCheckpointInterval = DEFAULT_CHECKPOINT_INTERVAL; + private int mCheckpointThresholdKB = 1024; + private int mCheckpointThresholdMinutes = 5; private boolean mRunDeadlockDetector = true; + private Boolean mChecksumEnabled; private Object mInitialEnvConfig = null; private Object mInitialDBConfig = null; private StorableCodecFactory mStorableCodecFactory = new GenericStorableCodecFactory(); @@ -439,8 +442,8 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { } /** - * Set the percent of JVM heap used by the repository cache. Actual - * BDB implementation will select a suitable default if this is not + * Set the percent of JVM heap used by the repository cache. Actual + * BDB implementation will select a suitable default if this is not * set. This is overridden by setting an explicit cacheSize. */ public void setCachePercent(int cachePercent) { @@ -448,8 +451,8 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { } /** - * Set the percent of JVM heap used by the repository cache. Actual - * BDB implementation will select a suitable default if this is not + * Set the percent of JVM heap used by the repository cache. Actual + * BDB implementation will select a suitable default if this is not * set. This is overridden by setting an explicit cacheSize. * * @param cachePercent percent of JVM heap to use, or null for default @@ -459,7 +462,7 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { } /** - * Returns the percent of JVM heap used by the repository cache, or + * Returns the percent of JVM heap used by the repository cache, or * null if default should be selected. */ public Integer getCachePercent() { @@ -675,6 +678,48 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { return mCheckpointInterval; } + /** + * Set the size threshold to run checkpoints. This setting is ignored if + * the checkpointer is not configured to run. + * + *

Checkpoint threshold is only used by Carbonado's built-in + * checkpointer, and is ignored when using BDB-JE. + * + * @param thresholdKB run checkpoint if at least this many kilobytes in log + */ + public void setCheckpointThresholdKB(int thresholdKB) { + mCheckpointThresholdKB = thresholdKB; + } + + /** + * @return run checkpoint if at least this many kilobytes in log + */ + public int getCheckpointThresholdKB() { + return mCheckpointThresholdKB; + } + + /** + * Set the time threshold to run checkpoints. This setting is ignored if + * the checkpointer is not configured to run. + * + *

Checkpoint threshold is only used by Carbonado's built-in + * checkpointer, and is ignored when using BDB-JE. + * + * @param thresholdMinutes run checkpoint if at least this many minutes + * passed since last checkpoint + */ + public void setCheckpointThresholdMinutes(int thresholdMinutes) { + mCheckpointThresholdMinutes = thresholdMinutes; + } + + /** + * @return run checkpoint if at least this many minutes passed since last + * checkpoint + */ + public int getCheckpointThresholdMinutes() { + return mCheckpointThresholdMinutes; + } + /** * Disable automatic deadlock detection of database if another thread is * responsible for that. @@ -690,6 +735,23 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { return mRunDeadlockDetector; } + /** + * When true, enable checksum verification of pages read into the cache + * from the backing filestore. By default checksum is enabled for BDB-JE, + * and disabled for BDB-C. + */ + public void setChecksumEnabled(Boolean checksumEnabled) { + mChecksumEnabled = checksumEnabled; + } + + /** + * Returns true if checksum verification is enabled. Returns null if the + * BDB default is used. + */ + public Boolean getChecksumEnabled() { + return mChecksumEnabled; + } + /** * Optionally set the BDB specific environment configuration to * use. The builder will verify that needed configuration values are set. -- cgit v1.2.3