diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-02-18 03:19:54 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-02-18 03:19:54 +0000 |
commit | b7ac911eb0747e43e24c49c4540b5b43e568235e (patch) | |
tree | 567e3595ecfd075c0eda052b0f28899131f21c84 | |
parent | c4954dc33c91c3815dda286b765e7164ec2b3eba (diff) |
Index creation does a better job of picking up where it left off, avoiding unnecessary delete/insert pairs.
-rw-r--r-- | RELEASE-NOTES.txt | 2 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java | 18 |
2 files changed, 17 insertions, 3 deletions
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index ea9ff54..1d9d7ca 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -10,6 +10,8 @@ Carbonado change history - ReplicatedRepository installs user triggers on the replica again, but it now
disables all triggers during resync to prevent errors. When triggers were on
master, downstream triggers would not see changes made by earlier triggers.
+- Index creation does a better job of picking up where it left off, avoiding
+ unnecessary delete/insert pairs.
1.1-BETA9 to 1.1-BETA10
-------------------------------
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java index 274c452..958bd7b 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java @@ -370,9 +370,21 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> { for (Object obj : buffer) {
Storable indexEntry = (Storable) obj;
if (!indexEntry.tryInsert()) {
- // repair
- indexEntry.tryDelete();
- indexEntry.tryInsert();
+ // Couldn't insert because an index entry already exists.
+ Storable existing = indexEntry.copy();
+ if (existing.tryLoad()) {
+ if (!existing.equalProperties(indexEntry)) {
+ // Existing entry differs, so update it.
+ indexEntry.copyUnequalProperties(existing);
+ existing.tryUpdate();
+ indexEntry = existing;
+ }
+ } else {
+ // Couldn't find existing entry for some reason, so
+ // repair by brute force.
+ indexEntry.tryDelete();
+ indexEntry.tryInsert();
+ }
}
totalInserted++;
if (totalInserted % POPULATE_BATCH_SIZE == 0) {
|