@Override public int size() throws IOException, AlluxioException { int totalSize = 0; // TODO(cc): Put size into PartitionInfo. for (PartitionInfo partition : mPartitions) { KeyValuePartitionReader partitionReader = KeyValuePartitionReader.Factory.create(partition.getBlockId()); totalSize += partitionReader.size(); partitionReader.close(); } return totalSize; }
@Override public ByteBuffer get(ByteBuffer key) throws IOException, AlluxioException { Preconditions.checkNotNull(key); // TODO(binfan): improve the inefficient for-loop to binary search. for (PartitionInfo partition : mPartitions) { // NOTE: keyStart and keyLimit are both inclusive if (key.compareTo(partition.bufferForKeyStart()) >= 0 && key.compareTo(partition.bufferForKeyLimit()) <= 0) { long blockId = partition.getBlockId(); KeyValuePartitionReader reader = KeyValuePartitionReader.Factory.create(blockId); try { ByteBuffer value = reader.get(key); return value; } finally { reader.close(); } } } return null; }