/** * Get a key from the spillable data structures This conducts a linear search through all active * pages in the current SpillFile Before doing an actual IO on the page, we check its associated * bloomFilter if the key is contained. False positives are possible but compensated for. */ @Override public byte[] get(Object key) { if (!(key instanceof ImmutableBytesPtr)) { // TODO ... work on type safety } ImmutableBytesPtr ikey = (ImmutableBytesPtr) key; byte[] value = null; int bucketIndex = 0; // Iterate over all pages for (int i = 0; i <= spillFile.getMaxPageId(); i++) { // run in loop in case of false positives in bloom filter bucketIndex = isKeyinPage(ikey, i); if (bucketIndex == -1) { // key not contained in current bloom filter continue; } if (bucketIndex != byteMap.getCurIndex()) { // key contained in page which is not in memory // page it in if (byteMap.getSize() > 0) { // ensure consistency and flush current memory page to disk byteMap.flushBuffer(); } // load page into memory byteMap = MappedByteBufferMap.newMappedByteBufferMap(bucketIndex, thresholdBytes, spillFile); byteMap.pageIn(); } // get KV from current queue value = byteMap.getPagedInElement(ikey); if (value != null) { return value; } } return value; }