/** * Increment the counter for the given family and column by the specified amount * <p> * If the family and column already exist in the Increment the counter value is incremented by the * specified amount rather than overridden, as it is in HBase's * {@link Increment#addColumn(byte[], byte[], long)} method * @param inc The {@link Increment} to update * @param family The column family * @param qualifier The column qualifier * @param amount The amount to increment the counter by */ public static void addIncrement(Increment inc, final byte[] family, final byte[] qualifier, final Long amount) { NavigableMap<byte[], Long> set = inc.getFamilyMap().get(family); if (set == null) { set = new TreeMap<byte[], Long>(Bytes.BYTES_COMPARATOR); } // If qualifier exists, increment amount Long counter = set.get(qualifier); if (counter == null) { counter = 0L; } set.put(qualifier, amount + counter); inc.getFamilyMap().put(family, set); }
for (Map.Entry<byte[],NavigableMap<byte[], Long>> entry : increment.getFamilyMap().entrySet()) { byte[] cf = entry.getKey(); for (byte[] cq : entry.getValue().keySet()) {
/** {@inheritDoc} */ @Override public void execute(Tuple tuple) { Increment newInc = conf.getIncrementFromTuple(tuple, TupleTableConfig.DEFAULT_INCREMENT); Increment extInc = counters.get(newInc.getRow()); if (extInc != null) { // Increment already exists for row, add newInc to extInc for (Entry<byte[], NavigableMap<byte[], Long>> families : newInc.getFamilyMap().entrySet()) { for (Entry<byte[], Long> columns : families.getValue().entrySet()) { TupleTableConfig.addIncrement(extInc, families.getKey(), columns.getKey(), columns.getValue()); } } counters.put(newInc.getRow(), extInc); } else { counters.put(newInc.getRow(), newInc); } }
for (Entry<byte[], NavigableMap<byte[], Long>> e : inc.getFamilyMap().entrySet()) {
@Override public Object answer(InvocationOnMock a) throws Throwable { List<Increment> increments = (List<Increment>) a.getArguments()[0]; Object[] objects = (Object[]) a.getArguments()[1]; int size = increments.size(); List<Row> failedOperations = new ArrayList<>(); List<Throwable> throwables = new ArrayList<>(); List<String> hosts = new ArrayList<>(); for (int i = 0; i < size; ++i) { if (i % 2 == 1) { failedOperations.add(increments.get(i)); throwables.add(new IOException("ughhh " + i)); hosts.add("host: " + i); objects[i] = null; } else { incrementOperations.add(increments.get(i)); objects[i] = new Result(new KeyValue[]{new KeyValue( increments.get(i).getRow(), CF, HBaseDbHarness.QUALIFIER, Longs.toByteArray(increments.get(i).getFamilyMap().get(CF).get(HBaseDbHarness.QUALIFIER)) )}); } } if (!failedOperations.isEmpty()) { throw new RetriesExhaustedWithDetailsException(throwables, failedOperations, hosts); } return objects; } }
increment.getFamilyMap().entrySet()) { closeRegionOperation(); long after = EnvironmentEdgeManager.currentTimeMillis(); this.opMetrics.updateIncrementMetrics(increment.getFamilyMap().keySet(), after - before);