diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
5 files changed, 39 insertions, 26 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/StoredIndexInfo.java b/src/main/java/com/amazon/carbonado/repo/indexed/StoredIndexInfo.java index 915f90b..5674de5 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/StoredIndexInfo.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/StoredIndexInfo.java @@ -18,6 +18,8 @@ package com.amazon.carbonado.repo.indexed;
+import com.amazon.carbonado.Alias;
+import com.amazon.carbonado.Independent;
import com.amazon.carbonado.Nullable;
import com.amazon.carbonado.PrimaryKey;
import com.amazon.carbonado.Storable;
@@ -34,6 +36,8 @@ import com.amazon.carbonado.layout.Unevolvable; * @author Brian S O'Neill
*/
@PrimaryKey("indexName")
+@Independent
+@Alias("CARBONADO_INDEX_INFO")
public interface StoredIndexInfo extends Storable, Unevolvable, Unindexed {
/**
* Returns the index name, which is also a valid index name
diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java index b07b853..16a33bd 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java @@ -40,6 +40,7 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.Storage;
import com.amazon.carbonado.SupportException;
import com.amazon.carbonado.Transaction;
+import com.amazon.carbonado.UnsupportedTypeException;
import com.amazon.carbonado.capability.Capability;
import com.amazon.carbonado.capability.IndexInfo;
@@ -143,11 +144,19 @@ class ReplicatedRepository mName = aName;
mReplicaRepository = aReplicaRepository;
mMasterRepository = aMasterRepository;
+
mStorages = new StorageCollection() {
protected <S extends Storable> Storage<S> createStorage(Class<S> type)
throws SupportException, RepositoryException
{
- return new ReplicatedStorage<S>(ReplicatedRepository.this, type);
+ Storage<S> replicaStorage = mReplicaRepository.storageFor(type);
+
+ try {
+ return new ReplicatedStorage<S>(ReplicatedRepository.this, replicaStorage);
+ } catch (UnsupportedTypeException e) {
+ // Okay, no master.
+ return replicaStorage;
+ }
}
};
}
@@ -324,6 +333,13 @@ class ReplicatedRepository Object... filterValues)
throws RepositoryException
{
+ ReplicationTrigger<S> trigger;
+ if (storageFor(type) instanceof ReplicatedStorage) {
+ trigger = ((ReplicatedStorage) storageFor(type)).getTrigger();
+ } else {
+ throw new UnsupportedTypeException(type);
+ }
+
Storage<S> replicaStorage, masterStorage;
replicaStorage = mReplicaRepository.storageFor(type);
masterStorage = mMasterRepository.storageFor(type);
@@ -372,7 +388,7 @@ class ReplicatedRepository try {
Cursor<S> masterCursor = masterQuery.fetch();
try {
- resync(((ReplicatedStorage) storageFor(type)).getTrigger(),
+ resync(trigger,
replicaCursor,
masterCursor,
throttle, desiredSpeed,
diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java index f781279..38c57c4 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java @@ -44,27 +44,25 @@ class ReplicatedStorage<S extends Storable> implements Storage<S> { final Storage<S> mReplicaStorage;
final ReplicationTrigger<S> mTrigger;
- public ReplicatedStorage(ReplicatedRepository aRepository, Class<S> aType)
- throws SupportException, RepositoryException
+ /**
+ * @throws UnsupportedTypeException if master doesn't support Storable, but
+ * it is marked as Independent
+ */
+ public ReplicatedStorage(ReplicatedRepository aRepository, Storage<S> replicaStorage)
+ throws SupportException, RepositoryException, UnsupportedTypeException
{
- mReplicaStorage = aRepository.getReplicaRepository().storageFor(aType);
+ mReplicaStorage = replicaStorage;
// Create master using BelatedStorageCreator such that we can start up
// and read from replica even if master is down.
Log log = LogFactory.getLog(getClass());
BelatedStorageCreator<S> creator = new BelatedStorageCreator<S>
- (log, aRepository.getMasterRepository(), aType,
+ (log, aRepository.getMasterRepository(), replicaStorage.getStorableType(),
ReplicatedRepositoryBuilder.DEFAULT_RETRY_MILLIS);
- Storage<S> masterStorage;
- try {
- masterStorage = creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS);
- } catch (UnsupportedTypeException e) {
- // Master doesn't support Storable, but it is marked as Independent.
- masterStorage = null;
- }
-
+ Storage<S> masterStorage =
+ creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS);
mTrigger = new ReplicationTrigger<S>(aRepository, mReplicaStorage, masterStorage);
addTrigger(mTrigger);
}
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 b97ec14..3e2feaf 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -459,19 +459,10 @@ abstract class BDBRepository<Txn> }
LobEngine getLobEngine() throws RepositoryException {
- LobEngine engine = mLobEngine;
- if (engine == null) {
- lockoutShutdown();
- try {
- if ((engine = mLobEngine) == null) {
- mLobEngine = engine = new LobEngine(this);
- }
- return engine;
- } finally {
- unlockoutShutdown();
- }
+ if (mLobEngine == null) {
+ mLobEngine = new LobEngine(getRootRepository());
}
- return engine;
+ return mLobEngine;
}
/**
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/StoredDatabaseInfo.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/StoredDatabaseInfo.java index 9925e01..ae005b3 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/StoredDatabaseInfo.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/StoredDatabaseInfo.java @@ -18,6 +18,8 @@ package com.amazon.carbonado.repo.sleepycat;
+import com.amazon.carbonado.Alias;
+import com.amazon.carbonado.Independent;
import com.amazon.carbonado.Nullable;
import com.amazon.carbonado.PrimaryKey;
import com.amazon.carbonado.Storable;
@@ -35,6 +37,8 @@ import com.amazon.carbonado.repo.indexed.Unindexed; * @author Brian S O'Neill
*/
@PrimaryKey("databaseName")
+@Independent
+@Alias("CARBONADO_DATABASE_INFO")
public abstract class StoredDatabaseInfo implements Storable, Unevolvable, Unindexed {
/** Evolution strategy code */
public static final int EVOLUTION_NONE = 0, EVOLUTION_STANDARD = 1;
|