From 975fd9fec74313f52007ebb264a03ec68d33448d Mon Sep 17 00:00:00 2001 From: Tom Keller Date: Fri, 26 Jan 2007 19:36:20 +0000 Subject: Index removal is now batched - reducing memory requirements when removing large indexes --- .../carbonado/repo/indexed/IndexedStorage.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/amazon/carbonado/repo/indexed') 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 implements Storage, StorageAccess // 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 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); } } -- cgit v1.2.3