summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/sleepycat
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/sleepycat')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java37
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java45
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java10
3 files changed, 71 insertions, 21 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 6fbc4f5..28fc347 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
@@ -49,6 +49,7 @@ import com.amazon.carbonado.capability.StorableInfoCapability;
import com.amazon.carbonado.info.StorableIntrospector;
+import com.amazon.carbonado.layout.Layout;
import com.amazon.carbonado.layout.LayoutCapability;
import com.amazon.carbonado.layout.LayoutFactory;
@@ -88,7 +89,8 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
EnvironmentCapability,
ShutdownCapability,
StorableInfoCapability,
- SequenceCapability
+ SequenceCapability,
+ LayoutCapability
{
private final Log mLog = LogFactory.getLog(getClass());
@@ -168,19 +170,6 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
getLog().info("Opening repository \"" + getName() + '"');
}
- @Override
- @SuppressWarnings("unchecked")
- public <C extends Capability> C getCapability(Class<C> capabilityType) {
- C cap = super.getCapability(capabilityType);
- if (cap != null) {
- return cap;
- }
- if (capabilityType == LayoutCapability.class) {
- return (C) mLayoutFactory;
- }
- return null;
- }
-
public <S extends Storable> IndexInfo[] getIndexInfo(Class<S> storableType)
throws RepositoryException
{
@@ -341,6 +330,26 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
}
@Override
+ public Layout layoutFor(Class<? extends Storable> type)
+ throws FetchException, PersistException
+ {
+ try {
+ return ((BDBStorage) storageFor(type)).getLayout(mStorableCodecFactory);
+ } catch (PersistException e) {
+ throw e;
+ } catch (RepositoryException e) {
+ throw e.toFetchException();
+ }
+ }
+
+ @Override
+ public Layout layoutFor(Class<? extends Storable> type, int generation)
+ throws FetchException
+ {
+ return mLayoutFactory.layoutFor(type, generation);
+ }
+
+ @Override
protected void finalize() {
close();
}
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 c1e6196..0beea65 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java
@@ -34,7 +34,8 @@ import com.amazon.carbonado.RepositoryException;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.repo.indexed.IndexedRepositoryBuilder;
-import com.amazon.carbonado.raw.GenericStorableCodecFactory;
+import com.amazon.carbonado.raw.CompressionType;
+import com.amazon.carbonado.raw.CompressedStorableCodecFactory;
import com.amazon.carbonado.raw.StorableCodecFactory;
import com.amazon.carbonado.spi.AbstractRepositoryBuilder;
@@ -101,6 +102,7 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
private boolean mPrivate;
private boolean mMultiversion;
private boolean mLogInMemory;
+ private Integer mLogFileMaxSize;
private boolean mRunFullRecovery;
private boolean mRunCheckpointer = true;
private int mCheckpointInterval = DEFAULT_CHECKPOINT_INTERVAL;
@@ -110,10 +112,11 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
private Boolean mChecksumEnabled;
private Object mInitialEnvConfig = null;
private Object mInitialDBConfig = null;
- private StorableCodecFactory mStorableCodecFactory = new GenericStorableCodecFactory();
+ private StorableCodecFactory mStorableCodecFactory;
private Runnable mPreShutdownHook;
private Runnable mPostShutdownHook;
private DatabaseHook mDatabaseHook;
+ private Map<String, CompressionType> mCompressionMap;
public BDBRepositoryBuilder() {
}
@@ -136,6 +139,10 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
}
}
+ if (mStorableCodecFactory == null) {
+ mStorableCodecFactory = new CompressedStorableCodecFactory(mCompressionMap);
+ }
+
assertReady();
// Make environment directory if it doesn't exist.
@@ -860,6 +867,40 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
return mDatabaseHook;
}
+ /**
+ * Set the compressor for the given class, overriding a custom StorableCodecFactory.
+
+ * @param type Storable to compress.
+ * @param compressionType String representation of type of
+ * compression. Available options are "NONE" for no compression or "GZIP"
+ * for gzip compression
+ */
+ public void setCompressor(String type, String compressionType) {
+ mStorableCodecFactory = null;
+ compressionType = compressionType.toUpperCase();
+ if (mCompressionMap == null) {
+ mCompressionMap = new HashMap<String, CompressionType>();
+ }
+ CompressionType compressionEnum = CompressionType.valueOf(compressionType);
+ if (compressionEnum != null) {
+ mCompressionMap.put(type, compressionEnum);
+ }
+ }
+
+ /**
+ * Return the compressor used for the given storable.
+ * @param type Storable to compress
+ * @return String representation of the type of compression used. Available options are "NONE"
+ * for no compression and "GZIP" for gzip compression.
+ */
+ public String getCompressor(String type) {
+ if (mCompressionMap == null) {
+ return null;
+ }
+
+ return mCompressionMap.get(type).toString();
+ }
+
private long inMicros(double seconds) {
if (seconds >= Long.MAX_VALUE) {
return Long.MAX_VALUE;
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 4f1ff29..d00b7d5 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
@@ -60,6 +60,7 @@ import com.amazon.carbonado.info.StorableProperty;
import com.amazon.carbonado.layout.Layout;
import com.amazon.carbonado.layout.LayoutFactory;
+import com.amazon.carbonado.layout.LayoutOptions;
import com.amazon.carbonado.layout.Unevolvable;
import com.amazon.carbonado.lob.Blob;
@@ -416,11 +417,9 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
protected void open(boolean readOnly, Txn openTxn, boolean installTriggers)
throws RepositoryException
{
- final Layout layout = getLayout();
-
StorableInfo<S> info = StorableIntrospector.examine(getStorableType());
-
StorableCodecFactory codecFactory = mRepository.getStorableCodecFactory();
+ final Layout layout = getLayout(codecFactory);
// Open primary database.
Object primaryDatabase;
@@ -767,7 +766,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
}
}
- private Layout getLayout() throws RepositoryException {
+ Layout getLayout(StorableCodecFactory codecFactory) throws RepositoryException {
if (Unevolvable.class.isAssignableFrom(getStorableType())) {
// Don't record generation for storables marked as unevolvable.
return null;
@@ -782,7 +781,8 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
return null;
}
- return factory.layoutFor(getStorableType());
+ Class<S> type = getStorableType();
+ return factory.layoutFor(type, codecFactory.getLayoutOptions(type));
}
/**