summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-04-22 19:34:53 +0000
committerJesse Morgan <jesse@jesterpm.net>2013-04-22 19:34:53 +0000
commitba9f2c325aab60e9637e39256d01b235ff4fa5ac (patch)
tree0d21526a0c16084e7165ce6465dbc6db366b182e
parenta9992bb7c3a4b8ac3bed9755395d0be25e5b096b (diff)
Fix to remove bogus index entries if the primary key can't be loaded
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java22
1 files changed, 17 insertions, 5 deletions
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<S extends Storable> implements IndexEntryAccessor<S> {
// 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();
}