summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/indexed
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2010-08-26 00:31:18 +0000
committerBrian S. O'Neill <bronee@gmail.com>2010-08-26 00:31:18 +0000
commit7283752c177a5d38776905f0fa115c2405ae2175 (patch)
tree15a3ee64ca867686ca9b54fe5e7c6f50d6f7b0e4 /src/main/java/com/amazon/carbonado/repo/indexed
parent754b0ca594680502727eb71da755d6a41c9d210f (diff)
More robust corruption repairs.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java38
1 files changed, 31 insertions, 7 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 1b6fe8d..2bb2f49 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java
@@ -207,7 +207,18 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> {
/** Assumes caller is in a transaction */
boolean deleteIndexEntry(S userStorable) throws PersistException {
- return makeIndexEntry(userStorable).tryDelete();
+ try {
+ return makeIndexEntry(userStorable).tryDelete();
+ } catch (PersistException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof IllegalArgumentException) {
+ // Can be caused by a corrupt master record, which is
+ // attempting do assign an illegal value to the index. There's
+ // no way to find the old index entry to delete.
+ return false;
+ }
+ throw e;
+ }
}
/** Assumes caller is in a transaction */
@@ -219,13 +230,26 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> {
boolean updateIndexEntry(S userStorable, S oldUserStorable) throws PersistException {
Storable newIndexEntry = makeIndexEntry(userStorable);
- if (oldUserStorable != null) {
- Storable oldIndexEntry = makeIndexEntry(oldUserStorable);
+ if (oldUserStorable != null) deleteOldEntry: {
+ Storable oldIndexEntry;
+ try {
+ oldIndexEntry = makeIndexEntry(oldUserStorable);
+ } catch (PersistException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof IllegalArgumentException) {
+ // Can be caused by a corrupt master record, which is
+ // attempting do assign an illegal value to the index. There's
+ // no way to find the old index entry to delete.
+ break deleteOldEntry;
+ }
+ throw e;
+ }
+
if (oldIndexEntry.equalPrimaryKeys(newIndexEntry)) {
- // Index entry didn't change, so nothing to do. If the
- // index entry has a version, it will lag behind the
- // master's version until the index entry changes, at which
- // point the version will again match the master.
+ // Index entry didn't change, so nothing to do. If the index
+ // entry has a version, it will lag behind the master's version
+ // until the index entry changes, at which point the version
+ // will again match the master.
return true;
}