Refine search
private static void increment(int sleepSteps) throws IOException { for (long i = 1; i <= UPPER; i++) { TABLE.increment(new Increment(ROW).addColumn(FAMILY, CQ1, i).addColumn(FAMILY, CQ2, 2 * i)); if (sleepSteps > 0 && i % sleepSteps == 0) { try { Thread.sleep(10); } catch (InterruptedException e) { } } } }
CrossRowCellIncrementer(final int i, final int count, final HRegion region, final int range) { super("" + i); setDaemon(true); this.count = count; this.region = region; this.increments = new Increment[range]; for (int ii = 0; ii < range; ii++) { this.increments[ii] = new Increment(Bytes.toBytes(i)); this.increments[ii].addColumn(INCREMENT_BYTES, INCREMENT_BYTES, 1); } }
/** * From a {@link TIncrement} create an {@link Increment}. * @param tincrement the Thrift version of an increment * @return an increment that the {@link TIncrement} represented. */ public static Increment incrementFromThrift(TIncrement tincrement) { Increment inc = new Increment(tincrement.getRow()); byte[][] famAndQf = CellUtil.parseColumn(tincrement.getColumn()); if (famAndQf.length != 2) { return null; } inc.addColumn(famAndQf[0], famAndQf[1], tincrement.getAmmount()); return inc; }
@Override public void run() { try { for (int i = 0; i < 100; i++) { byte[] row = Bytes.toBytes("incrementRow" + i); Increment inc = new Increment(row); inc.addColumn("cf".getBytes(), Bytes.toBytes(0), 1); // inc.setDurability(Durability.ASYNC_WAL); region.increment(inc); latch.countDown(); Thread.sleep(10); } } catch (Throwable t) { LOG.warn("Error happend when Put: ", t); } } }
/** * Atomically increments a column value. If the column value already exists and is not a * big-endian long, this could throw an exception. If the column value does not yet exist it is * initialized to <code>amount</code> and written to the specified column. * <p> * Setting durability to {@link Durability#SKIP_WAL} means that in a fail scenario you will lose * any increments that have not been flushed. * @param row The row that contains the cell to increment. * @param family The column family of the cell to increment. * @param qualifier The column qualifier of the cell to increment. * @param amount The amount to increment the cell with (or decrement, if the amount is negative). * @param durability The persistence guarantee for this increment. * @return The new value, post increment. The return value will be wrapped by a * {@link CompletableFuture}. */ default CompletableFuture<Long> incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount, Durability durability) { Preconditions.checkNotNull(row, "row is null"); Preconditions.checkNotNull(family, "family is null"); return increment( new Increment(row).addColumn(family, qualifier, amount).setDurability(durability)) .thenApply(r -> Bytes.toLong(r.getValue(family, qualifier))); }
/** * See {@link #incrementColumnValue(byte[], byte[], byte[], long, Durability)} * <p> * The {@link Durability} is defaulted to {@link Durability#SYNC_WAL}. * @param row The row that contains the cell to increment. * @param family The column family of the cell to increment. * @param qualifier The column qualifier of the cell to increment. * @param amount The amount to increment the cell with (or decrement, if the * amount is negative). * @return The new value, post increment. * @throws IOException if a remote or network exception occurs. */ default long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount) throws IOException { Increment increment = new Increment(row).addColumn(family, qualifier, amount); Cell cell = increment(increment).getColumnLatestCell(family, qualifier); return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
@Test public void testIncrementInstance() { final long expected = 13; Increment inc = new Increment(new byte [] {'r'}); int total = 0; for (int i = 0; i < 2; i++) { byte [] bytes = Bytes.toBytes(i); inc.addColumn(bytes, bytes, expected); total++; } Map<byte[], NavigableMap<byte [], Long>> familyMapOfLongs = inc.getFamilyMapOfLongs(); int found = 0; for (Map.Entry<byte [], NavigableMap<byte [], Long>> entry: familyMapOfLongs.entrySet()) { for (Map.Entry<byte [], Long> e: entry.getValue().entrySet()) { assertEquals(expected, e.getValue().longValue()); found++; } } assertEquals(total, found); } }
@Test public void testIncrWithReadOnlyTable() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); this.region = initHRegion(tableName, method, CONF, true, Bytes.toBytes("somefamily")); boolean exceptionCaught = false; Increment inc = new Increment(Bytes.toBytes("somerow")); inc.setDurability(Durability.SKIP_WAL); inc.addColumn(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 1L); try { region.increment(inc); } catch (IOException e) { exceptionCaught = true; } assertTrue(exceptionCaught == true); }
@Override boolean testRow(final int i) throws IOException { Increment increment = new Increment(format(i)); // unlike checkAndXXX tests, which make most sense to do on a single value, // if multiple families are specified for an increment test we assume it is // meant to raise the work factor for (int family = 0; family < opts.families; family++) { byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family); increment.addColumn(familyName, getQualifier(), 1l); } updateValueSize(this.table.increment(increment)); return true; } }