diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
-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);
}
}
|