From 7a51e9e8fc2b668cf45959236830c6e42056f508 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 7 Dec 2006 18:27:42 +0000 Subject: ReplicatedRepository installs user triggers on the master, not the replica. --- .../carbonado/repo/replicated/ReplicatedStorage.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/amazon') 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 34b6880..ebb6db6 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedStorage.java @@ -42,6 +42,7 @@ import com.amazon.carbonado.spi.BelatedStorageCreator; */ class ReplicatedStorage implements Storage { final Storage mReplicaStorage; + final Storage mMasterStorage; final ReplicationTrigger mTrigger; /** @@ -61,9 +62,8 @@ class ReplicatedStorage implements Storage { (log, aRepository.getMasterRepository(), replicaStorage.getStorableType(), ReplicatedRepositoryBuilder.DEFAULT_RETRY_MILLIS); - Storage masterStorage = - creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS); - mTrigger = new ReplicationTrigger(aRepository, mReplicaStorage, masterStorage); + mMasterStorage = creator.get(ReplicatedRepositoryBuilder.DEFAULT_MASTER_TIMEOUT_MILLIS); + mTrigger = new ReplicationTrigger(aRepository, mReplicaStorage, mMasterStorage); mReplicaStorage.addTrigger(mTrigger); } @@ -75,6 +75,7 @@ class ReplicatedStorage implements Storage { Storage masterStorage) { mReplicaStorage = replicaStorage; + mMasterStorage = masterStorage; mTrigger = new ReplicationTrigger(aRepository, mReplicaStorage, masterStorage); mReplicaStorage.addTrigger(mTrigger); } @@ -99,14 +100,18 @@ class ReplicatedStorage implements Storage { return mReplicaStorage.query(filter); } + // Note: All user triggers must be added to the master storage. Otherwise, + // resync operations can cause the triggers to run again, which can be + // disastrous. If triggers ever support "after load" events, things get + // complicated. Perhaps this use case is a good example for why supporting + // "after load" events might be bad. + public boolean addTrigger(Trigger trigger) { - // FIXME: Should trigger be added to master? - return mReplicaStorage.addTrigger(trigger); + return mMasterStorage.addTrigger(trigger); } public boolean removeTrigger(Trigger trigger) { - // FIXME: Should trigger be added to master? - return mReplicaStorage.removeTrigger(trigger); + return mMasterStorage.removeTrigger(trigger); } ReplicationTrigger getTrigger() { -- cgit v1.2.3