org.apache.hadoop.hbase.client.BufferedMutator#mutate ( )源码实例Demo

下面列出了org.apache.hadoop.hbase.client.BufferedMutator#mutate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BigData   文件: Data2HBase1.java
/**
 * 利用BufferedMutator批量导入
 *
 * @param connection
 * @throws IOException
 */
private static void bmImport(Connection connection) throws IOException {
    BufferedMutator bufferedMutator = connection.getBufferedMutator(TableName.valueOf("t3"));
    byte[] columnFamily = "f1".getBytes();

    long startTime = System.currentTimeMillis();
    ArrayList<Put> puts = new ArrayList<Put>();
    for (int i = 0; i < 999999; i++) {
        puts.add(HBaseUtil.createPut(i + "", columnFamily, "c1", i + ""));
        //每10000条导入一次
        if (i % 10000 == 0) {
            bufferedMutator.mutate(puts);
            puts.clear();
        }
    }
    //批量调用
    bufferedMutator.mutate(puts);
    bufferedMutator.close();
    System.out.println("共耗时:" + (System.currentTimeMillis() - startTime) + "ms");
}
 
源代码2 项目: hbase   文件: MultiTableOutputFormat.java
/**
 * Writes an action (Put or Delete) to the specified table.
 *
 * @param tableName
 *          the table being updated.
 * @param action
 *          the update, either a put or a delete.
 * @throws IllegalArgumentException
 *          if the action is not a put or a delete.
 */
@Override
public void write(ImmutableBytesWritable tableName, Mutation action) throws IOException {
  BufferedMutator mutator = getBufferedMutator(tableName);
  // The actions are not immutable, so we defensively copy them
  if (action instanceof Put) {
    Put put = new Put((Put) action);
    put.setDurability(useWriteAheadLogging ? Durability.SYNC_WAL
        : Durability.SKIP_WAL);
    mutator.mutate(put);
  } else if (action instanceof Delete) {
    Delete delete = new Delete((Delete) action);
    mutator.mutate(delete);
  } else
    throw new IllegalArgumentException(
        "action must be either Delete or Put");
}
 
源代码3 项目: hbase   文件: IntegrationTestSendTraceRequests.java
private LinkedBlockingQueue<Long> insertData() throws IOException, InterruptedException {
  LinkedBlockingQueue<Long> rowKeys = new LinkedBlockingQueue<>(25000);
  BufferedMutator ht = util.getConnection().getBufferedMutator(this.tableName);
  byte[] value = new byte[300];
  TraceUtil.addSampler(Sampler.ALWAYS);
  for (int x = 0; x < 5000; x++) {
    try (TraceScope traceScope = TraceUtil.createTrace("insertData")) {
      for (int i = 0; i < 5; i++) {
        long rk = random.nextLong();
        rowKeys.add(rk);
        Put p = new Put(Bytes.toBytes(rk));
        for (int y = 0; y < 10; y++) {
          random.nextBytes(value);
          p.addColumn(familyName, Bytes.toBytes(random.nextLong()), value);
        }
        ht.mutate(p);
      }
      if ((x % 1000) == 0) {
        admin.flush(tableName);
      }
    }
  }
  admin.flush(tableName);
  return rowKeys;
}
 
源代码4 项目: hudi   文件: HBaseIndex.java
/**
 * Helper method to facilitate performing mutations (including puts and deletes) in Hbase.
 */
private void doMutations(BufferedMutator mutator, List<Mutation> mutations) throws IOException {
  if (mutations.isEmpty()) {
    return;
  }
  mutator.mutate(mutations);
  mutator.flush();
  mutations.clear();
  sleepForTime(SLEEP_TIME_MILLISECONDS);
}
 
源代码5 项目: beam   文件: HBaseIOTest.java
/** Helper function to create a table and return the rows that it created. */
private static void writeData(String tableId, int numRows) throws Exception {
  Connection connection = admin.getConnection();
  TableName tableName = TableName.valueOf(tableId);
  BufferedMutator mutator = connection.getBufferedMutator(tableName);
  List<Mutation> mutations = makeTableData(numRows);
  mutator.mutate(mutations);
  mutator.flush();
  mutator.close();
}
 
源代码6 项目: hbase   文件: TestExpiredMobFileCleaner.java
private void putKVAndFlush(BufferedMutator table, byte[] row, byte[] value, long ts)
    throws Exception {

  Put put = new Put(row, ts);
  put.addColumn(Bytes.toBytes(family), qf, value);
  table.mutate(put);

  table.flush();
  admin.flush(tableName);
}
 
源代码7 项目: cloud-bigtable-examples   文件: WritePerfTest.java
protected static void doPut(BufferedMutator mutator, byte[] value) throws IOException {
  byte[] key = Bytes.toBytes(RandomStringUtils.randomAlphanumeric(10));
  mutator.mutate(new Put(key, System.currentTimeMillis()).addColumn(BigtableUtilities.FAMILY,
  BigtableUtilities.QUALIFIER, value));
}