private Value InternalGet(Key lookupKey) {
Value output = Value.Empty;
// Capture copy of the rotated table if there is one
var rotatedMemTable = _rotatedJournaledMemTable;
// somtimes on shutdown this is null
if (_currentJournaledMemTable == null || _manifest == null)
return Value.Empty;
// First check the current memtable
if (_currentJournaledMemTable.Lookup(lookupKey, out output)) {
return output;
}
// Check the table in rotation
if (rotatedMemTable != null) {
if (rotatedMemTable.Lookup(lookupKey, out output)) {
return output;
}
}
// Now check the files on disk
using (var manifest = _manifest.GetLatestManifest()) {
// Must check all pages on level 0
var zeroPages = manifest.GetPagesAtLevel(0).OrderByDescending((page) => page.Version);
foreach (var page in zeroPages) {
if (SortedBlockTable.Lookup(_manifest.BaseFileName, page.Level, page.Version, _cache, lookupKey, out output, _exceptionHandling, _manifest.Logger)) {
return output;
}
}
// If not found, must check pages on the higher levels, but we can use the page index to make the search quicker
for (int level = 1; level < manifest.NumLevels; level++) {
var page = manifest.FindPageForKey(level, lookupKey);
if (page != null && SortedBlockTable.Lookup(_manifest.BaseFileName, page.Level, page.Version, _cache, lookupKey, out output, _exceptionHandling, _manifest.Logger)) {
return output;
}
}
}
// OK, not found anywhere, return null
return Value.Empty;
}