@Override public void close() throws IOException { table.flush(); table.close(); } }
@Override void testTakedown() throws IOException { if (flushCommits) { this.mutator.flush(); } mutator.close(); } }
private void loadData(Admin admin, BufferedMutator table, TableName tableName, Put[] puts) throws IOException { table.mutate(Arrays.asList(puts)); table.flush(); admin.flush(tableName); }
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); }
/** * loads some data to the table. */ private void loadData(Admin admin, BufferedMutator table, TableName tableName, int fileNum, int rowNumPerFile) throws IOException, InterruptedException { if (fileNum <= 0) { throw new IllegalArgumentException(); } for (int i = 0; i < fileNum * rowNumPerFile; i++) { for (byte k0 : KEYS) { byte[] k = new byte[] { k0 }; byte[] key = Bytes.add(k, Bytes.toBytes(i)); byte[] mobVal = makeDummyData(10 * (i + 1)); Put put = new Put(key); put.setDurability(Durability.SKIP_WAL); put.addColumn(Bytes.toBytes(family1), Bytes.toBytes(qf1), mobVal); put.addColumn(Bytes.toBytes(family1), Bytes.toBytes(qf2), mobVal); put.addColumn(Bytes.toBytes(family2), Bytes.toBytes(qf1), mobVal); table.mutate(put); } if ((i + 1) % rowNumPerFile == 0) { table.flush(); admin.flush(tableName); } } }
public static void loadData(final Connection connection, final TableName tableName, int rows, final byte[][] splitKeys, final String... sfamilies) throws IOException { byte[][] families = new byte[sfamilies.length][]; for (int i = 0; i < families.length; ++i) { families[i] = Bytes.toBytes(sfamilies[i]); } BufferedMutator mutator = connection.getBufferedMutator(tableName); // Ensure one row per region assertTrue(rows >= splitKeys.length); for (byte[] k: splitKeys) { byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), k); byte[] key = Bytes.add(k, Bytes.toBytes(MD5Hash.getMD5AsHex(value))); mutator.mutate(createPut(families, key, value)); rows--; } // Add other extra rows. more rows, more files while (rows-- > 0) { byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), Bytes.toBytes(rows)); byte[] key = Bytes.toBytes(MD5Hash.getMD5AsHex(value)); mutator.mutate(createPut(families, key, value)); } mutator.flush(); }
public static void loadData(final HBaseTestingUtility util, final BufferedMutator mutator, int rows, byte[]... families) throws IOException, InterruptedException { // Ensure one row per region assertTrue(rows >= KEYS.length); for (byte k0: KEYS) { byte[] k = new byte[] { k0 }; byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), k); byte[] key = Bytes.add(k, Bytes.toBytes(MD5Hash.getMD5AsHex(value))); final byte[][] families1 = families; final byte[] key1 = key; final byte[] value1 = value; mutator.mutate(createPut(families1, key1, value1)); rows--; } // Add other extra rows. more rows, more files while (rows-- > 0) { byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), Bytes.toBytes(rows)); byte[] key = Bytes.toBytes(MD5Hash.getMD5AsHex(value)); final byte[][] families1 = families; final byte[] key1 = key; final byte[] value1 = value; mutator.mutate(createPut(families1, key1, value1)); } mutator.flush(); waitForTableToBeOnline(util, mutator.getName()); }
@Override protected void map(NullWritable key, NullWritable value, Context context) throws IOException, InterruptedException { String suffix = "/" + shortTaskId; int BLOCK_SIZE = (int) (recordsToWrite / 100); for (long i = 0; i < recordsToWrite;) { for (long idx = 0; idx < BLOCK_SIZE && i < recordsToWrite; idx++, i++) { int expIdx = rand.nextInt(BLOCK_SIZE) % VISIBILITY_EXPS_COUNT; String exp = VISIBILITY_EXPS[expIdx]; byte[] row = Bytes.add(Bytes.toBytes(i), Bytes.toBytes(suffix), Bytes.toBytes(exp)); Put p = new Put(row); p.addColumn(TEST_FAMILY, TEST_QUALIFIER, HConstants.EMPTY_BYTE_ARRAY); p.setCellVisibility(new CellVisibility(exp)); getCounter(expIdx).increment(1); mutator.mutate(p); if (i % 100 == 0) { context.setStatus("Written " + i + "/" + recordsToWrite + " records"); context.progress(); } } // End of block, flush all of them before we start writing anything // pointing to these! mutator.flush(); } }
mutator.flush(); if (hbaseCluster != null) { getMiniHBaseCluster().flushcache(table.getName());
protected void persist(Context output, long count, byte[][] prev, byte[][] current, byte[] id) throws IOException { for (int i = 0; i < current.length; i++) { if (i % 100 == 0) { // Tickle progress every so often else maprunner will think us hung output.progress(); } Put put = new Put(current[i]); put.addColumn(FAMILY_NAME, COLUMN_PREV, prev == null ? NO_KEY : prev[i]); if (count >= 0) { put.addColumn(FAMILY_NAME, COLUMN_COUNT, Bytes.toBytes(count + i)); } if (id != null) { put.addColumn(FAMILY_NAME, COLUMN_CLIENT, id); } // See if we are to write multiple columns. if (this.multipleUnevenColumnFamilies) { // Use any column name. put.addColumn(TINY_FAMILY_NAME, TINY_FAMILY_NAME, this.tinyValue); // Use any column name. put.addColumn(BIG_FAMILY_NAME, BIG_FAMILY_NAME, this.bigValue); } mutator.mutate(put); } mutator.flush(); }
@Test public void testMultiMetrics() throws Exception { Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); conf.set(MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY, "true"); ConnectionImplementation conn = (ConnectionImplementation) ConnectionFactory.createConnection(conf); try { BufferedMutator mutator = conn.getBufferedMutator(TABLE_NAME); byte[][] keys = {Bytes.toBytes("aaa"), Bytes.toBytes("mmm"), Bytes.toBytes("zzz")}; for (byte[] key : keys) { Put p = new Put(key); p.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(10)); mutator.mutate(p); } mutator.flush(); mutator.close(); MetricsConnection metrics = conn.getConnectionMetrics(); assertEquals(1, metrics.multiTracker.reqHist.getCount()); assertEquals(3, metrics.numActionsPerServerHist.getSnapshot().getMean(), 1e-15); assertEquals(1, metrics.numActionsPerServerHist.getCount()); } finally { conn.close(); } } }
mutator.flush();
BufferedMutator m = c.getBufferedMutator(TABLE); m.mutate(put); m.flush();
System.out.println("Result: " + res1); // co PutWriteBufferExample2-4-Get1 Try to load previously stored row, this will print "Result: keyvalues=NONE". mutator.flush(); // co PutWriteBufferExample2-5-Flush Force a flush, this causes an RPC to occur.
System.out.println("Result: " + res1); // co PutWriteBufferExample1-3-Get1 Try to load previously stored row, this will print "Result: keyvalues=NONE". mutator.flush(); // co PutWriteBufferExample1-4-Flush Force a flush, this causes an RPC to occur.
@FinishBundle public void finishBundle() throws Exception { mutator.flush(); LOG.debug("Wrote {} records", recordsWritten); }
@Override public void flush() { try { synchronized (duplicateRowTracker) { writer.flush(); duplicateRowTracker.clear(); } } catch (final IOException e) { LOGGER.warn("Unable to flush metadata writer", e); } } }
@Override public void close() throws IOException { table.flush(); table.close(); } }