Example #1
0
  @Override
  public GetResult get(byte[] key) throws IOException {
    ensureNotClosed();
    Preconditions.checkArgument(key != null && key.length > 0, "Key is empty");
    Preconditions.checkArgument(this.getAppendedSize() >= 1, "the map table is empty");
    GetResult result = new GetResult();

    // leverage bloom filter for guarded condition
    if (!this.bloomFilter.mightContain(key)) return result;

    IMapEntry mapEntry = this.binarySearch(key);
    if (mapEntry == null) return result;
    else {
      if (mapEntry.isCompressed()) {
        result.setValue(Snappy.uncompress(mapEntry.getValue()));
      } else {
        result.setValue(mapEntry.getValue());
      }
      if (mapEntry.isDeleted()) {
        result.setDeleted(true);
        return result;
      }
      if (mapEntry.isExpired()) {
        result.setExpired(true);
        return result;
      }
      // hint for locality
      result.setLevel(this.getLevel());
      result.setTimeToLive(mapEntry.getTimeToLive());
      result.setCreatedTime(mapEntry.getCreatedTime());

      return result;
    }
  }