From b7ac911eb0747e43e24c49c4540b5b43e568235e Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 18 Feb 2007 03:19:54 +0000 Subject: Index creation does a better job of picking up where it left off, avoiding unnecessary delete/insert pairs. --- .../amazon/carbonado/repo/indexed/ManagedIndex.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src') 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 implements IndexEntryAccessor { 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) { -- cgit v1.2.3