From 30cc7f1c3943be87573849864f1f0637fd5cc3c6 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 17 Oct 2006 23:32:59 +0000 Subject: Prevent accidental replication of internal storables. --- .../carbonado/repo/indexed/StoredIndexInfo.java | 4 ++++ .../repo/replicated/ReplicatedRepository.java | 20 ++++++++++++++++++-- .../repo/replicated/ReplicatedStorage.java | 22 ++++++++++------------ .../carbonado/repo/sleepycat/BDBRepository.java | 15 +++------------ .../repo/sleepycat/StoredDatabaseInfo.java | 4 ++++ 5 files changed, 39 insertions(+), 26 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo') 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 Storage createStorage(Class type) throws SupportException, RepositoryException { - return new ReplicatedStorage(ReplicatedRepository.this, type); + Storage replicaStorage = mReplicaRepository.storageFor(type); + + try { + return new ReplicatedStorage(ReplicatedRepository.this, replicaStorage); + } catch (UnsupportedTypeException e) { + // Okay, no master. + return replicaStorage; + } } }; } @@ -324,6 +333,13 @@ class ReplicatedRepository Object... filterValues) throws RepositoryException { + ReplicationTrigger trigger; + if (storageFor(type) instanceof ReplicatedStorage) { + trigger = ((ReplicatedStorage) storageFor(type)).getTrigger(); + } else { + throw new UnsupportedTypeException(type); + } + Storage replicaStorage, masterStorage; replicaStorage = mReplicaRepository.storageFor(type); masterStorage = mMasterRepository.storageFor(type); @@ -372,7 +388,7 @@ class ReplicatedRepository try { Cursor 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 implements Storage { final Storage mReplicaStorage; final ReplicationTrigger mTrigger; - public ReplicatedStorage(ReplicatedRepository aRepository, Class aType) - throws SupportException, RepositoryException + /** + * @throws UnsupportedTypeException if master doesn't support Storable, but + * it is marked as Independent + */ + public ReplicatedStorage(ReplicatedRepository aRepository, Storage 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 creator = new BelatedStorageCreator - (log, aRepository.getMasterRepository(), aType, + (log, aRepository.getMasterRepository(), replicaStorage.getStorableType(), ReplicatedRepositoryBuilder.DEFAULT_RETRY_MILLIS); - Storage 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 masterStorage = + creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS); mTrigger = new ReplicationTrigger(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 } 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; -- cgit v1.2.3