diff options
author | Tom Keller <keller_tl@users.sourceforge.net> | 2007-01-26 19:36:20 +0000 |
---|---|---|
committer | Tom Keller <keller_tl@users.sourceforge.net> | 2007-01-26 19:36:20 +0000 |
commit | 975fd9fec74313f52007ebb264a03ec68d33448d (patch) | |
tree | def181c16d07d96aacf6686d37394d5847ba03b5 /src/main/java/com/amazon/carbonado | |
parent | bd61d20688ba374941bae16bae990c89645a4e06 (diff) |
Index removal is now batched - reducing memory requirements when removing
large indexes
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java index 9b7f408..5fb94eb 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java @@ -446,7 +446,37 @@ class IndexedStorage<S extends Storable> implements Storage<S>, StorageAccess<S> // Doesn't completely remove the index, but it should free up space.
// TODO: when truncate method exists, call that instead
- indexEntryStorage.query().deleteAll();
+ // TODO: set batchsize based on repository locktable size
+ int batchSize = 10;
+ while (true) {
+ Transaction txn = mRepository.getWrappedRepository()
+ .enterTopTransaction(IsolationLevel.READ_COMMITTED);
+ txn.setForUpdate(true);
+
+ try {
+ Cursor<? extends Storable> cursor = indexEntryStorage.query().fetch();
+ if (!cursor.hasNext()) {
+ break;
+ }
+ int count = 0;
+ try {
+ while (count++ < batchSize && cursor.hasNext()) {
+ cursor.next().tryDelete();
+ }
+ } finally {
+ cursor.close();
+ }
+ if (txn != null) {
+ txn.commit();
+ }
+ } catch (FetchException e) {
+ throw e.toPersistException();
+ } finally {
+ if (txn != null) {
+ txn.exit();
+ }
+ }
+ }
unregisterIndex(index);
}
}
|