Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.TableDescriptor


  @Test
  public void testCreateAndUpdate() throws IOException {
    Path testdir = UTIL.getDataTestDir("testCreateAndUpdate");
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testCreate"));
    TableDescriptor td = new TableDescriptor(htd, TableState.State.ENABLED);
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, testdir);
    assertTrue(fstd.createTableDescriptor(td));
    assertFalse(fstd.createTableDescriptor(td));
    FileStatus [] statuses = fs.listStatus(testdir);
View Full Code Here


  @Test
  public void testSequenceIdAdvancesOnTableInfo() throws IOException {
    Path testdir = UTIL.getDataTestDir("testSequenceidAdvancesOnTableInfo");
    HTableDescriptor htd = new HTableDescriptor(
        TableName.valueOf("testSequenceidAdvancesOnTableInfo"));
    TableDescriptor td = new TableDescriptor(htd);
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, testdir);
    Path p0 = fstd.updateTableDescriptor(td);
    int i0 = FSTableDescriptors.getTableInfoSequenceId(p0);
    Path p1 = fstd.updateTableDescriptor(td);
    // Assert we cleaned up the old file.
    assertTrue(!fs.exists(p0));
    int i1 = FSTableDescriptors.getTableInfoSequenceId(p1);
    assertTrue(i1 == i0 + 1);
    Path p2 = fstd.updateTableDescriptor(td);
    // Assert we cleaned up the old file.
    assertTrue(!fs.exists(p1));
    int i2 = FSTableDescriptors.getTableInfoSequenceId(p2);
    assertTrue(i2 == i1 + 1);
    td = new TableDescriptor(htd, TableState.State.DISABLED);
    Path p3 = fstd.updateTableDescriptor(td);
    // Assert we cleaned up the old file.
    assertTrue(!fs.exists(p2));
    int i3 = FSTableDescriptors.getTableInfoSequenceId(p3);
    assertTrue(i3 == i2 + 1);
    TableDescriptor descriptor = fstd.getDescriptor(htd.getTableName());
    assertEquals(descriptor, td);
  }
View Full Code Here

  @Test public void testReadingHTDFromFS() throws IOException {
    final String name = "testReadingHTDFromFS";
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
    TableDescriptor td = new TableDescriptor(htd, TableState.State.ENABLED);
    Path rootdir = UTIL.getDataTestDir(name);
    FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
    fstd.createTableDescriptor(td);
    TableDescriptor td2 =
      FSTableDescriptors.getTableDescriptorFromFs(fs, rootdir, htd.getTableName());
    assertTrue(td.equals(td2));
  }
View Full Code Here

    final String name = "testReadingOldHTDFromFS";
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    Path rootdir = UTIL.getDataTestDir(name);
    FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
    TableDescriptor td = new TableDescriptor(htd, TableState.State.ENABLED);
    Path descriptorFile = fstd.updateTableDescriptor(td);
    try (FSDataOutputStream out = fs.create(descriptorFile, true)) {
      out.write(htd.toByteArray());
    }
    FSTableDescriptors fstd2 = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
    TableDescriptor td2 = fstd2.getDescriptor(htd.getTableName());
    assertEquals(td, td2);
    FileStatus descriptorFile2 =
        FSTableDescriptors.getTableInfoPath(fs, fstd2.getTableDir(htd.getTableName()));
    byte[] buffer = td.toByteArray();
    try (FSDataInputStream in = fs.open(descriptorFile2.getPath())) {
      in.readFully(buffer);
    }
    TableDescriptor td3 = TableDescriptor.parseFrom(buffer);
    assertEquals(td, td3);
  }
View Full Code Here

      }
    };
    final int count = 10;
    // Write out table infos.
    for (int i = 0; i < count; i++) {
      TableDescriptor htd = new TableDescriptor(new HTableDescriptor(name + i),
          TableState.State.ENABLED);
      htds.createTableDescriptor(htd);
    }

    for (int i = 0; i < count; i++) {
      assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
    }
    for (int i = 0; i < count; i++) {
      assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
    }
    // Update the table infos
    for (int i = 0; i < count; i++) {
      HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name + i));
      htd.addFamily(new HColumnDescriptor("" + i));
      htds.updateTableDescriptor(new TableDescriptor(htd));
    }
    // Wait a while so mod time we write is for sure different.
    Thread.sleep(100);
    for (int i = 0; i < count; i++) {
      assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
View Full Code Here

    }
    // Update the table infos
    for (int i = 0; i < count; i++) {
      HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name + i));
      htd.addFamily(new HColumnDescriptor("" + i));
      htds.updateTableDescriptor(new TableDescriptor(htd));
    }
    for (int i = 0; i < count; i++) {
      assertNotNull("Expected HTD, got null instead", htds.get(TableName.valueOf(name + i)));
      assertTrue("Column Family " + i + " missing",
                 htds.get(TableName.valueOf(name + i)).hasFamily(Bytes.toBytes("" + i)));
View Full Code Here

  @Test
  public void testCreateTableDescriptorUpdatesIfExistsAlready() throws IOException {
    Path testdir = UTIL.getDataTestDir("testCreateTableDescriptorUpdatesIfThereExistsAlready");
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(
        "testCreateTableDescriptorUpdatesIfThereExistsAlready"));
    TableDescriptor td = new TableDescriptor(htd, TableState.State.ENABLED);
    FileSystem fs = FileSystem.get(UTIL.getConfiguration());
    FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, testdir);
    assertTrue(fstd.createTableDescriptor(td));
    assertFalse(fstd.createTableDescriptor(td));
    htd.setValue(Bytes.toBytes("mykey"), Bytes.toBytes("myValue"));
View Full Code Here

    super.setUp();
    try {
      // Create meta region
      createMetaRegion();
      new FSTableDescriptors(this.conf, this.fs, testDir).createTableDescriptor(
          new TableDescriptor(this.desc));
      /*
       * Create the regions we will merge
       */
      for (int i = 0; i < sourceRegions.length; i++) {
        regions[i] =
View Full Code Here

   * @param newState new state
   * @throws IOException
   */
  public void setTableState(TableName tableName, TableState.State newState) throws IOException {
    synchronized (tableStates) {
      TableDescriptor descriptor = readDescriptor(tableName);
      if (descriptor == null) {
        throw new TableNotFoundException(tableName);
      }
      if (descriptor.getTableState() != newState) {
        writeDescriptor(
            new TableDescriptor(descriptor.getHTableDescriptor(), newState));
      }
    }
  }
View Full Code Here

  public boolean setTableStateIfInStates(TableName tableName,
                                         TableState.State newState,
                                         TableState.State... states)
          throws IOException {
    synchronized (tableStates) {
      TableDescriptor descriptor = readDescriptor(tableName);
      if (descriptor == null) {
        throw new TableNotFoundException(tableName);
      }
      if (TableState.isInStates(descriptor.getTableState(), states)) {
        writeDescriptor(
            new TableDescriptor(descriptor.getHTableDescriptor(), newState));
        return true;
      } else {
        return false;
      }
    }
View Full Code Here

TOP

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

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.