-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F.memory limited cache #348
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
86a516c
Memory Limit for the Cache
joka921 3e62aab
Clang-formatted this whole business.
joka921 5f26897
Refactorings from hannahs review for the Cache.h file
joka921 099e3bb
Added tests for pinned CacheAdapter functionality, added remarks by H…
joka921 6e3dfbf
Included Hannah's review into the ConcurrentCache (previously CacheAd…
joka921 20ed72a
Changes from Hannah's review.
joka921 0699d6f
Finished including Hannah's review:
joka921 c5c3bec
Changes from Hannah's second Review.
joka921 b5cd717
Changes from Hannah's second Review.
joka921 d74095a
The ConcurrentCacheTest now works deterministically, even on a single…
joka921 460f0e5
Last Renames from Hannah's Review.
joka921 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,86 +55,61 @@ shared_ptr<const ResultTable> Operation::getResult(bool isRoot) { | |
const bool pinChildIndexScanSizes = _executionContext->_pinResult && isRoot; | ||
const bool pinResult = | ||
_executionContext->_pinSubtrees || pinChildIndexScanSizes; | ||
LOG(TRACE) << "Check cache for Operation result" << endl; | ||
LOG(TRACE) << "Using key: \n" << cacheKey << endl; | ||
auto [newResult, existingResult] = | ||
(pinResult) | ||
? cache.tryEmplacePinned(cacheKey, _executionContext->getAllocator()) | ||
: cache.tryEmplace(cacheKey, _executionContext->getAllocator()); | ||
|
||
// When we pin a final result only, we also need to remember the sizes of all | ||
// involved IndexScans with two bound columns. If we don't do this, the query | ||
// planner will otherwise trigger their computation even if it is uneeded | ||
// because the final result can be found in the cache. | ||
if (pinChildIndexScanSizes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename variable to pinFinalResultButNotSubtrees |
||
auto lock = getExecutionContext()->getPinnedSizes().wlock(); | ||
forAllDescendants([&lock](QueryExecutionTree* child) { | ||
if (child->getType() == QueryExecutionTree::OperationType::SCAN) { | ||
if (child->getType() == QueryExecutionTree::OperationType::SCAN && | ||
child->getResultWidth() == 1) { | ||
(*lock)[child->getRootOperation()->asString()] = | ||
child->getSizeEstimate(); | ||
} | ||
}); | ||
} | ||
|
||
if (newResult) { | ||
LOG(TRACE) << "Not in the cache, need to compute result" << endl; | ||
LOG(DEBUG) << "Available memory (in MB) before operation: " | ||
<< (_executionContext->getAllocator().numFreeBytes() >> 20) | ||
<< std::endl; | ||
// Passing the raw pointer here is ok as the result shared_ptr remains | ||
// in scope | ||
try { | ||
computeResult(newResult->_resTable.get()); | ||
} catch (const ad_semsearch::AbortException& e) { | ||
// A child Operation was aborted, abort this Operation | ||
// as well. The child already printed | ||
abort(newResult, false); | ||
// Continue unwinding the stack | ||
throw; | ||
} catch (const std::exception& e) { | ||
// We are in the innermost level of the exception, so print | ||
abort(newResult, true); | ||
// Rethrow as QUERY_ABORTED allowing us to print the Operation | ||
// only at innermost failure of a recursive call | ||
throw ad_semsearch::AbortException(e); | ||
} catch (...) { | ||
// We are in the innermost level of the exception, so print | ||
abort(newResult, true); | ||
LOG(ERROR) << "WEIRD_EXCEPTION not inheriting from std::exception" | ||
<< endl; | ||
// Rethrow as QUERY_ABORTED allowing us to print the Operation | ||
// only at innermost failure of a recursive call | ||
throw ad_semsearch::AbortException("WEIRD_EXCEPTION"); | ||
} | ||
timer.stop(); | ||
_runtimeInfo.setRows(newResult->_resTable->size()); | ||
_runtimeInfo.setCols(getResultWidth()); | ||
_runtimeInfo.setDescriptor(getDescriptor()); | ||
_runtimeInfo.setColumnNames(getVariableColumns()); | ||
try { | ||
auto computeLambda = [this] { | ||
CacheValue val(getExecutionContext()->getAllocator()); | ||
computeResult(val._resultTable.get()); | ||
return val; | ||
}; | ||
|
||
_runtimeInfo.setTime(timer.msecs()); | ||
_runtimeInfo.setWasCached(false); | ||
// cache the runtime information for the execution as well | ||
newResult->_runtimeInfo = _runtimeInfo; | ||
// Only now we can let other threads access the result | ||
// and runtime information | ||
newResult->_resTable->finish(); | ||
return newResult->_resTable; | ||
} | ||
auto result = (pinResult) ? cache.computeOncePinned(cacheKey, computeLambda) | ||
: cache.computeOnce(cacheKey, computeLambda); | ||
|
||
existingResult->_resTable->awaitFinished(); | ||
if (existingResult->_resTable->status() == ResultTable::ABORTED) { | ||
LOG(ERROR) << "Operation aborted while awaiting result" << endl; | ||
AD_THROW(ad_semsearch::Exception::BAD_QUERY, | ||
"Operation aborted while awaiting result"); | ||
timer.stop(); | ||
createRuntimeInformation(result, timer.msecs()); | ||
return result._resultPointer->_resultTable; | ||
} catch (const ad_semsearch::AbortException& e) { | ||
// A child Operation was aborted, do not print the information again. | ||
throw; | ||
} catch (const ad_utility::WaitedForResultWhichThenFailedException& e) { | ||
LOG(ERROR) << "Waited for a result from another thread which then failed" | ||
<< endl; | ||
LOG(ERROR) << asString(); | ||
throw ad_semsearch::AbortException(e); | ||
} catch (const std::exception& e) { | ||
// We are in the innermost level of the exception, so print | ||
LOG(ERROR) << "Aborted Operation:" << endl; | ||
LOG(ERROR) << asString() << endl; | ||
LOG(ERROR) << e.what() << endl; | ||
// Rethrow as QUERY_ABORTED allowing us to print the Operation | ||
// only at innermost failure of a recursive call | ||
throw ad_semsearch::AbortException(e); | ||
} catch (...) { | ||
// We are in the innermost level of the exception, so print | ||
LOG(ERROR) << "Aborted Operation:" << endl; | ||
LOG(ERROR) << asString() << endl; | ||
LOG(ERROR) | ||
<< "Unexpected exception that is not a subclass of std::exception" | ||
<< endl; | ||
// Rethrow as QUERY_ABORTED allowing us to print the Operation | ||
// only at innermost failure of a recursive call | ||
throw ad_semsearch::AbortException( | ||
"Unexpected expection that is not a subclass of std::exception"); | ||
} | ||
timer.stop(); | ||
_runtimeInfo = existingResult->_runtimeInfo; | ||
// We need to update column names and descriptor as we may have cached with | ||
// different variable names | ||
_runtimeInfo.setDescriptor(getDescriptor()); | ||
_runtimeInfo.setColumnNames(getVariableColumns()); | ||
_runtimeInfo.setTime(timer.msecs()); | ||
_runtimeInfo.setWasCached(true); | ||
_runtimeInfo.addDetail("original_total_time", | ||
existingResult->_runtimeInfo.getTime()); | ||
_runtimeInfo.addDetail("original_operation_time", | ||
existingResult->_runtimeInfo.getOperationTime()); | ||
return existingResult->_resTable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// When we pin the final result but no subtrees, we need to remember the sizes of all involved index scans that have only one free variable. Note that these index scans are executed already during query planning because they have to be executed anyway, for any query plan. If we don't remember these sizes here, future queries that take the result from the cache would redo these index scans. Note that we do not need to remember the multiplicity (and distinctness) because the multiplicity for an index scan with a single free variable is always 1.