@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { Mutation mut = miniBatchOp.getOperation(0); List<Cell> cells = mut.getFamilyCellMap().get(test); Put[] puts = new Put[] { new Put(Bytes.toBytes("cpPut")).addColumn(test, dummy, cells.get(0).getTimestamp(), Bytes.toBytes("cpdummy")).setTTL(mut.getTTL()) }; LOG.info("Putting:" + Arrays.toString(puts)); miniBatchOp.addOperationsFromCP(0, puts); } }
@Test public void testPutWithTTL() throws Exception { createTable(TestPutWithTTLCoprocessor.class.getName()); try (Table t = util.getConnection().getTable(tableName)) { t.put(new Put(row1).addColumn(test, dummy, dummy).setTTL(3000)); assertRowCount(t, 2); // wait long enough for the TTL to expire Thread.sleep(5000); assertRowCount(t, 0); } }
p.addColumn(family, QUALIFIER, valBytes); p.setTTL(1l); context.write(new ImmutableBytesWritable(key), p);
protected void populatePut(byte[] lineBytes, ImportTsv.TsvParser.ParsedLine parsed, Put put, int i) throws BadTsvLineException, IOException { Cell cell = null; if (hfileOutPath == null) { cell = new KeyValue(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, KeyValue.Type.Put, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i)); if (cellVisibilityExpr != null) { // We won't be validating the expression here. The Visibility CP will do // the validation put.setCellVisibility(new CellVisibility(cellVisibilityExpr)); } if (ttl > 0) { put.setTTL(ttl); } } else { // Creating the KV which needs to be directly written to HFiles. Using the Facade // KVCreator for creation of kvs. cell = this.kvCreator.create(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i), tags); } put.add(cell); } }
/** * Creates an HBase Put. * * @param rowKey The row key. * @param cols The columns to put. * @param durability The durability of the put. * @param timeToLiveMillis The TTL in milliseconds. */ private Put createPut(byte[] rowKey, ColumnList cols, Durability durability, long timeToLiveMillis) { Put put = new Put(rowKey); put.setDurability(durability); put.setTTL(timeToLiveMillis); addColumns(cols, put); return put; }
/** * Adds a Mutation such as a Put or Increment with a time to live. The Mutation is only queued * for later execution. * * @param rowKey The row key of the Mutation. * @param cols The columns affected by the Mutation. * @param durability The durability of the mutation. * @param timeToLiveMillis The time to live in milliseconds. */ public void addMutation(byte[] rowKey, ColumnList cols, Durability durability, Long timeToLiveMillis) { if (cols.hasColumns()) { Put put = createPut(rowKey, cols, durability, timeToLiveMillis); mutations.add(put); } if (cols.hasCounters()) { Increment inc = createIncrement(rowKey, cols, durability, timeToLiveMillis); mutations.add(inc); } if (mutations.isEmpty()) { Put put = new Put(rowKey); put.setTTL(timeToLiveMillis); mutations.add(put); } }
p.addColumn(family, QUALIFIER, valBytes); p.setTTL(1l); context.write(new ImmutableBytesWritable(key), p);
p.addColumn(family, QUALIFIER, valBytes); p.setTTL(1l); context.write(new ImmutableBytesWritable(key), p);
p.addColumn(family, QUALIFIER, valBytes); p.setTTL(1l); context.write(new ImmutableBytesWritable(key), p);
p.addColumn(family, QUALIFIER, valBytes); p.setTTL(1l); context.write(new ImmutableBytesWritable(key), p);
put.setTTL(ttl);
protected void populatePut(byte[] lineBytes, ImportTsv.TsvParser.ParsedLine parsed, Put put, int i) throws BadTsvLineException, IOException { Cell cell = null; if (hfileOutPath == null) { cell = new KeyValue(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, KeyValue.Type.Put, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i)); if (cellVisibilityExpr != null) { // We won't be validating the expression here. The Visibility CP will do // the validation put.setCellVisibility(new CellVisibility(cellVisibilityExpr)); } if (ttl > 0) { put.setTTL(ttl); } } else { // Creating the KV which needs to be directly written to HFiles. Using the Facade // KVCreator for creation of kvs. cell = this.kvCreator.create(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i), tags); } put.add(cell); } }
protected void populatePut(byte[] lineBytes, ImportTsv.TsvParser.ParsedLine parsed, Put put, int i) throws BadTsvLineException, IOException { Cell cell = null; if (hfileOutPath == null) { cell = new KeyValue(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, KeyValue.Type.Put, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i)); if (cellVisibilityExpr != null) { // We won't be validating the expression here. The Visibility CP will do // the validation put.setCellVisibility(new CellVisibility(cellVisibilityExpr)); } if (ttl > 0) { put.setTTL(ttl); } } else { // Creating the KV which needs to be directly written to HFiles. Using the Facade // KVCreator for creation of kvs. cell = this.kvCreator.create(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i), tags); } put.add(cell); } }