Пример #1
0
 @Test
 public void testDeleteTable() throws Exception {
   String namespace = prefix + "_dummy";
   NamespaceDescriptor nspDesc =
       NamespaceDescriptor.create(namespace)
           .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "100")
           .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "3")
           .build();
   ADMIN.createNamespace(nspDesc);
   assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(namespace));
   NamespaceTableAndRegionInfo stateInfo = getNamespaceState(nspDesc.getName());
   assertNotNull("Namespace state found null for " + namespace, stateInfo);
   HTableDescriptor tableDescOne =
       new HTableDescriptor(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table1"));
   HTableDescriptor tableDescTwo =
       new HTableDescriptor(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table2"));
   ADMIN.createTable(tableDescOne);
   ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5);
   stateInfo = getNamespaceState(nspDesc.getName());
   assertNotNull("Namespace state found to be null.", stateInfo);
   assertEquals(2, stateInfo.getTables().size());
   assertEquals(5, stateInfo.getRegionCountOfTable(tableDescTwo.getTableName()));
   assertEquals(6, stateInfo.getRegionCount());
   ADMIN.disableTable(tableDescOne.getTableName());
   deleteTable(tableDescOne.getTableName());
   stateInfo = getNamespaceState(nspDesc.getName());
   assertNotNull("Namespace state found to be null.", stateInfo);
   assertEquals(5, stateInfo.getRegionCount());
   assertEquals(1, stateInfo.getTables().size());
   ADMIN.disableTable(tableDescTwo.getTableName());
   deleteTable(tableDescTwo.getTableName());
   ADMIN.deleteNamespace(namespace);
   stateInfo = getNamespaceState(namespace);
   assertNull("Namespace state not found to be null.", stateInfo);
 }
Пример #2
0
  private void ensureColumnFamilyExists(String tableName, String columnFamily)
      throws StorageException {
    HBaseAdmin adm = getAdminInterface();
    HTableDescriptor desc = ensureTableExists(tableName);

    Preconditions.checkNotNull(desc);

    HColumnDescriptor cf = desc.getFamily(columnFamily.getBytes());

    // Create our column family, if necessary
    if (cf == null) {
      try {
        adm.disableTable(tableName);
        desc.addFamily(
            new HColumnDescriptor(columnFamily).setCompressionType(Compression.Algorithm.GZ));
        adm.modifyTable(tableName.getBytes(), desc);

        try {
          logger.debug(
              "Added HBase ColumnFamily {}, waiting for 1 sec. to propogate.", columnFamily);
          Thread.sleep(1000L);
        } catch (InterruptedException ie) {
          throw new TemporaryStorageException(ie);
        }

        adm.enableTable(tableName);
      } catch (TableNotFoundException ee) {
        logger.error("TableNotFoundException", ee);
        throw new PermanentStorageException(ee);
      } catch (org.apache.hadoop.hbase.TableExistsException ee) {
        logger.debug("Swallowing exception {}", ee);
      } catch (IOException ee) {
        throw new TemporaryStorageException(ee);
      }
    } else { // check if compression was enabled, if not - enable it
      if (cf.getCompressionType() == null
          || cf.getCompressionType() == Compression.Algorithm.NONE) {
        try {
          adm.disableTable(tableName);

          adm.modifyColumn(tableName, cf.setCompressionType(Compression.Algorithm.GZ));

          adm.enableTable(tableName);
        } catch (IOException e) {
          throw new TemporaryStorageException(e);
        }
      }
    }
  }
Пример #3
0
 /** alter用于修改表明。需要新旧两个表明作为参数。 */
 @Override
 public Builder alter() {
   if (type == 2) {
     // 修改表名。snapshot
     final String snapshotName = "snapShotName";
     try {
       if (!hBaseAdmin.tableExists(tableName)
           || tableName == null
           || tableName.trim().equals("")) {
         Log.error("=== LiMingji Debug Info === TableName is invalid");
         return this;
       }
       if (newTableName == null || newTableName.trim().equals("")) {
         Log.error("=== LiMingji error Info === newTableName is invalid");
         return this;
       }
       if (!hBaseAdmin.isTableDisabled(tableName)) hBaseAdmin.disableTable(tableName);
       // 删除可能存在的snapShotName
       try {
         hBaseAdmin.deleteSnapshot(snapshotName);
       } catch (IOException e) {
         // Do nothing.
       }
       hBaseAdmin.snapshot(snapshotName, tableName);
       hBaseAdmin.cloneSnapshot(snapshotName, newTableName);
       hBaseAdmin.deleteSnapshot(snapshotName);
       hBaseAdmin.deleteTable(tableName);
     } catch (InterruptedException e) {
       Log.info("=== LiMingji error Info === alter@DTL interrupt");
     } catch (IOException e) {
       Log.error("=== LiMingji error Info === alter@DTL IOException");
     }
   }
   return this;
 }
Пример #4
0
 /**
  * Drops table in HBase when it exists.
  *
  * @param conf
  * @throws IOException
  */
 public void dropTable() throws IOException {
   if (exists()) {
     HBaseAdmin admin = new HBaseAdmin(getConfiguration());
     admin.disableTable(getStringName());
     admin.deleteTable(getStringName());
   }
 }
 /**
  * @param rawAttributeName is the attribute name viewed by applications, it allows multiple
  *     values. For example, secondaryIndex in secondaryIndex$1 and coprocessor in corpcessor$2
  * @param indexOfAttribute is of the same raw attribute name, for example 2 in secondary$2
  */
 static void updateTableAttribute(
     Configuration conf,
     byte[] tableName,
     String rawAttributeName,
     int indexOfAttribute,
     boolean ifUpdateorRemove,
     String value)
     throws IOException {
   HBaseAdmin admin = new HBaseAdmin(conf);
   HTableDescriptor desc = admin.getTableDescriptor(tableName);
   admin.disableTable(tableName);
   //        System.out.println("TTDEBUG: disable table " + Bytes.toString(tableName));
   String coprocessorKey = rawAttributeName + indexOfAttribute;
   if (!ifUpdateorRemove) {
     desc.remove(Bytes.toBytes(coprocessorKey));
   } else {
     desc.setValue(coprocessorKey, value);
   }
   admin.modifyTable(tableName, desc);
   //        System.out.println("TTDEBUG: modify table " + Bytes.toString(tableName));
   admin.enableTable(tableName);
   //        System.out.println("TTDEBUG: enable table " + Bytes.toString(tableName));
   HTableDescriptor descNew = admin.getTableDescriptor(tableName);
   // modify table is asynchronous, has to loop over to check
   while (!desc.equals(descNew)) {
     System.err.println(
         "TTDEBUG: waiting for descriptor to change: from " + descNew + " to " + desc);
     try {
       Thread.sleep(500);
     } catch (InterruptedException ex) {
     }
     descNew = admin.getTableDescriptor(tableName);
   }
 }
Пример #6
0
 /**
  * 删除指定表名
  *
  * @param rowKey
  */
 public void deleteTable(byte[] rowKey) {
   Connection conn = null;
   HBaseAdmin admin = null;
   try {
     conn = ConnectionFactory.createConnection(conf);
     admin = (HBaseAdmin) conn.getAdmin();
     // 在删除一张表前,要使其失效
     admin.disableTable(rowKey);
     admin.deleteTable(rowKey);
     admin.enableTable(rowKey);
   } catch (Exception e) {
     logger.error("HBaseAdmin deleteTable exception, errMsg:{}", e.getMessage());
   } finally {
     try {
       if (null != admin) {
         admin.close();
       }
     } catch (IOException e) {
       logger.error("HBaseAdmin close exception, errMsg:{}", e.getMessage());
     }
     try {
       if (null != conn) {
         conn.close();
       }
     } catch (Exception e) {
       logger.error("Connection close exception, errMsg:{}", e.getMessage());
     }
   }
 }
Пример #7
0
 public void fixInconsistent() throws IOException {
   if (ifFix == true) {
     for (String segFullName : inconsistentHTables) {
       String[] sepNameList = segFullName.split(",");
       HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
       logger.info(
           "Change the host of htable "
               + sepNameList[0]
               + "belonging to cube "
               + sepNameList[1]
               + " from "
               + desc.getValue(IRealizationConstants.HTableTag)
               + " to "
               + dstCfg.getMetadataUrlPrefix());
       hbaseAdmin.disableTable(sepNameList[0]);
       desc.setValue(IRealizationConstants.HTableTag, dstCfg.getMetadataUrlPrefix());
       hbaseAdmin.modifyTable(sepNameList[0], desc);
       hbaseAdmin.enableTable(sepNameList[0]);
     }
   } else {
     logger.info("------ Inconsistent HTables Needed To Be Fixed ------");
     for (String hTable : inconsistentHTables) {
       String[] sepNameList = hTable.split(",");
       logger.info(sepNameList[0] + " belonging to cube " + sepNameList[1]);
     }
     logger.info("----------------------------------------------------");
   }
 }
Пример #8
0
  /**
   * @param table
   * @return
   */
  public boolean createTable(JSONObject table) {

    try {
      String table_name = "";
      if (!table.has(XHBaseConstant.TABLE_DESC_NAME)) return false;

      table_name = (String) table.get(XHBaseConstant.TABLE_DESC_NAME);
      if (table_name.isEmpty()) return false;

      if (admin.tableExists(table_name)) {
        admin.disableTable(table_name);
        admin.deleteTable(table_name);
      }

      HTableDescriptor td = this.createTableDescription(table);
      this.admin.createTable(td);

      return true;

    } catch (Exception e) {
      e.printStackTrace();
    }

    return false;
  }
Пример #9
0
  @Test(timeout = 180000)
  public void testRestoreSnapshot() throws Exception {
    String nsp = prefix + "_testRestoreSnapshot";
    NamespaceDescriptor nspDesc =
        NamespaceDescriptor.create(nsp)
            .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10")
            .build();
    ADMIN.createNamespace(nspDesc);
    assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
    TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
    HTableDescriptor tableDescOne = new HTableDescriptor(tableName1);
    ADMIN.createTable(tableDescOne, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);

    NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
    assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());

    String snapshot = "snapshot_testRestoreSnapshot";
    ADMIN.snapshot(snapshot, tableName1);

    List<HRegionInfo> regions = ADMIN.getTableRegions(tableName1);
    Collections.sort(regions);

    ADMIN.split(tableName1, Bytes.toBytes("JJJ"));
    Thread.sleep(2000);
    assertEquals("Total regions count should be 5.", 5, nstate.getRegionCount());

    ADMIN.disableTable(tableName1);
    ADMIN.restoreSnapshot(snapshot);

    assertEquals("Total regions count should be 4 after restore.", 4, nstate.getRegionCount());

    ADMIN.enableTable(tableName1);
    ADMIN.deleteSnapshot(snapshot);
  }
Пример #10
0
 /** Apply column family options such as Bloom filters, compression, and data block encoding. */
 protected void applyColumnFamilyOptions(byte[] tableName, byte[][] columnFamilies)
     throws IOException {
   HBaseAdmin admin = new HBaseAdmin(conf);
   HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
   LOG.info("Disabling table " + Bytes.toString(tableName));
   admin.disableTable(tableName);
   for (byte[] cf : columnFamilies) {
     HColumnDescriptor columnDesc = tableDesc.getFamily(cf);
     boolean isNewCf = columnDesc == null;
     if (isNewCf) {
       columnDesc = new HColumnDescriptor(cf);
     }
     if (bloomType != null) {
       columnDesc.setBloomFilterType(bloomType);
     }
     if (compressAlgo != null) {
       columnDesc.setCompressionType(compressAlgo);
     }
     if (dataBlockEncodingAlgo != null) {
       columnDesc.setDataBlockEncoding(dataBlockEncodingAlgo);
       columnDesc.setEncodeOnDisk(!encodeInCacheOnly);
     }
     if (inMemoryCF) {
       columnDesc.setInMemory(inMemoryCF);
     }
     if (isNewCf) {
       admin.addColumn(tableName, columnDesc);
     } else {
       admin.modifyColumn(tableName, columnDesc);
     }
   }
   LOG.info("Enabling table " + Bytes.toString(tableName));
   admin.enableTable(tableName);
 }
Пример #11
0
 public static synchronized void dropTableIfExists() throws Exception {
   HBaseAdmin admin = HBaseUtils.getHBaseAdmin();
   if (admin.tableExists(TABLE_NAME)) {
     admin.disableTable(TABLE_NAME);
     admin.deleteTable(TABLE_NAME);
   }
 }
Пример #12
0
  /*
   * 删除表
   *
   * @tableName 表名
   */
  public static void deleteTable(String tableName) throws IOException {

    @SuppressWarnings("resource")
    HBaseAdmin admin = new HBaseAdmin(conf);
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
    System.out.println(tableName + "is deleted!");
  }
Пример #13
0
 protected void dropTable(String tableName) throws IOException {
   if (admin.tableExists(tableName)) {
     try {
       admin.disableTable(tableName);
     } catch (TableNotEnabledException ignored) {
     }
     admin.deleteTable(tableName);
   }
 }
Пример #14
0
 /**
  * delete table in preparation for next test
  *
  * @param tablename
  * @throws IOException
  */
 void deleteTable(HBaseAdmin admin, String tablename) throws IOException {
   try {
     byte[] tbytes = Bytes.toBytes(tablename);
     admin.disableTable(tbytes);
     admin.deleteTable(tbytes);
   } catch (Exception e) {
     // Do nothing.
   }
 }
Пример #15
0
 public static void main(String... args)
     throws IOException, ClassNotFoundException, InterruptedException {
   UserGroupInformation.loginUserFromKeytab("web_dp", "web_dp.keytab");
   Configuration conf = HBaseConfiguration.create();
   HBaseAdmin admin = new HBaseAdmin(conf);
   if (admin.tableExists(QueryDataListener.TN_BYTES_DOMAIN)) {
     admin.disableTable(QueryDataListener.TN_BYTES_DOMAIN);
     admin.deleteTable(QueryDataListener.TN_BYTES_DOMAIN);
   }
   if (admin.tableExists(QueryDataListener.TN_BYTES_URL)) {
     admin.disableTable(QueryDataListener.TN_BYTES_URL);
     admin.deleteTable(QueryDataListener.TN_BYTES_URL);
   }
   if (admin.tableExists(QueryDataListener.TN_BYTES_QUERY)) {
     admin.disableTable(QueryDataListener.TN_BYTES_QUERY);
     admin.deleteTable(QueryDataListener.TN_BYTES_QUERY);
   }
 }
Пример #16
0
 /**
  * 删除表
  *
  * @param tableName 表名
  */
 public void deleteTable(String tableName) {
   try {
     HBaseAdmin admin = new HBaseAdmin(conf);
     admin.disableTable(tableName);
     admin.deleteTable(tableName);
   } catch (Exception e) {
     logger.error("deleteTable failed", e);
   }
 }
Пример #17
0
  /*
   * Create a table and make sure that the table creation fails after adding this table entry into
   * namespace quota cache. Now correct the failure and recreate the table with same name.
   * HBASE-13394
   */
  @Test(timeout = 180000)
  public void testRecreateTableWithSameNameAfterFirstTimeFailure() throws Exception {
    String nsp1 = prefix + "_testRecreateTable";
    NamespaceDescriptor nspDesc =
        NamespaceDescriptor.create(nsp1)
            .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20")
            .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1")
            .build();
    ADMIN.createNamespace(nspDesc);
    final TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1");
    byte[] columnFamily = Bytes.toBytes("info");
    HTableDescriptor tableDescOne = new HTableDescriptor(tableOne);
    tableDescOne.addFamily(new HColumnDescriptor(columnFamily));
    MasterSyncObserver.throwExceptionInPreCreateTableHandler = true;
    try {
      try {
        ADMIN.createTable(tableDescOne);
        fail("Table " + tableOne.toString() + "creation should fail.");
      } catch (Exception exp) {
        LOG.error(exp);
      }
      assertFalse(ADMIN.tableExists(tableOne));

      NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp1);
      assertEquals(
          "First table creation failed in namespace so number of tables in namespace "
              + "should be 0.",
          0,
          nstate.getTables().size());

      MasterSyncObserver.throwExceptionInPreCreateTableHandler = false;
      try {
        ADMIN.createTable(tableDescOne);
      } catch (Exception e) {
        fail("Table " + tableOne.toString() + "creation should succeed.");
        LOG.error(e);
      }
      assertTrue(ADMIN.tableExists(tableOne));
      nstate = getNamespaceState(nsp1);
      assertEquals(
          "First table was created successfully so table size in namespace should " + "be one now.",
          1,
          nstate.getTables().size());
    } finally {
      MasterSyncObserver.throwExceptionInPreCreateTableHandler = false;
      if (ADMIN.tableExists(tableOne)) {
        ADMIN.disableTable(tableOne);
        deleteTable(tableOne);
      }
      ADMIN.deleteNamespace(nsp1);
    }
  }
 private static void deleteTables() {
   if (admin != null) {
     for (TableName tableName : createdTables) {
       try {
         if (admin.tableExists(tableName)) {
           admin.disableTable(tableName);
           admin.deleteTable(tableName);
         }
       } catch (IOException e) {
         assertNull("Exception found deleting the table", e);
       }
     }
   }
 }
 @Test
 public void testTableExists() throws IOException {
   final String name = "testTableExists";
   final byte[] nameBytes = Bytes.toBytes(name);
   assertFalse(MetaReader.tableExists(ct, name));
   UTIL.createTable(nameBytes, HConstants.CATALOG_FAMILY);
   assertTrue(MetaReader.tableExists(ct, name));
   HBaseAdmin admin = UTIL.getHBaseAdmin();
   admin.disableTable(name);
   admin.deleteTable(name);
   assertFalse(MetaReader.tableExists(ct, name));
   assertTrue(MetaReader.tableExists(ct, Bytes.toString(HConstants.META_TABLE_NAME)));
   assertTrue(MetaReader.tableExists(ct, Bytes.toString(HConstants.ROOT_TABLE_NAME)));
 }
Пример #20
0
 @BeforeClass
 public static void doBeforeTestSetup() throws Exception {
   HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin();
   try {
     try {
       admin.disableTable(HBASE_DYNAMIC_COLUMNS_BYTES);
       admin.deleteTable(HBASE_DYNAMIC_COLUMNS_BYTES);
     } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
     }
     ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS);
     initTableValues();
   } finally {
     admin.close();
   }
 }
Пример #21
0
 @After
 public void cleanup() throws Exception, KeeperException {
   for (HTableDescriptor table : ADMIN.listTables()) {
     ADMIN.disableTable(table.getTableName());
     deleteTable(table.getTableName());
   }
   for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) {
     if (ns.getName().startsWith(prefix)) {
       ADMIN.deleteNamespace(ns.getName());
     }
   }
   assertTrue(
       "Quota manager not enabled",
       UTIL.getHBaseCluster().getMaster().getMasterQuotaManager().isQuotaEnabled());
 }
Пример #22
0
 private static void clearHBase(Configuration conf) throws IOException {
   HBaseAdmin admin = new HBaseAdmin(conf);
   if (admin.tableExists(table_bytes)) {
     try {
       admin.disableTable(table_bytes);
     } catch (Exception ex) {
     }
     try {
       admin.deleteTable(table_bytes);
     } catch (Exception ex) {
     }
   }
   HTableDescriptor tdesc = new HTableDescriptor(table_bytes);
   HColumnDescriptor cdesc = new HColumnDescriptor(colfam0_bytes);
   tdesc.addFamily(cdesc);
   admin.createTable(tdesc);
 }
Пример #23
0
  // 创建一张表,通过HBaseAdmin HTableDescriptor来创建
  public static void creat(String tablename, String columnFamily) throws Exception {

    HBaseAdmin admin = new HBaseAdmin(configuration);
    if (admin.tableExists(tablename)) {
      try {
        admin.disableTable(tablename);
        admin.deleteTable(tablename);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    HTableDescriptor tableDesc = new HTableDescriptor(tablename.valueOf(tablename));
    tableDesc.addFamily(new HColumnDescriptor(columnFamily));
    admin.createTable(tableDesc);
    admin.close();
    System.out.println("create table success!");
  }
Пример #24
0
  @Before
  public void before() throws IOException {
    HBaseAdmin admin = new HBaseAdmin(configuration);

    boolean exists = admin.tableExists(TABLE_NAME);
    if (exists) {
      admin.disableTable(TABLE_NAME);
      admin.deleteTable(TABLE_NAME);
    }

    // tworzenie tabeli HBase
    HTableDescriptor table = new HTableDescriptor(TABLE_NAME);
    table.addFamily(new HColumnDescriptor(FAMILY_NAME));
    table.addFamily(new HColumnDescriptor(LoadMovieData.FAMILY_NAME));
    table.addFamily(new HColumnDescriptor(LoadMovieRatingData.FAMILY_NAME));

    admin.createTable(table);
  }
Пример #25
0
 /**
  * Uses SchemaTool to register the required schemas and create the required tables.
  *
  * @param conf The HBaseConfiguration.
  * @param schemaManager The schema manager SchemaTool needs to create the schemas.
  */
 private void registerSchemas(Configuration conf, SchemaManager schemaManager) {
   HBaseAdmin admin;
   try {
     // Construct an HBaseAdmin object (required by schema tool), and delete it
     // if it exists so we start fresh.
     admin = new HBaseAdmin(conf);
     if (admin.tableExists("cdk_example_user_profiles")) {
       admin.disableTable("cdk_example_user_profiles");
       admin.deleteTable("cdk_example_user_profiles");
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   // Use the SchemaTool to create the schemas that are in the example-models
   // directory, and create the table and column families required by those
   // schemas.
   SchemaTool tool = new SchemaTool(admin, schemaManager);
   tool.createOrMigrateSchemaDirectory("classpath:example-models", true);
 }
Пример #26
0
 public static void deleteTableTest(String tableStr) {
   try {
     Configuration conf = HBaseConfiguration.create();
     byte[] tableName = Bytes.toBytes(tableStr);
     if (conf == null) {
       throw new IOException("conf not set.");
     } else {
       HBaseAdmin admin = new HBaseAdmin(conf);
       if (admin.tableExists(tableName)) {
         admin.disableTable(tableName); // 关闭一个表
         admin.deleteTable(tableName); // 删除一个表
       } else {
         throw new IOException("no such table.");
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 @BeforeClass
 public static void doBeforeTestSetup() throws Exception {
   HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin();
   try {
     try {
       admin.disableTable(HBASE_NATIVE_BYTES);
       admin.deleteTable(HBASE_NATIVE_BYTES);
     } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
     }
     HTableDescriptor descriptor = new HTableDescriptor(HBASE_NATIVE_BYTES);
     HColumnDescriptor columnDescriptor = new HColumnDescriptor(FAMILY_NAME);
     columnDescriptor.setKeepDeletedCells(true);
     descriptor.addFamily(columnDescriptor);
     admin.createTable(descriptor, SPLITS);
     initTableValues();
   } finally {
     admin.close();
   }
 }
Пример #28
0
  @Override
  public void setConfigurationProperty(final String key, final String value)
      throws StorageException {
    byte[] name = tableName.getBytes();

    HTableDescriptor desc = ensureTableExists(tableName);

    try {
      HBaseAdmin adm = getAdminInterface();

      adm.disableTable(tableName);

      desc.setValue(key, value);

      adm.modifyTable(name, desc);
      adm.enableTable(tableName);
    } catch (IOException e) {
      throw new PermanentStorageException(e);
    }
  }
Пример #29
0
  public HTable createTable(String tableName, String[] metrics, int[] max_version)
      throws IOException {
    System.out.println("create table for " + tableName);
    try {
      if (admin.tableExists(tableName)) {
        System.out.println(admin.listTables());
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
      }
      HTableDescriptor td = this.createTableDescription(tableName, metrics, max_version);
      System.out.println(tableName + ": <=>table descirption : " + td.toString());
      this.admin.createTable(td);
      // this.admin.createTable(td, ("0-").getBytes(), ("2-"+Long.MAX_VALUE).getBytes(),80);

    } catch (Exception e) {
      e.printStackTrace();
      // log.info(e.fillInStackTrace());
    }
    return new HTable(conf, tableName);
  }
Пример #30
0
  @Test(timeout = 180000)
  public void testRestoreSnapshotQuotaExceed() throws Exception {
    String nsp = prefix + "_testRestoreSnapshotQuotaExceed";
    NamespaceDescriptor nspDesc =
        NamespaceDescriptor.create(nsp)
            .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10")
            .build();
    ADMIN.createNamespace(nspDesc);
    NamespaceDescriptor ndesc = ADMIN.getNamespaceDescriptor(nsp);
    assertNotNull("Namespace descriptor found null.", ndesc);
    TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
    HTableDescriptor tableDescOne = new HTableDescriptor(tableName1);
    ADMIN.createTable(tableDescOne, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);

    NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
    assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());

    String snapshot = "snapshot_testRestoreSnapshotQuotaExceed";
    ADMIN.snapshot(snapshot, tableName1);

    List<HRegionInfo> regions = ADMIN.getTableRegions(tableName1);
    Collections.sort(regions);

    ADMIN.split(tableName1, Bytes.toBytes("JJJ"));
    Thread.sleep(2000);
    assertEquals("Total regions count should be 5.", 5, nstate.getRegionCount());

    ndesc.setConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "2");
    ADMIN.modifyNamespace(ndesc);

    ADMIN.disableTable(tableName1);
    try {
      ADMIN.restoreSnapshot(snapshot);
      fail(
          "Region quota is exceeded so QuotaExceededException should be thrown but HBaseAdmin"
              + " wraps IOException into RestoreSnapshotException");
    } catch (RestoreSnapshotException ignore) {
    }
    ADMIN.enableTable(tableName1);
    ADMIN.deleteSnapshot(snapshot);
  }