/** * 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-existance) * * @param row to check * @param family column family to check * @param qualifier column qualifier to check * @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, byte[] value, Put put) throws IOException { return checkAndPut(row, family, qualifier, CompareOperator.EQUAL, value, put); }
@Override public boolean checkAndPut(final String tableName, final byte[] rowId, final byte[] family, final byte[] qualifier, final byte[] value, final PutColumn column) throws IOException { try (final Table table = connection.getTable(TableName.valueOf(tableName))) { Put put = new Put(rowId); put.addColumn( column.getColumnFamily(), column.getColumnQualifier(), column.getBuffer()); return table.checkAndPut(rowId, family, qualifier, value, put); } }
@Override public boolean checkAndPut(final String tableName, final byte[] rowId, final byte[] family, final byte[] qualifier, final byte[] value, final PutColumn column) throws IOException { try (final Table table = connection.getTable(TableName.valueOf(tableName))) { Put put = new Put(rowId); put.addColumn( column.getColumnFamily(), column.getColumnQualifier(), column.getBuffer()); return table.checkAndPut(rowId, family, qualifier, value, put); } }
@Override public synchronized boolean putIfAbsent(String key, V value) { try { Put put = new Put(row(key)); put.addColumn(FAMILY, QUALIFIER, bytes(value)); return hbaseTable.checkAndPut(put.getRow(), FAMILY, QUALIFIER, null /*absent*/, put); } catch (IOException e) { throw UserException.dataReadError(e) .message("Caught error while putting row '%s' into table '%s'", key, hbaseTableName) .build(logger); } }
put.addColumn(B_FAMILY, B_COLUMN_TS, Bytes.toBytes(newTS)); boolean ok = table.checkAndPut(row, B_FAMILY, B_COLUMN_TS, bOldTS, put); logger.trace("Update row {} from oldTs: {}, to newTs: {}, operation result: {}", resPath, oldTS, newTS, ok); if (!ok) {
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put) throws IOException { return delegate.checkAndPut(row, family, qualifier, value, put); }
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOperator op, byte[] value, Put put) throws IOException { return delegate.checkAndPut(row, family, qualifier, op, value, put); }
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, byte[] value, Put put) throws IOException { return delegate.checkAndPut(row, family, qualifier, compareOp, value, put); }
assertObserverHasExecuted(); assertTrue(table.checkAndPut(ROW, FAMILY, QUALIFIER, null, put)); assertObserverHasExecuted();
/** * 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-existance) * * @param row to check * @param family column family to check * @param qualifier column qualifier to check * @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, byte[] value, Put put) throws IOException { return checkAndPut(row, family, qualifier, CompareOperator.EQUAL, value, put); }
Bytes.toBytes("val1")); // co CheckAndPutExample-01-Put1 Create a new Put instance. boolean res1 = table.checkAndPut(Bytes.toBytes("row1"), Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), null, put1); // co CheckAndPutExample-02-CAS1 Check if column does not exist and perform optional put operation. System.out.println("Put 1a applied: " + res1); // co CheckAndPutExample-03-SOUT1 Print out the result, should be "Put 1a applied: true". boolean res2 = table.checkAndPut(Bytes.toBytes("row1"), Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), null, put1); // co CheckAndPutExample-04-CAS2 Attempt to store same cell again. System.out.println("Put 1b applied: " + res2); // co CheckAndPutExample-05-SOUT2 Print out the result, should be "Put 1b applied: false" as the column now already exists. Bytes.toBytes("val2")); // co CheckAndPutExample-06-Put2 Create another Put instance, but using a different column qualifier. boolean res3 = table.checkAndPut(Bytes.toBytes("row1"), Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), // co CheckAndPutExample-07-CAS3 Store new data only if the previous data has been saved. Bytes.toBytes("val1"), put2); Bytes.toBytes("val3")); // co CheckAndPutExample-09-Put3 Create yet another Put instance, but using a different row. boolean res4 = table.checkAndPut(Bytes.toBytes("row1"), Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), // co CheckAndPutExample-10-CAS4 Store new data while checking a different row. Bytes.toBytes("val1"), put3);
put.addColumn(family, qualifier, value); boolean checkAndPut = sysMutexTable.checkAndPut(rowKey, family, qualifier, null, put); String processName = ManagementFactory.getRuntimeMXBean().getName(); String msg =
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual17"), Bytes.toBytes("val17")); boolean cap = table.checkAndPut(Bytes.toBytes("row10"), Bytes.toBytes("colfam1"), Bytes.toBytes("qual15"), null, put); System.out.println(" -> success: " + cap); cap = table.checkAndPut(Bytes.toBytes("row10"), Bytes.toBytes("colfam1"), Bytes.toBytes("qual16"), null, put); System.out.println(" -> success: " + cap);
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, byte[] value, Put put) throws IOException { return delegate.checkAndPut(row, family, qualifier, compareOp, value, put); }
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOperator op, byte[] value, Put put) throws IOException { return delegate.checkAndPut(row, family, qualifier, op, value, put); }
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put) throws IOException { return delegate.checkAndPut(row, family, qualifier, value, put); }
if (metaTable.checkAndPut(statsTableKey, PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, UPGRADE_TO_4_7_COLUMN_NAME, null, upgradePut)) { List<Mutation> mutations = Lists.newArrayListWithExpectedSize(1000);
saltPut.add(saltKV); if (!sysTable.checkAndPut(seqTableKey, PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.SALT_BUCKETS_BYTES, null, saltPut)) { if (sysTable.checkAndPut(seqTableKey, PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES, oldSeqNum, seqNumPut)) {
@Override public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put) throws IOException { if (allowNonTransactional) { return hTable.checkAndPut(row, family, qualifier, value, put); } else { throw new UnsupportedOperationException("Operation is not supported transactionally"); } }
@Override public boolean checkAndPut(final String tableName, final byte[] rowId, final byte[] family, final byte[] qualifier, final byte[] value, final PutColumn column) throws IOException { try (final Table table = connection.getTable(TableName.valueOf(tableName))) { Put put = new Put(rowId); put.addColumn( column.getColumnFamily(), column.getColumnQualifier(), column.getBuffer()); return table.checkAndPut(rowId, family, qualifier, value, put); } }