summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java4
-rw-r--r--src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java31
-rw-r--r--src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java6
3 files changed, 33 insertions, 8 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java
index a12e0c9..c8ebfa8 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java
@@ -1020,6 +1020,10 @@ public class JDBCStorableIntrospector extends StorableIntrospector {
return mMainInfo.isIndependent();
}
+ public boolean isAuthoritative() {
+ return mMainInfo.isAuthoritative();
+ }
+
public boolean isSupported() {
return mTableName != null;
}
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 ebfd87f..11c11b6 100644
--- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java
@@ -50,6 +50,7 @@ import com.amazon.carbonado.capability.ShutdownCapability;
import com.amazon.carbonado.capability.StorableInfoCapability;
import com.amazon.carbonado.info.Direction;
+import com.amazon.carbonado.info.StorableInfo;
import com.amazon.carbonado.info.StorableIntrospector;
import com.amazon.carbonado.spi.StorageCollection;
@@ -152,13 +153,31 @@ class ReplicatedRepository
protected <S extends Storable> Storage<S> createStorage(Class<S> type)
throws SupportException, RepositoryException
{
- Storage<S> replicaStorage = mReplicaRepository.storageFor(type);
+ StorableInfo<S> info = StorableIntrospector.examine(type);
- try {
- return new ReplicatedStorage<S>(ReplicatedRepository.this, replicaStorage);
- } catch (UnsupportedTypeException e) {
- // Okay, no master.
- return replicaStorage;
+ if (info.isAuthoritative()) {
+ // Cannot rely on replica to be up-to-date, so always go to master.
+ try {
+ return mMasterRepository.storageFor(type);
+ } catch (UnsupportedTypeException e) {
+ if (info.isIndependent()) {
+ // Okay, no master. A standalone replica is
+ // considered to be authoritative.
+ return mReplicaRepository.storageFor(type);
+ }
+ throw e;
+ }
+ } else {
+ Storage<S> replicaStorage = mReplicaRepository.storageFor(type);
+ try {
+ return new ReplicatedStorage<S>(ReplicatedRepository.this, replicaStorage);
+ } catch (UnsupportedTypeException e) {
+ if (info.isIndependent()) {
+ // Okay, no master.
+ return replicaStorage;
+ }
+ throw e;
+ }
}
}
};
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 38c57c4..34b6880 100644
--- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java
@@ -64,7 +64,7 @@ class ReplicatedStorage<S extends Storable> implements Storage<S> {
Storage<S> masterStorage =
creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS);
mTrigger = new ReplicationTrigger<S>(aRepository, mReplicaStorage, masterStorage);
- addTrigger(mTrigger);
+ mReplicaStorage.addTrigger(mTrigger);
}
/**
@@ -76,7 +76,7 @@ class ReplicatedStorage<S extends Storable> implements Storage<S> {
{
mReplicaStorage = replicaStorage;
mTrigger = new ReplicationTrigger<S>(aRepository, mReplicaStorage, masterStorage);
- addTrigger(mTrigger);
+ mReplicaStorage.addTrigger(mTrigger);
}
public Class<S> getStorableType() {
@@ -100,10 +100,12 @@ class ReplicatedStorage<S extends Storable> implements Storage<S> {
}
public boolean addTrigger(Trigger<? super S> trigger) {
+ // FIXME: Should trigger be added to master?
return mReplicaStorage.addTrigger(trigger);
}
public boolean removeTrigger(Trigger<? super S> trigger) {
+ // FIXME: Should trigger be added to master?
return mReplicaStorage.removeTrigger(trigger);
}