[NO ISSUE][RT] Ensure an inverted list cursor.close()
- user model changes: no
- storage format changes: no
- interface changes: no
details:
- Ensure to always execute an inverted list cursor.close().
Change-Id: I78c7908830be810b1d40abffffbd5f1978818869
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2410
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/InMemoryInvertedListCursor.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/InMemoryInvertedListCursor.java
index 085f8d5..6e8689b 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/InMemoryInvertedListCursor.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/InMemoryInvertedListCursor.java
@@ -172,6 +172,7 @@
btreePred.setHighKey(btreeSearchTuple, true);
try {
btreeAccessor.search(btreeCursor, btreePred);
+ cursorNeedsClose = true;
} catch (Exception e) {
btreeSearchTuple.removeLastTuple();
throw HyracksDataException.create(e);
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/ondisk/OnDiskInvertedIndexRangeSearchCursor.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/ondisk/OnDiskInvertedIndexRangeSearchCursor.java
index a33b045..d9e7d34 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/ondisk/OnDiskInvertedIndexRangeSearchCursor.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/ondisk/OnDiskInvertedIndexRangeSearchCursor.java
@@ -87,8 +87,11 @@
return true;
}
// The current inverted-list-range-search cursor is exhausted.
- invListRangeSearchCursor.unloadPages();
- invListRangeSearchCursor.close();
+ try {
+ invListRangeSearchCursor.unloadPages();
+ } finally {
+ invListRangeSearchCursor.close();
+ }
isInvListCursorOpen = false;
openInvListRangeSearchCursor();
return isInvListCursorOpen;
@@ -105,22 +108,34 @@
@Override
public void doDestroy() throws HyracksDataException {
- if (isInvListCursorOpen) {
- invListRangeSearchCursor.unloadPages();
- invListRangeSearchCursor.destroy();
- isInvListCursorOpen = false;
+ try {
+ if (isInvListCursorOpen) {
+ try {
+ invListRangeSearchCursor.unloadPages();
+ } finally {
+ isInvListCursorOpen = false;
+ invListRangeSearchCursor.destroy();
+ }
+ }
+ } finally {
+ btreeCursor.destroy();
}
- btreeCursor.destroy();
}
@Override
public void doClose() throws HyracksDataException {
- if (isInvListCursorOpen) {
- invListRangeSearchCursor.unloadPages();
- invListRangeSearchCursor.close();
- isInvListCursorOpen = false;
+ try {
+ if (isInvListCursorOpen) {
+ try {
+ invListRangeSearchCursor.unloadPages();
+ } finally {
+ invListRangeSearchCursor.close();
+ }
+ isInvListCursorOpen = false;
+ }
+ } finally {
+ btreeCursor.close();
}
- btreeCursor.close();
}
@Override
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/AbstractTOccurrenceSearcher.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/AbstractTOccurrenceSearcher.java
index ff9a2f1..cd0ba36 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/AbstractTOccurrenceSearcher.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/AbstractTOccurrenceSearcher.java
@@ -239,8 +239,11 @@
private void resetResultSource() throws HyracksDataException {
if (isSingleInvertedList) {
isSingleInvertedList = false;
- singleInvListCursor.unloadPages();
- singleInvListCursor.close();
+ try {
+ singleInvListCursor.unloadPages();
+ } finally {
+ singleInvListCursor.close();
+ }
singleInvListCursor = null;
} else {
finalSearchResult.resetBuffer();
@@ -253,9 +256,12 @@
((BufferManagerBackedVSizeFrame) queryTokenFrame).destroy();
// Releases the frames of the cursor.
- if (isSingleInvertedList && singleInvListCursor != null) {
- singleInvListCursor.unloadPages();
- singleInvListCursor.close();
+ if (singleInvListCursor != null) {
+ try {
+ singleInvListCursor.unloadPages();
+ } finally {
+ singleInvListCursor.close();
+ }
}
// Releases the frame of the final search result.
finalSearchResult.close();
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/InvertedListMerger.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/InvertedListMerger.java
index 0bfc140..5da4702 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/InvertedListMerger.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/search/InvertedListMerger.java
@@ -126,41 +126,48 @@
isFinalList = true;
}
InvertedListCursor invListCursor = invListCursors.get(i);
- // Loads the inverted list (at least some part of it).
- invListCursor.prepareLoadPages();
- invListCursor.loadPages();
- if (i < numPrefixLists) {
- // Merges a prefix list.
- doneMerge = mergePrefixList(invListCursor, prevSearchResult, result, isFinalList);
- } else {
- // Merge suffix list.
- int numInvListElements = invListCursor.size();
- int currentNumResults = prevSearchResult.getNumResults();
- // Should we binary search the next list or should we sort-merge it?
- if (currentNumResults * Math.log(numInvListElements) < currentNumResults + numInvListElements) {
- doneMerge = mergeSuffixListProbe(invListCursor, prevSearchResult, result, i, numInvLists,
- occurrenceThreshold, isFinalList);
+ // Track whether an exception is occurred.
+ boolean finishedTryBlock = false;
+ try {
+ // Loads the inverted list (at least some part of it).
+ invListCursor.prepareLoadPages();
+ invListCursor.loadPages();
+ if (i < numPrefixLists) {
+ // Merges a prefix list.
+ doneMerge = mergePrefixList(invListCursor, prevSearchResult, result, isFinalList);
} else {
- doneMerge = mergeSuffixListScan(invListCursor, prevSearchResult, result, i, numInvLists,
- occurrenceThreshold, isFinalList);
+ // Merge suffix list.
+ int numInvListElements = invListCursor.size();
+ int currentNumResults = prevSearchResult.getNumResults();
+ // Should we binary search the next list or should we sort-merge it?
+ if (currentNumResults * Math.log(numInvListElements) < currentNumResults + numInvListElements) {
+ doneMerge = mergeSuffixListProbe(invListCursor, prevSearchResult, result, i, numInvLists,
+ occurrenceThreshold, isFinalList);
+ } else {
+ doneMerge = mergeSuffixListScan(invListCursor, prevSearchResult, result, i, numInvLists,
+ occurrenceThreshold, isFinalList);
+ }
+ }
+ finishedTryBlock = true;
+ } finally {
+ // An intermediate inverted list should always be closed.
+ // The final inverted list should be closed only when traversing the list is done.
+ // If an exception was occurred, just close the cursor.
+ if (!isFinalList || (isFinalList && doneMerge) || !finishedTryBlock) {
+ try {
+ invListCursor.unloadPages();
+ } finally {
+ invListCursor.close();
+ }
}
}
- if (isFinalList) {
- // For the final list, the method unloadPages() should be called only when traversing
- // the inverted list is finished.
- if (doneMerge) {
- invListCursor.unloadPages();
- invListCursor.close();
- }
- // Needs to return the calculation result for the final list only.
- // Otherwise, the process needs to be continued until this method traverses the final inverted list
- // and either generates some output in the output buffer or finishes traversing it.
+ // Needs to return the calculation result for the final list only.
+ // Otherwise, the process needs to be continued until this method traverses the final inverted list
+ // and either generates some output in the output buffer or finishes traversing it.
+ if (isFinalList && doneMerge) {
return doneMerge;
}
-
- invListCursor.unloadPages();
- invListCursor.close();
}
// Control does not reach here.
@@ -195,8 +202,11 @@
if (doneMerge) {
// Final calculation is done.
- finalInvListCursor.unloadPages();
- finalInvListCursor.close();
+ try {
+ finalInvListCursor.unloadPages();
+ } finally {
+ finalInvListCursor.close();
+ }
}
return doneMerge;
@@ -553,8 +563,14 @@
* Cleans every stuff.
*/
public void close() throws HyracksDataException {
- prevSearchResult.close();
- newSearchResult.close();
+ try {
+ prevSearchResult.close();
+ newSearchResult.close();
+ } finally {
+ if (finalInvListCursor != null) {
+ finalInvListCursor.close();
+ }
+ }
}
// Resets the variables.