Search in sources :

Example 6 with Put

use of org.apache.hadoop.hbase.client.Put in project hbase by apache.

the class MetaTableAccessor method updateTableState.

/**
   * Update state of the table in meta.
   * @param connection what we use for update
   * @param state new state
   * @throws IOException
   */
public static void updateTableState(Connection connection, TableState state) throws IOException {
    Put put = makePutFromTableState(state);
    putToMetaTable(connection, put);
    LOG.info("Updated table " + state.getTableName() + " state to " + state.getState() + " in META");
}
Also used : Put(org.apache.hadoop.hbase.client.Put)

Example 7 with Put

use of org.apache.hadoop.hbase.client.Put in project hbase by apache.

the class MetaTableAccessor method updateReplicationPositions.

/**
   * Updates the progress of pushing entries to peer cluster. Skip entry if value is -1.
   * @param connection connection we're using
   * @param peerId the peerId to push
   * @param positions map that saving positions for each region
   * @throws IOException
   */
public static void updateReplicationPositions(Connection connection, String peerId, Map<String, Long> positions) throws IOException {
    List<Put> puts = new ArrayList<>(positions.entrySet().size());
    for (Map.Entry<String, Long> entry : positions.entrySet()) {
        long value = Math.abs(entry.getValue());
        Put put = new Put(Bytes.toBytes(entry.getKey()));
        put.addImmutable(HConstants.REPLICATION_POSITION_FAMILY, Bytes.toBytes(peerId), Bytes.toBytes(value));
        puts.add(put);
    }
    getMetaHTable(connection).put(puts);
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Put(org.apache.hadoop.hbase.client.Put)

Example 8 with Put

use of org.apache.hadoop.hbase.client.Put in project hbase by apache.

the class MetaTableAccessor method makePutFromTableState.

/**
   * Construct PUT for given state
   * @param state new state
   */
public static Put makePutFromTableState(TableState state) {
    long time = EnvironmentEdgeManager.currentTime();
    Put put = new Put(state.getTableName().getName(), time);
    put.addColumn(getTableFamily(), getStateColumn(), state.convert().toByteArray());
    return put;
}
Also used : Put(org.apache.hadoop.hbase.client.Put)

Example 9 with Put

use of org.apache.hadoop.hbase.client.Put in project hbase by apache.

the class MetaTableAccessor method addDaughter.

/**
   * Adds a daughter region entry to meta.
   * @param regionInfo the region to put
   * @param sn the location of the region
   * @param openSeqNum the latest sequence number obtained when the region was open
   */
public static void addDaughter(final Connection connection, final HRegionInfo regionInfo, final ServerName sn, final long openSeqNum) throws NotAllMetaRegionsOnlineException, IOException {
    long now = EnvironmentEdgeManager.currentTime();
    Put put = new Put(regionInfo.getRegionName(), now);
    addRegionInfo(put, regionInfo);
    if (sn != null) {
        addLocation(put, sn, openSeqNum, -1, regionInfo.getReplicaId());
    }
    putToMetaTable(connection, put);
    LOG.info("Added daughter " + regionInfo.getEncodedName() + (sn == null ? ", serverName=null" : ", serverName=" + sn.toString()));
}
Also used : Put(org.apache.hadoop.hbase.client.Put)

Example 10 with Put

use of org.apache.hadoop.hbase.client.Put in project hbase by apache.

the class TestHelloHBase method testDeleteRow.

@Test
public void testDeleteRow() throws IOException {
    Admin admin = TEST_UTIL.getAdmin();
    admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build());
    Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME);
    table.put(new Put(HelloHBase.MY_ROW_ID).addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz")));
    HelloHBase.deleteRow(table);
    Result row = table.get(new Get(HelloHBase.MY_ROW_ID));
    assertEquals("#deleteRow failed to delete row.", true, row.isEmpty());
    TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME);
    admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

Put (org.apache.hadoop.hbase.client.Put)849 Test (org.junit.Test)414 Table (org.apache.hadoop.hbase.client.Table)237 ArrayList (java.util.ArrayList)216 Result (org.apache.hadoop.hbase.client.Result)183 Scan (org.apache.hadoop.hbase.client.Scan)164 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)149 Delete (org.apache.hadoop.hbase.client.Delete)146 Cell (org.apache.hadoop.hbase.Cell)141 IOException (java.io.IOException)134 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)134 TableName (org.apache.hadoop.hbase.TableName)118 Get (org.apache.hadoop.hbase.client.Get)114 KeyValue (org.apache.hadoop.hbase.KeyValue)98 Configuration (org.apache.hadoop.conf.Configuration)79 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)75 Connection (org.apache.hadoop.hbase.client.Connection)68 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)60 Admin (org.apache.hadoop.hbase.client.Admin)54 Mutation (org.apache.hadoop.hbase.client.Mutation)53