summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-11-16 23:47:31 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-11-16 23:47:31 +0000
commit579aa77f7ead94863d1f0c56d450b3bd2800f8db (patch)
tree5e5225bb778e9e83c1870a0156122b3a6e0976c4 /src
parent5159aab259b67108f9adcdffd863b5c7d58af261 (diff)
Rebuild layout metadata if broken.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/layout/Layout.java12
-rw-r--r--src/main/java/com/amazon/carbonado/layout/LayoutFactory.java10
2 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/Layout.java b/src/main/java/com/amazon/carbonado/layout/Layout.java
index f784e84..d127835 100644
--- a/src/main/java/com/amazon/carbonado/layout/Layout.java
+++ b/src/main/java/com/amazon/carbonado/layout/Layout.java
@@ -408,7 +408,17 @@ public class Layout {
throw new IllegalStateException();
}
mStoredLayout.setGeneration(generation);
- mStoredLayout.insert();
+ if (!mStoredLayout.tryInsert()) {
+ StoredLayout existing = mLayoutFactory.mLayoutStorage.prepare();
+ mStoredLayout.copyPrimaryKeyProperties(existing);
+ try {
+ existing.load();
+ } catch (FetchException e) {
+ throw e.toPersistException();
+ }
+ mStoredLayout.setVersionNumber(existing.getVersionNumber());
+ mStoredLayout.update();
+ }
for (LayoutProperty property : mAllProperties) {
property.insert();
}
diff --git a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java
index 6deb3ee..dc77b75 100644
--- a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java
+++ b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java
@@ -125,6 +125,13 @@ public class LayoutFactory implements LayoutCapability {
break loadLayout;
}
+ if (knownLayout.getAllProperties().size() == 0) {
+ // This is clearly wrong. All Storables must have
+ // at least one property. Assume that layout record
+ // is corrupt so rebuild it.
+ break;
+ }
+
// If this point is reached, then there was a hash collision in
// the generated layout ID. This should be extremely rare.
// Rehash and try again.
@@ -133,7 +140,8 @@ public class LayoutFactory implements LayoutCapability {
// No more rehashes to attempt. This should be extremely,
// extremely rare, unless there is a bug somewhere.
throw new FetchException
- ("Unable to generate unique layout identifier");
+ ("Unable to generate unique layout identifier for " +
+ type.getName());
}
}