Advertisement
Guest User

DeltaEncoder

a guest
Sep 14th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.35 KB | None | 0 0
  1. /**
  2.  * Copyright 2011 The Apache Software Foundation
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  */
  20. package org.apache.hadoop.hbase.io.deltaencoder;
  21.  
  22. import java.io.DataInputStream;
  23. import java.io.IOException;
  24. import java.io.OutputStream;
  25. import java.nio.ByteBuffer;
  26.  
  27. import org.apache.hadoop.io.RawComparator;
  28.  
  29. /**
  30.  * Encoding of KeyValue. It aims to be fast and efficient
  31.  * using assumptions:
  32.  * - the KeyValue are stored sorted by key
  33.  * - we know the structure of KeyValue
  34.  * - the values are iterated always forward from beginning of block
  35.  * - knowledge of Key Value format
  36.  *
  37.  *
  38.  * It is designed to work fast enough to be feasible as in memory compression.
  39.  */
  40. public interface DeltaEncoder {
  41.   /**
  42.    * Compress KeyValues and write them to output buffer.
  43.    * @param writeHere Where to write compressed data.
  44.    * @param rawKeyValues Source of KeyValue for compression.
  45.    * @throws IOException If there is an error in writeHere.
  46.    */
  47.   public void compressKeyValues(OutputStream writeHere, ByteBuffer rawKeyValues)
  48.       throws IOException;
  49.  
  50.   /**
  51.    * Uncompress.
  52.    * @param source Compressed stream of KeyValues.
  53.    * @return Uncompressed block of KeyValues.
  54.    * @throws IOException If there is an error in source.
  55.    */
  56.   public ByteBuffer uncompressKeyValues(DataInputStream source)
  57.           throws IOException;
  58.  
  59.   /**
  60.    * Uncompress.
  61.    * @param source Compressed stream of KeyValues.
  62.    * @param allocateHeaderLength Alloc n bytes for header.
  63.    * @param skipLastBytes Do not copy n last bytes.
  64.    * @return Uncompressed block of KeyValues.
  65.    * @throws IOException If there is an error in source.
  66.    */
  67.   public ByteBuffer uncompressKeyValues(DataInputStream source,
  68.       int allocateHeaderLength, int skipLastBytes)
  69.           throws IOException;
  70.  
  71.   /**
  72.    * Return first key in block. Useful for indexing.
  73.    * @param block encoded block we want index, the position will not change
  74.    * @return First key in block.
  75.    */
  76.   public ByteBuffer getFirstKeyInBlock(ByteBuffer block);
  77.  
  78.   /**
  79.    * Create a HFileBlock seeker which find KeyValues within a block.
  80.    * @param comperator what kind of comparison should be used
  81.    * @return A newly created seeker.
  82.    */
  83.   public DeltaEncoderSeeker createSeeker(RawComparator<byte[]> comperator);
  84.  
  85.   /**
  86.    * An interface which enable to seek while underlying data is encoded.
  87.    *
  88.    * It works on one HFileBlock, but it is reusable. See
  89.    * {@link #setCurrentBuffer(ByteBuffer)}.
  90.    */
  91.   public static interface DeltaEncoderSeeker {
  92.     /**
  93.      * Set on which buffer there will be done seeking.
  94.      * @param buffer Used for seeking.
  95.      */
  96.     public void setCurrentBuffer(ByteBuffer buffer);
  97.    
  98.     /** @return key at current position */
  99.     public ByteBuffer getKey();
  100.     /** @return value at current position */
  101.     public ByteBuffer getValue();
  102.     /** @return key value at current position. */
  103.     public ByteBuffer getKeyValue();
  104.    
  105.     /** Set position to beginning of given block */
  106.     public void rewind();
  107.    
  108.     /**
  109.      * Move to next position
  110.      * @return true on success, false if there is no more positions.
  111.      */
  112.     public boolean next();
  113.    
  114.     /**
  115.      * Move position to the same key (or one before it).
  116.      * @param key Array where is the key.
  117.      * @param offset Key position in array.
  118.      * @param length Key length in array.
  119.      * @param seekBefore find the key before in case of exact match
  120.      * @return 0 on exact match, 1 on inexact match.
  121.      */
  122.     public int blockSeekTo(byte[] key, int offset, int length,
  123.         boolean seekBefore);
  124.   }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement