diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java | 10 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java | 53 |
2 files changed, 35 insertions, 28 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java index b9380fc..8516628 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java @@ -159,9 +159,13 @@ class IndexedRepository implements Repository, mRepository.storageFor(StoredIndexInfo.class)
.query().fetch();
- while (cursor.hasNext()) {
- StoredIndexInfo info = cursor.next();
- names.remove(info.getIndexName());
+ try {
+ while (cursor.hasNext()) {
+ StoredIndexInfo info = cursor.next();
+ names.remove(info.getIndexName());
+ }
+ } finally {
+ cursor.close();
}
return names.toArray(new String[names.size()]);
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 bb17067..ebdea0b 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java @@ -302,37 +302,40 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> { Transaction txn = repo.enterTopTransaction(IsolationLevel.NONE);
try {
Cursor<S> cursor = masterStorage.query().fetch();
- if (!cursor.hasNext()) {
- // Nothing exists in master, so nothing to populate.
- cursor.close();
- return;
- }
+ try {
+ if (!cursor.hasNext()) {
+ // Nothing exists in master, so nothing to populate.
+ return;
+ }
- Log log = LogFactory.getLog(IndexedStorage.class);
- if (log.isInfoEnabled()) {
- StringBuilder b = new StringBuilder();
- b.append("Populating index on ");
- b.append(masterStorage.getStorableType().getName());
- b.append(": ");
- try {
- mIndex.appendTo(b);
- } catch (java.io.IOException e) {
- // Not gonna happen.
+ Log log = LogFactory.getLog(IndexedStorage.class);
+ if (log.isInfoEnabled()) {
+ StringBuilder b = new StringBuilder();
+ b.append("Populating index on ");
+ b.append(masterStorage.getStorableType().getName());
+ b.append(": ");
+ try {
+ mIndex.appendTo(b);
+ } catch (java.io.IOException e) {
+ // Not gonna happen.
+ }
+ log.info(b.toString());
}
- log.info(b.toString());
- }
- // Preload and sort all index entries for improved performance.
+ // Preload and sort all index entries for improved performance.
- buffer = new MergeSortBuffer(mIndexEntryStorage);
- c = mGenerator.getComparator();
- buffer.prepare(c);
+ buffer = new MergeSortBuffer(mIndexEntryStorage);
+ c = mGenerator.getComparator();
+ buffer.prepare(c);
- while (cursor.hasNext()) {
- buffer.add(makeIndexEntry(cursor.next()));
- }
+ while (cursor.hasNext()) {
+ buffer.add(makeIndexEntry(cursor.next()));
+ }
- // No need to commit transaction because no changes should have been made.
+ // No need to commit transaction because no changes should have been made.
+ } finally {
+ cursor.close();
+ }
} finally {
txn.exit();
}
|