summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java5
-rw-r--r--src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java21
2 files changed, 21 insertions, 5 deletions
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 9b1a218..1b46073 100644
--- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepository.java
@@ -694,8 +694,11 @@ class ReplicatedRepository
Runnable task = new Runnable() {
public void run() {
+ // Reload deletes and updates. Don't reload inserts, because it
+ // makes a resync from an empty replica way too expensive.
+ boolean reload = masterEntry == null || replicaEntry != null;
try {
- replicationTrigger.resyncEntries(listener, replicaEntry, masterEntry);
+ replicationTrigger.resyncEntries(listener, replicaEntry, masterEntry, reload);
} catch (Exception e) {
LogFactory.getLog(ReplicatedRepository.class).error(null, e);
}
diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java
index 941910d..c646f8c 100644
--- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java
+++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java
@@ -217,9 +217,10 @@ class ReplicationTrigger<S extends Storable> extends Trigger<S> {
* @param listener optional
* @param replicaEntry current replica entry, or null if none
* @param masterEntry current master entry, or null if none
+ * @param reload true to reload master entry
*/
void resyncEntries(ResyncCapability.Listener<? super S> listener,
- S replicaEntry, S masterEntry)
+ S replicaEntry, S masterEntry, boolean reload)
throws FetchException, PersistException
{
if (replicaEntry == null && masterEntry == null) {
@@ -232,6 +233,18 @@ class ReplicationTrigger<S extends Storable> extends Trigger<S> {
try {
Transaction txn = mRepository.enterTransaction();
try {
+ txn.setForUpdate(true);
+
+ if (reload) {
+ if (masterEntry == null) {
+ masterEntry = mMasterStorage.prepare();
+ replicaEntry.copyAllProperties(masterEntry);
+ }
+ if (!masterEntry.tryLoad()) {
+ masterEntry = null;
+ }
+ }
+
final S newReplicaEntry;
if (replicaEntry == null) {
newReplicaEntry = mReplicaStorage.prepare();
@@ -419,12 +432,12 @@ class ReplicationTrigger<S extends Storable> extends Trigger<S> {
txn.setForUpdate(true);
if (finalReplica.tryLoad()) {
if (finalMaster.tryLoad()) {
- resyncEntries(null, finalReplica, finalMaster);
+ resyncEntries(null, finalReplica, finalMaster, false);
} else {
- resyncEntries(null, finalReplica, null);
+ resyncEntries(null, finalReplica, null, false);
}
} else if (finalMaster.tryLoad()) {
- resyncEntries(null, null, finalMaster);
+ resyncEntries(null, null, finalMaster, false);
}
txn.commit();
} finally {