Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HStoreKey


    // Now test reading from the top.
    HalfMapFileReader top = new HalfMapFileReader(this.fs, p.toString(),
      this.conf, Reference.Range.top, midkey, null);
    ImmutableBytesWritable val = new ImmutableBytesWritable();
    final String startRowPrefix = "zy";
    HStoreKey key = new HStoreKey(startRowPrefix);
    WritableComparable closest = top.getClosest(key, val);
    assertTrue(closest.toString().startsWith(startRowPrefix));
    int count = 0;
    for (boolean first = true; top.next(key, val); count++) {
      if (first) {
        assertTrue(key.toString().compareTo(startRowPrefix) > 0);
      }
      LOG.info(key.toString());
    }
    assertTrue(count > 0);
  }
View Full Code Here


      HStoreKey.class, ImmutableBytesWritable.class);
    try {
      for (char d = FIRST_CHAR; d <= LAST_CHAR; d++) {
        byte[] b = new byte[] {(byte)d};
        byte [] t = Bytes.toBytes(new String(b, HConstants.UTF8_ENCODING));
        writer.append(new HStoreKey(t, t, System.currentTimeMillis()),
            new ImmutableBytesWritable(t));
      }
    } finally {
      writer.close();
    }
View Full Code Here

    try {
      for (char d = FIRST_CHAR; d <= LAST_CHAR; d++) {
        for (char e = FIRST_CHAR; e <= LAST_CHAR; e++) {
          byte[] b = new byte[] { (byte) d, (byte) e };
          byte [] t = Bytes.toBytes(new String(b, HConstants.UTF8_ENCODING));
          writer.append(new HStoreKey(t, t, System.currentTimeMillis()),
            new ImmutableBytesWritable(t));
        }
      }
    } finally {
      writer.close();
View Full Code Here

    writeStoreFile(writer);
    MapFile.Reader reader = hsf.getReader(this.fs, false, false);
    // Split on a row, not in middle of row.  Midkey returned by reader
    // may be in middle of row.  Create new one with empty column and
    // timestamp.
    HStoreKey midkey = new HStoreKey(((HStoreKey)reader.midKey()).getRow());
    HStoreKey hsk = new HStoreKey();
    reader.finalKey(hsk);
    byte [] finalKey = hsk.getRow();
    // Make a reference for the bottom half of the just written file.
    Reference reference =
      new Reference(hsf.getEncodedRegionName(), hsf.getFileId(),
          midkey, Reference.Range.top);
    HStoreFile refHsf = new HStoreFile(this.conf, this.fs,
        new Path(DIR, getName()),
        HRegionInfo.FIRST_META_REGIONINFO,
        hsf.getColFamily(), 456, reference);
    // Assert that reference files are written and that we can write and
    // read the info reference file at least.
    refHsf.writeReferenceFiles(this.fs);
    assertTrue(this.fs.exists(refHsf.getMapFilePath()));
    assertTrue(this.fs.exists(refHsf.getInfoFilePath()));
    Reference otherReference =
      HStoreFile.readSplitInfo(refHsf.getInfoFilePath(), this.fs);
    assertEquals(reference.getEncodedRegionName(),
        otherReference.getEncodedRegionName());
    assertEquals(reference.getFileId(),
        otherReference.getFileId());
    assertEquals(reference.getMidkey().toString(),
        otherReference.getMidkey().toString());
    // Now confirm that I can read from the reference and that it only gets
    // keys from top half of the file.
    MapFile.Reader halfReader = refHsf.getReader(this.fs, false, false);
    HStoreKey key = new HStoreKey();
    ImmutableBytesWritable value = new ImmutableBytesWritable();
    boolean first = true;
    while(halfReader.next(key, value)) {
      if (first) {
        assertTrue(Bytes.equals(key.getRow(), midkey.getRow()));
        first = false;
      }
    }
    assertTrue(Bytes.equals(key.getRow(), finalKey));
  }
View Full Code Here

  public void testSmallHalfMapFile() throws Exception {
    Path p = writeSmallMapFile(getName());
    // I know keys are a-z.  Let the midkey we want to use be 'd'.  See if
    // HalfMapFiles work even if size of file is < than default MapFile
    // interval.
    checkHalfMapFile(p, new HStoreKey("d"));
  }
View Full Code Here

  }
 
  private WritableComparable getMidkey(final Path p) throws IOException {
    MapFile.Reader reader =
      new MapFile.Reader(this.fs, p.toString(), this.conf);
    HStoreKey key = new HStoreKey();
    ImmutableBytesWritable value = new ImmutableBytesWritable();
    reader.next(key, value);
    String firstKey = key.toString();
    WritableComparable midkey = reader.midKey();
    reader.finalKey(key);
    LOG.info("First key " + firstKey + ", midkey " + midkey.toString()
        + ", last key " + key.toString());
    reader.close();
    return midkey;
  }
View Full Code Here

 
  private void checkHalfMapFile(final Path p, WritableComparable midkey)
  throws IOException {
    MapFile.Reader top = null;
    MapFile.Reader bottom = null;
    HStoreKey key = new HStoreKey();
    ImmutableBytesWritable value = new ImmutableBytesWritable();
    String previous = null;
    try {
      // Now make two HalfMapFiles and assert they can read the full backing
      // file, one from the top and the other from the bottom.
      // Test bottom half first.
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
      boolean first = true;
      while (bottom.next(key, value)) {
        previous = key.toString();
        if (first) {
          first = false;
          LOG.info("First in bottom: " + previous);
        }
        assertTrue(key.compareTo((HStoreKey)midkey) < 0);
      }
      if (previous != null) {
        LOG.info("Last in bottom: " + previous.toString());
      }
      // Now test reading from the top.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, midkey, null);
      first = true;
      while (top.next(key, value)) {
        assertTrue(key.compareTo((HStoreKey)midkey) >= 0);
        if (first) {
          first = false;
          LOG.info("First in top: " + key.toString());
        }
      }
      LOG.info("Last in top: " + key.toString());

      // Next test using a midkey that does not exist in the file.
      // First, do a key that is < than first key. Ensure splits behave
      // properly.
      WritableComparable badkey = new HStoreKey("   ");
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, badkey, null);
      // When badkey is < than the bottom, should return no values.
      assertFalse(bottom.next(key, value));
      // Now read from the top.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, badkey, null);
      first = true;
      while (top.next(key, value)) {
        assertTrue(key.compareTo((HStoreKey)badkey) >= 0);
        if (first) {
          first = false;
          LOG.info("First top when key < bottom: " + key.toString());
          String tmp = Bytes.toString(key.getRow());
          for (int i = 0; i < tmp.length(); i++) {
            assertTrue(tmp.charAt(i) == 'a');
          }
        }
      }
      LOG.info("Last top when key < bottom: " + key.toString());
      String tmp = Bytes.toString(key.getRow());
      for (int i = 0; i < tmp.length(); i++) {
        assertTrue(tmp.charAt(i) == 'z');
      }

      // Test when badkey is > than last key in file ('||' > 'zz').
      badkey = new HStoreKey("|||");
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, badkey, null);
      first = true;
      while (bottom.next(key, value)) {
        if (first) {
View Full Code Here

   * @throws Exception
   */
  public void testOutOfRangeMidkeyHalfMapFile() throws Exception {
    MapFile.Reader top = null;
    MapFile.Reader bottom = null;
    HStoreKey key = new HStoreKey();
    ImmutableBytesWritable value = new ImmutableBytesWritable();
    Path p = writeMapFile(getName());
    try {
      try {
        // Test using a midkey that does not exist in the file.
        // First, do a key that is < than first key.  Ensure splits behave
        // properly.
        HStoreKey midkey = new HStoreKey("   ");
        bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
        // When midkey is < than the bottom, should return no values.
        assertFalse(bottom.next(key, value));
        // Now read from the top.
        top = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.top, midkey, null);
        boolean first = true;
        while (top.next(key, value)) {
          assertTrue(key.compareTo(midkey) >= 0);
          if (first) {
            first = false;
            LOG.info("First top when key < bottom: " + key.toString());
            assertEquals("aa", Bytes.toString(key.getRow()));
          }
        }
        LOG.info("Last top when key < bottom: " + key.toString());
        assertEquals("zz", Bytes.toString(key.getRow()));
       
        // Test when midkey is > than last key in file ('||' > 'zz').
        midkey = new HStoreKey("|||");
        bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
        first = true;
        while (bottom.next(key, value)) {
          if (first) {
View Full Code Here

    int count = 0;
    boolean containsStartRow = false;
    for (MapFile.Reader reader: this.r.stores.
        get(Bytes.mapKey(COLUMN_FAMILY_TEXT_MINUS_COLON)).getReaders()) {
      reader.reset();
      HStoreKey key = new HStoreKey();
      ImmutableBytesWritable val = new ImmutableBytesWritable();
      while(reader.next(key, val)) {
        if (Bytes.equals(key.getRow(), STARTROW)) {
          containsStartRow = true;
          count++;
        } else {
          // After major compaction, should be none of these rows in compacted
          // file.
          assertFalse(Bytes.equals(key.getRow(), secondRowBytes));
        }
      }
    }
    assertTrue(containsStartRow);
    assertTrue(count == 3);
View Full Code Here

  private int count() throws IOException {
    int count = 0;
    for (MapFile.Reader reader: this.r.stores.
        get(Bytes.mapKey(COLUMN_FAMILY_TEXT_MINUS_COLON)).getReaders()) {
      reader.reset();
      HStoreKey key = new HStoreKey();
      ImmutableBytesWritable val = new ImmutableBytesWritable();
      while(reader.next(key, val)) {
        count++;
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HStoreKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.