diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-10-17 23:32:59 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-10-17 23:32:59 +0000 |
commit | 30cc7f1c3943be87573849864f1f0637fd5cc3c6 (patch) | |
tree | af8c1e479d97bed96eb28e6fc55358f48c71fa74 /src | |
parent | 987e5b79304062308a5d304a57dabcce97654867 (diff) |
Prevent accidental replication of internal storables.
Diffstat (limited to 'src')
11 files changed, 59 insertions, 43 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/Layout.java b/src/main/java/com/amazon/carbonado/layout/Layout.java index b751fb1..8b8fc0b 100644 --- a/src/main/java/com/amazon/carbonado/layout/Layout.java +++ b/src/main/java/com/amazon/carbonado/layout/Layout.java @@ -220,7 +220,9 @@ public class Layout { */
public List<LayoutProperty> getAllProperties() throws FetchException {
if (mAllProperties == null) {
- Cursor <StoredLayoutProperty> cursor = mStoredLayout.getProperties()
+ Cursor <StoredLayoutProperty> cursor = mLayoutFactory.mPropertyStorage
+ .query("layoutID = ?")
+ .with(mStoredLayout.getLayoutID())
.orderBy("ordinal")
.fetch();
diff --git a/src/main/java/com/amazon/carbonado/layout/StoredLayout.java b/src/main/java/com/amazon/carbonado/layout/StoredLayout.java index b7065d9..f7e250a 100644 --- a/src/main/java/com/amazon/carbonado/layout/StoredLayout.java +++ b/src/main/java/com/amazon/carbonado/layout/StoredLayout.java @@ -18,13 +18,13 @@ package com.amazon.carbonado.layout;
+import com.amazon.carbonado.Alias;
import com.amazon.carbonado.AlternateKeys;
+import com.amazon.carbonado.Independent;
import com.amazon.carbonado.FetchException;
-import com.amazon.carbonado.Join;
import com.amazon.carbonado.Key;
import com.amazon.carbonado.Nullable;
import com.amazon.carbonado.PrimaryKey;
-import com.amazon.carbonado.Query;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Version;
@@ -39,6 +39,8 @@ import com.amazon.carbonado.Version; @Key({"storableTypeName", "generation"})
})
@PrimaryKey("layoutID")
+@Independent
+@Alias("CARBONADO_LAYOUT")
public interface StoredLayout extends Storable<StoredLayout>, Unevolvable {
long getLayoutID();
@@ -82,9 +84,6 @@ public interface StoredLayout extends Storable<StoredLayout>, Unevolvable { void setCreationHost(String host);
- @Join
- Query<StoredLayoutProperty> getProperties() throws FetchException;
-
/**
* Record version number for this StoredTypeLayout instance. Some encoding
* strategies require a version number.
diff --git a/src/main/java/com/amazon/carbonado/layout/StoredLayoutProperty.java b/src/main/java/com/amazon/carbonado/layout/StoredLayoutProperty.java index 96a990a..a6d25db 100644 --- a/src/main/java/com/amazon/carbonado/layout/StoredLayoutProperty.java +++ b/src/main/java/com/amazon/carbonado/layout/StoredLayoutProperty.java @@ -18,9 +18,10 @@ package com.amazon.carbonado.layout;
+import com.amazon.carbonado.Alias;
import com.amazon.carbonado.AlternateKeys;
import com.amazon.carbonado.FetchException;
-import com.amazon.carbonado.Join;
+import com.amazon.carbonado.Independent;
import com.amazon.carbonado.Key;
import com.amazon.carbonado.Nullable;
import com.amazon.carbonado.PrimaryKey;
@@ -38,6 +39,8 @@ import com.amazon.carbonado.Version; @Key({"layoutID", "propertyName"})
})
@PrimaryKey({"layoutID", "ordinal"})
+@Independent
+@Alias("CARBONADO_LAYOUT_PROPERTY")
public interface StoredLayoutProperty extends Storable<StoredLayoutProperty>, Unevolvable {
long getLayoutID();
@@ -101,9 +104,6 @@ public interface StoredLayoutProperty extends Storable<StoredLayoutProperty>, Un void setAdapterParams(String params);
- @Join
- StoredLayout getEnclosingLayout() throws FetchException;
-
/**
* Record version number for this StoredPropertyLayout instance. Some
* encoding strategies require a version number.
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;
diff --git a/src/main/java/com/amazon/carbonado/spi/LobEngine.java b/src/main/java/com/amazon/carbonado/spi/LobEngine.java index 167c5b1..e91bf59 100644 --- a/src/main/java/com/amazon/carbonado/spi/LobEngine.java +++ b/src/main/java/com/amazon/carbonado/spi/LobEngine.java @@ -149,7 +149,7 @@ public class LobEngine { lob.setLocator(locator);
if (lob.tryDelete()) {
try {
- lob.getBlocks().deleteAll();
+ mLobBlockStorage.query("locator = ?").with(lob.getLocator()).deleteAll();
} catch (FetchException e) {
throw e.toPersistException();
}
@@ -579,7 +579,8 @@ public class LobEngine { // Free unused blocks.
long newBlockCount = lob.getBlockCount();
if (newBlockCount < oldBlockCount) {
- lob.getBlocks().and("blockNumber >= ?")
+ mLobBlockStorage.query("locator = ? & blockNumber >= ?")
+ .with(lob.getLocator())
// Subtract 0x80000000 such that block zero is
// physically stored with the smallest integer.
.with(((int) newBlockCount) - 0x80000000)
diff --git a/src/main/java/com/amazon/carbonado/spi/StoredLob.java b/src/main/java/com/amazon/carbonado/spi/StoredLob.java index e081bb3..2435cb1 100644 --- a/src/main/java/com/amazon/carbonado/spi/StoredLob.java +++ b/src/main/java/com/amazon/carbonado/spi/StoredLob.java @@ -18,10 +18,10 @@ package com.amazon.carbonado.spi;
+import com.amazon.carbonado.Alias;
import com.amazon.carbonado.FetchException;
-import com.amazon.carbonado.Join;
+import com.amazon.carbonado.Independent;
import com.amazon.carbonado.PrimaryKey;
-import com.amazon.carbonado.Query;
import com.amazon.carbonado.Sequence;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Version;
@@ -35,6 +35,8 @@ import com.amazon.carbonado.constraint.IntegerConstraint; * @see LobEngine
*/
@PrimaryKey("locator")
+@Independent
+@Alias("CARBONADO_LOB")
public abstract class StoredLob implements Storable<StoredLob> {
@Sequence("com.amazon.carbonado.spi.StoredLob")
public abstract long getLocator();
@@ -52,9 +54,6 @@ public abstract class StoredLob implements Storable<StoredLob> { public abstract int getVersion();
public abstract void setVersion(int version);
- @Join
- public abstract Query<Block> getBlocks() throws FetchException;
-
/**
* Returns number of blocks required to store Lob.
*/
diff --git a/src/main/java/com/amazon/carbonado/spi/StoredSequence.java b/src/main/java/com/amazon/carbonado/spi/StoredSequence.java index bcd0a3c..0a5a19e 100644 --- a/src/main/java/com/amazon/carbonado/spi/StoredSequence.java +++ b/src/main/java/com/amazon/carbonado/spi/StoredSequence.java @@ -19,6 +19,7 @@ package com.amazon.carbonado.spi;
import com.amazon.carbonado.Alias;
+import com.amazon.carbonado.Independent;
import com.amazon.carbonado.PrimaryKey;
import com.amazon.carbonado.Storable;
@@ -28,6 +29,7 @@ import com.amazon.carbonado.Storable; * @author Brian S O'Neill
*/
@PrimaryKey("name")
+@Independent
@Alias("CARBONADO_SEQUENCE")
public interface StoredSequence extends Storable<StoredSequence> {
String getName();
|