From ba9f2c325aab60e9637e39256d01b235ff4fa5ac Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Mon, 22 Apr 2013 19:34:53 +0000 Subject: Fix to remove bogus index entries if the primary key can't be loaded --- .../carbonado/repo/indexed/ManagedIndex.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo') 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 60a21d5..ab46307 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java @@ -721,14 +721,26 @@ class ManagedIndex implements IndexEntryAccessor { // If index entry already exists, then index might be corrupt. try { - Storable freshEntry = mIndexEntryStorage.prepare(); - mAccessor.copyFromMaster(freshEntry, userStorable); - freshEntry.load(); - indexEntry.copyVersionProperty(freshEntry); - if (freshEntry.equals(indexEntry)) { + Storable freshIndexEntry = mIndexEntryStorage.prepare(); + mAccessor.copyFromMaster(freshIndexEntry, userStorable); + freshIndexEntry.load(); + indexEntry.copyVersionProperty(freshIndexEntry); + if (freshIndexEntry.equals(indexEntry)) { // Existing entry is fine. return true; + + } else { + S freshMasterEntry = mMasterStorage.prepare(); + mAccessor.copyToMasterPrimaryKey(freshIndexEntry, freshMasterEntry); + + if (!freshMasterEntry.tryLoad()) { + // Existing entry for alternate key is bogus. Delete it. + freshIndexEntry.delete(); + indexEntry.insert(); + return true; + } } + } catch (FetchException e) { throw e.toPersistException(); } -- cgit v1.2.3