/** * Currently only supports {@link Put} and {@link Delete} mutations. * * @param mutation The data to send. * @throws IOException if the row of added mutation doesn't match the original row */ public RowMutations add(Mutation mutation) throws IOException { return add(Collections.singletonList(mutation)); }
/** * Add a {@link Put} operation to the list of mutations * @param p The {@link Put} to add * @throws IOException if the row of added mutation doesn't match the original row * @deprecated since 2.0 version and will be removed in 3.0 version. * use {@link #add(Mutation)} */ @Deprecated public void add(Put p) throws IOException { add((Mutation) p); }
/** * Add a {@link Delete} operation to the list of mutations * @param d The {@link Delete} to add * @throws IOException if the row of added mutation doesn't match the original row * @deprecated since 2.0 version and will be removed in 3.0 version. * use {@link #add(Mutation)} */ @Deprecated public void add(Delete d) throws IOException { add((Mutation) d); }
/** * Create a {@link RowMutations} with the specified mutations. * @param mutations the mutations to send * @return RowMutations * @throws IOException if any row in mutations is different to another */ public static RowMutations of(List<? extends Mutation> mutations) throws IOException { if (CollectionUtils.isEmpty(mutations)) { throw new IllegalArgumentException("Cannot instantiate a RowMutations by empty list"); } return new RowMutations(mutations.get(0).getRow(), mutations.size()) .add(mutations); }
/** * Atomically checks if a row/family/qualifier value matches the expected * value. If it does, it adds the put. If the passed value is null, the check * is for the lack of column (ie: non-existence) * * The expected value argument of this call is on the left and the current * value of the cell is on the right side of the comparison operator. * * Ie. eg. GREATER operator means expected value > existing <=> add the put. * * @param row to check * @param family column family to check * @param qualifier column qualifier to check * @param op comparison operator to use * @param value the expected value * @param put data to put if check succeeds * @throws IOException e * @return true if the new put was executed, false otherwise * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])} */ @Deprecated default boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOperator op, byte[] value, Put put) throws IOException { RowMutations mutations = new RowMutations(put.getRow(), 1); mutations.add(put); return checkAndMutate(row, family, qualifier, op, value, mutations); }
/** * Atomically checks if a row/family/qualifier value matches the expected * value. If it does, it adds the delete. If the passed value is null, the * check is for the lack of column (ie: non-existence) * * The expected value argument of this call is on the left and the current * value of the cell is on the right side of the comparison operator. * * Ie. eg. GREATER operator means expected value > existing <=> add the delete. * * @param row to check * @param family column family to check * @param qualifier column qualifier to check * @param compareOp comparison operator to use * @param value the expected value * @param delete data to delete if check succeeds * @throws IOException e * @return true if the new delete was executed, false otherwise * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])} */ @Deprecated default boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException { RowMutations mutations = new RowMutations(delete.getRow(), 1); mutations.add(delete); return checkAndMutate(row, family, qualifier, compareOp, value, mutations); }
private RowMutations makeRowMutationsWithColumnCDeleted() throws IOException { RowMutations rm = new RowMutations(ROWKEY, 2); Put put = new Put(ROWKEY); put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")); put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")); rm.add(put); Delete del = new Delete(ROWKEY); del.addColumn(FAMILY, Bytes.toBytes("C")); rm.add(del); return rm; }
/** * Atomically checks if a row/family/qualifier value matches the expected * value. If it does, it adds the put. If the passed value is null, the check * is for the lack of column (ie: non-existence) * * The expected value argument of this call is on the left and the current * value of the cell is on the right side of the comparison operator. * * Ie. eg. GREATER operator means expected value > existing <=> add the put. * * @param row to check * @param family column family to check * @param qualifier column qualifier to check * @param compareOp comparison operator to use * @param value the expected value * @param put data to put if check succeeds * @throws IOException e * @return true if the new put was executed, false otherwise * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])} */ @Deprecated default boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Put put) throws IOException { RowMutations mutations = new RowMutations(put.getRow(), 1); mutations.add(put); return checkAndMutate(row, family, qualifier, compareOp, value, mutations); }
@Override public boolean thenPut(Put put) throws IOException { preCheck(); RowMutations rowMutations = new RowMutations(put.getRow()); rowMutations.add(put); return checkAndMutate(row, family, qualifier, op, value, rowMutations); }
@Override public boolean thenDelete(Delete delete) throws IOException { preCheck(); RowMutations rowMutations = new RowMutations(delete.getRow()); rowMutations.add(delete); return checkAndMutate(row, family, qualifier, op, value, rowMutations); }
private RowMutations getBogusRowMutations() throws IOException { Put p = new Put(ROWKEY); byte[] value = new byte[0]; p.addColumn(new byte[]{'b', 'o', 'g', 'u', 's'}, new byte[]{'A'}, value); RowMutations rm = new RowMutations(ROWKEY); rm.add(p); return rm; }
/** * Creates a {@link RowMutations} (HBase) from a {@link TRowMutations} (Thrift) * * @param in the <code>TRowMutations</code> to convert * * @return converted <code>RowMutations</code> */ public static RowMutations rowMutationsFromThrift(TRowMutations in) throws IOException { List<TMutation> mutations = in.getMutations(); RowMutations out = new RowMutations(in.getRow(), mutations.size()); for (TMutation mutation : mutations) { if (mutation.isSetPut()) { out.add(putFromThrift(mutation.getPut())); } if (mutation.isSetDeleteSingle()) { out.add(deleteFromThrift(mutation.getDeleteSingle())); } } return out; }
/** * Reset the split parent region info in meta table */ private void resetSplitParent(HbckInfo hi) throws IOException { RowMutations mutations = new RowMutations(hi.metaEntry.getRegionName()); Delete d = new Delete(hi.metaEntry.getRegionName()); d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER); d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER); mutations.add(d); RegionInfo hri = RegionInfoBuilder.newBuilder(hi.metaEntry) .setOffline(false) .setSplit(false) .build(); Put p = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime()); mutations.add(p); meta.mutateRow(mutations); LOG.info("Reset split parent " + hi.metaEntry.getRegionNameAsString() + " in META" ); }
@Test public void testMutateRow() throws InterruptedException, ExecutionException, IOException { AsyncTable<?> table = getTable.get(); RowMutations mutation = new RowMutations(row); mutation.add((Mutation) new Put(row).addColumn(FAMILY, concat(QUALIFIER, 1), VALUE)); table.mutateRow(mutation).get(); Result result = table.get(new Get(row)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, 1))); mutation = new RowMutations(row); mutation.add((Mutation) new Delete(row).addColumn(FAMILY, concat(QUALIFIER, 1))); mutation.add((Mutation) new Put(row).addColumn(FAMILY, concat(QUALIFIER, 2), VALUE)); table.mutateRow(mutation).get(); result = table.get(new Get(row)).get(); assertNull(result.getValue(FAMILY, concat(QUALIFIER, 1))); assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, 2))); }
@Test public void testMutateRow_WriteRequestCount() throws Exception { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); byte[] qf1 = Bytes.toBytes("qualifier"); byte[] val1 = Bytes.toBytes("value1"); RowMutations rm = new RowMutations(row1); Put put = new Put(row1); put.addColumn(fam1, qf1, val1); rm.add(put); this.region = initHRegion(tableName, method, CONF, fam1); long wrcBeforeMutate = this.region.writeRequestsCount.longValue(); this.region.mutateRow(rm); long wrcAfterMutate = this.region.writeRequestsCount.longValue(); Assert.assertEquals(wrcBeforeMutate + rm.getMutations().size(), wrcAfterMutate); }
@Test public void testRowMutationsWithPreBatchMutate() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); testPreBatchMutate(tableName, () -> { try { RowMutations rm = new RowMutations(ROW, 1); Table t = TEST_UTIL.getConnection().getTable(tableName); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); rm.add(put); t.mutateRow(rm); } catch (IOException ex) { throw new RuntimeException(ex); } }); }
@Test public void testFlushedFileWithVisibilityTags() throws Exception { final byte[] qual2 = Bytes.toBytes("qual2"); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); HTableDescriptor desc = new HTableDescriptor(tableName); HColumnDescriptor col = new HColumnDescriptor(fam); desc.addFamily(col); TEST_UTIL.getAdmin().createTable(desc); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put p1 = new Put(row1); p1.addColumn(fam, qual, value); p1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); Put p2 = new Put(row1); p2.addColumn(fam, qual2, value); p2.setCellVisibility(new CellVisibility(SECRET)); RowMutations rm = new RowMutations(row1); rm.add(p1); rm.add(p2); table.mutateRow(rm); } TEST_UTIL.getAdmin().flush(tableName); List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(tableName); HStore store = regions.get(0).getStore(fam); Collection<HStoreFile> storefiles = store.getStorefiles(); assertTrue(storefiles.size() > 0); for (HStoreFile storeFile : storefiles) { assertTrue(storeFile.getReader().getHFileReader().getFileContext().isIncludesTags()); } }
@Test public void testRowMutation() throws IOException { final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName()); Table table = util.createTable(tableName, new byte[][] { A, B, C }); try { verifyMethodResult(SimpleRegionObserver.class, new String[] { "hadPreGet", "hadPostGet", "hadPrePut", "hadPostPut", "hadDeleted" }, tableName, new Boolean[] { false, false, false, false, false }); Put put = new Put(ROW); put.addColumn(A, A, A); put.addColumn(B, B, B); put.addColumn(C, C, C); Delete delete = new Delete(ROW); delete.addColumn(A, A); delete.addColumn(B, B); delete.addColumn(C, C); RowMutations arm = new RowMutations(ROW); arm.add(put); arm.add(delete); table.mutateRow(arm); verifyMethodResult(SimpleRegionObserver.class, new String[] { "hadPreGet", "hadPostGet", "hadPrePut", "hadPostPut", "hadDeleted" }, tableName, new Boolean[] { false, false, true, true, true }); } finally { util.deleteTable(tableName); table.close(); } }
@Override boolean testRow(final int i) throws IOException { final byte [] bytes = format(i); // checkAndXXX tests operate on only a single value // Put a known value so when we go to check it, it is there. Put put = new Put(bytes); put.addColumn(FAMILY_ZERO, getQualifier(), bytes); this.table.put(put); RowMutations mutations = new RowMutations(bytes); mutations.add(put); this.table.checkAndMutate(bytes, FAMILY_ZERO).qualifier(getQualifier()) .ifEquals(bytes).thenMutate(mutations); return true; } }
@Test public void testMutateRowStats() throws IOException { Configuration conf = UTIL.getConfiguration(); ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(conf); Table table = conn.getTable(tableName); HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0); Region region = rs.getRegions(tableName).get(0); RowMutations mutations = new RowMutations(Bytes.toBytes("row")); Put p = new Put(Bytes.toBytes("row")); p.addColumn(family, qualifier, Bytes.toBytes("value2")); mutations.add(p); table.mutateRow(mutations); ServerStatisticTracker stats = conn.getStatisticsTracker(); assertNotNull( "No stats configured for the client!", stats); // get the names so we can query the stats ServerName server = rs.getServerName(); byte[] regionName = region.getRegionInfo().getRegionName(); // check to see we found some load on the memstore ServerStatistics serverStats = stats.getServerStatsForTesting(server); ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName); assertNotNull(regionStats); assertTrue(regionStats.getMemStoreLoadPercent() > 0); } }