@Override public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) { List<Put> puts = Lists.newArrayList(); for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> row : updates.entrySet()) { byte[] distributedKey = createDistributedRowKey(row.getKey()); PutBuilder put = tableUtil.buildPut(distributedKey); for (Map.Entry<byte[], byte[]> column : row.getValue().entrySet()) { put.add(columnFamily, column.getKey(), column.getValue()); } puts.add(put.build()); } try { hTable.put(puts); hTable.flushCommits(); } catch (IOException e) { throw new DataSetException("Put failed on table " + tableId, e); } }
public Put newIncrement(byte[] row, byte[] column, long timestamp, long value) { return tableUtil.buildPut(row) .add(FAMILY, column, timestamp, Bytes.toBytes(value)) .setAttribute(HBaseTable.DELTA_WRITE, EMPTY_BYTES) .build(); }
private Put getIncrementalPut(byte[] row) { return tableUtil.buildPut(row) .setAttribute(HBaseTable.DELTA_WRITE, Bytes.toBytes(true)) .build(); }
private PutBuilder getPut(PutBuilder existing, byte[] row, @Nullable byte[] txId) { if (existing != null) { return existing; } PutBuilder putBuilder = tableUtil.buildPut(row); if (txId != null) { putBuilder.setAttribute(TX_MAX_LIFETIME_MILLIS_KEY, txMaxLifetimeMillis) .setAttribute(TX_ID, txId); } return putBuilder; }
private Put getIncrementalPut(byte[] row) { return tableUtil.buildPut(row) .setAttribute(HBaseTable.DELTA_WRITE, Bytes.toBytes(true)) .build(); }
private PutBuilder getPut(PutBuilder existing, byte[] row, @Nullable byte[] txId) { if (existing != null) { return existing; } PutBuilder putBuilder = tableUtil.buildPut(row); if (txId != null) { putBuilder.setAttribute(TX_MAX_LIFETIME_MILLIS_KEY, txMaxLifetimeMillis) .setAttribute(TX_ID, txId); } return putBuilder; }
@Override public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) { List<Put> puts = Lists.newArrayList(); for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> row : updates.entrySet()) { byte[] distributedKey = createDistributedRowKey(row.getKey()); PutBuilder put = tableUtil.buildPut(distributedKey); for (Map.Entry<byte[], byte[]> column : row.getValue().entrySet()) { put.add(columnFamily, column.getKey(), column.getValue()); } puts.add(put.build()); } try { hTable.put(puts); hTable.flushCommits(); } catch (IOException e) { throw new DataSetException("Put failed on table " + tableId, e); } }
private PutBuilder getPutForIncrement(PutBuilder existing, byte[] row, @Nullable byte[] txId) { if (existing != null) { return existing; } return tableUtil.buildPut(row) .setAttribute(DELTA_WRITE, Bytes.toBytes(true)) .setAttribute(TX_MAX_LIFETIME_MILLIS_KEY, txMaxLifetimeMillis) .setAttribute(TX_ID, txId); }
@Override public void put(SortedMap<byte[], ? extends SortedMap<byte[], Long>> updates) { List<Put> puts = Lists.newArrayList(); for (Map.Entry<byte[], ? extends SortedMap<byte[], Long>> row : updates.entrySet()) { byte[] distributedKey = createDistributedRowKey(row.getKey()); PutBuilder put = tableUtil.buildPut(distributedKey); for (Map.Entry<byte[], Long> column : row.getValue().entrySet()) { put.add(columnFamily, column.getKey(), Bytes.toBytes(column.getValue())); } puts.add(put.build()); } try { hTable.put(puts); hTable.flushCommits(); } catch (IOException e) { throw new DataSetException("Put failed on table " + tableId, e); } }
private PutBuilder getPutForIncrement(PutBuilder existing, byte[] row, @Nullable byte[] txId) { if (existing != null) { return existing; } return tableUtil.buildPut(row) .setAttribute(DELTA_WRITE, Bytes.toBytes(true)) .setAttribute(TX_MAX_LIFETIME_MILLIS_KEY, txMaxLifetimeMillis) .setAttribute(TX_ID, txId); }
@Override public void put(SortedMap<byte[], ? extends SortedMap<byte[], Long>> updates) { List<Put> puts = Lists.newArrayList(); for (Map.Entry<byte[], ? extends SortedMap<byte[], Long>> row : updates.entrySet()) { byte[] distributedKey = createDistributedRowKey(row.getKey()); PutBuilder put = tableUtil.buildPut(distributedKey); for (Map.Entry<byte[], Long> column : row.getValue().entrySet()) { put.add(columnFamily, column.getKey(), Bytes.toBytes(column.getValue())); } puts.add(put.build()); } try { hTable.put(puts); hTable.flushCommits(); } catch (IOException e) { throw new DataSetException("Put failed on table " + tableId, e); } }
@WriteOnly @Override public void put(byte[] key, @Nullable byte[] value) { try { if (value == null) { table.delete(tableUtil.buildDelete(key).build()); } else { Put put = tableUtil.buildPut(key) .add(DATA_COLUMN_FAMILY, DEFAULT_COLUMN, value) .build(); table.put(put); } } catch (IOException e) { throw Throwables.propagate(e); } }
@WriteOnly @Override public void put(byte[] key, @Nullable byte[] value) { try { if (value == null) { table.delete(tableUtil.buildDelete(key).build()); } else { Put put = tableUtil.buildPut(key) .add(DATA_COLUMN_FAMILY, DEFAULT_COLUMN, value) .build(); table.put(put); } } catch (IOException e) { throw Throwables.propagate(e); } }
@Override public void persist(Iterator<RawPayloadTableEntry> entries) throws IOException { List<Put> batchPuts = new ArrayList<>(); while (entries.hasNext()) { RawPayloadTableEntry tableEntry = entries.next(); Put put = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(tableEntry.getKey())) .add(columnFamily, COL, tableEntry.getValue()) .build(); batchPuts.add(put); } try { if (!batchPuts.isEmpty()) { hTable.put(batchPuts); if (!hTable.isAutoFlush()) { hTable.flushCommits(); } } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException { byte[] rowKey = MessagingUtils.toMetadataRowKey(topicId); boolean completed = false; try { // Keep trying to delete while (!completed) { TopicMetadata oldMetadata = getMetadata(topicId); TreeMap<String, String> newProperties = new TreeMap<>(oldMetadata.getProperties()); newProperties.put(TopicMetadata.GENERATION_KEY, Integer.toString(oldMetadata.getGeneration() * -1)); Put put = tableUtil.buildPut(rowKey) .add(columnFamily, COL, Bytes.toBytes(GSON.toJson(newProperties, MAP_TYPE))) .build(); byte[] oldValue = Bytes.toBytes(GSON.toJson(new TreeMap<>(oldMetadata.getProperties()), MAP_TYPE)); completed = hTable.checkAndPut(rowKey, columnFamily, COL, oldValue, put); } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override public void persist(Iterator<RawPayloadTableEntry> entries) throws IOException { List<Put> batchPuts = new ArrayList<>(); while (entries.hasNext()) { RawPayloadTableEntry tableEntry = entries.next(); Put put = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(tableEntry.getKey())) .add(columnFamily, COL, tableEntry.getValue()) .build(); batchPuts.add(put); } try { if (!batchPuts.isEmpty()) { hTable.put(batchPuts); if (!hTable.isAutoFlush()) { hTable.flushCommits(); } } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException { byte[] rowKey = MessagingUtils.toMetadataRowKey(topicId); boolean completed = false; try { // Keep trying to delete while (!completed) { TopicMetadata oldMetadata = getMetadata(topicId); TreeMap<String, String> newProperties = new TreeMap<>(oldMetadata.getProperties()); newProperties.put(TopicMetadata.GENERATION_KEY, Integer.toString(oldMetadata.getGeneration() * -1)); Put put = tableUtil.buildPut(rowKey) .add(columnFamily, COL, Bytes.toBytes(GSON.toJson(newProperties, MAP_TYPE))) .build(); byte[] oldValue = Bytes.toBytes(GSON.toJson(new TreeMap<>(oldMetadata.getProperties()), MAP_TYPE)); completed = hTable.checkAndPut(rowKey, columnFamily, COL, oldValue, put); } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException { List<Put> batchPuts = new ArrayList<>(); while (entries.hasNext()) { RawMessageTableEntry entry = entries.next(); PutBuilder putBuilder = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(entry.getKey())); if (entry.getTxPtr() != null) { putBuilder.add(columnFamily, TX_COL, entry.getTxPtr()); } if (entry.getPayload() != null) { putBuilder.add(columnFamily, PAYLOAD_COL, entry.getPayload()); } batchPuts.add(putBuilder.build()); } try { if (!batchPuts.isEmpty()) { hTable.put(batchPuts); if (!hTable.isAutoFlush()) { hTable.flushCommits(); } } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override public void updateTopic(TopicMetadata topicMetadata) throws TopicNotFoundException, IOException { byte[] rowKey = MessagingUtils.toMetadataRowKey(topicMetadata.getTopicId()); boolean completed = false; try { // Keep trying to update while (!completed) { TopicMetadata oldMetadata = getMetadata(topicMetadata.getTopicId()); TreeMap<String, String> newProperties = new TreeMap<>(topicMetadata.getProperties()); newProperties.put(TopicMetadata.GENERATION_KEY, Integer.toString(oldMetadata.getGeneration())); Put put = tableUtil.buildPut(rowKey) .add(columnFamily, COL, Bytes.toBytes(GSON.toJson(newProperties, MAP_TYPE))) .build(); byte[] oldValue = Bytes.toBytes(GSON.toJson(new TreeMap<>(oldMetadata.getProperties()), MAP_TYPE)); completed = hTable.checkAndPut(rowKey, columnFamily, COL, oldValue, put); } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException { List<Put> batchPuts = new ArrayList<>(); while (entries.hasNext()) { RawMessageTableEntry entry = entries.next(); PutBuilder putBuilder = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(entry.getKey())); if (entry.getTxPtr() != null) { putBuilder.add(columnFamily, TX_COL, entry.getTxPtr()); } if (entry.getPayload() != null) { putBuilder.add(columnFamily, PAYLOAD_COL, entry.getPayload()); } batchPuts.add(putBuilder.build()); } try { if (!batchPuts.isEmpty()) { hTable.put(batchPuts); if (!hTable.isAutoFlush()) { hTable.flushCommits(); } } } catch (IOException e) { throw exceptionHandler.handle(e); } }