Exemplo n.º 1
0
    public Entry<InternalKey, Slice> next(int bucket, long minSeq) {
      if (hasNext()) {
        // parse the key in the block
        Entry<InternalKey, Slice> entry = iterator.next();
        InternalKey internalKey = entry.getKey();
        Preconditions.checkState(
            internalKey != null, "Corrupt key for %s", internalKey.getUserKey().toString(UTF_8));

        if (internalKey.bucket() == bucket && internalKey.getSequenceNumber() > minSeq) {
          return entry;
        }
      }
      return null;
    }
Exemplo n.º 2
0
  private int readWriteBatch(int bucket, SliceInput record, int updateSize, Entrys entries)
      throws IOException {
    List<Entry<Slice, Slice>> list = Lists.newArrayListWithCapacity(updateSize);
    int count = 0;
    while (record.isReadable()) {
      count++;
      ValueType valueType = ValueType.getValueTypeByPersistentId(record.readByte());
      if (valueType == VALUE) {
        Slice key = readLengthPrefixedBytes(record);
        Slice value = readLengthPrefixedBytes(record);
        list.add(new BlockEntry(key, value));
      } else if (valueType == DELETION) {
        Slice key = readLengthPrefixedBytes(record);
        list.add(new BlockEntry(key, Slices.EMPTY_SLICE));
      } else {
        throw new IllegalStateException("Unexpected value type " + valueType);
      }
    }

    if (count != updateSize) {
      throw new IOException(
          String.format(
              "Expected %d entries in log record but found %s entries", updateSize, entries));
    }

    int available = 0;
    for (Entry<Slice, Slice> e : list) {
      InternalKey iKey =
          new InternalKey(e.getKey(), 0, e.getValue().length() != 0 ? VALUE : DELETION);
      if (bucket == iKey.bucket()) {
        entries.add(e);
        available++;
      }
    }
    return available;
  }