/** * Add mutation for a particular row. The changes in the mutation will be applied atomic. However * there is no guarantees about the relative ordering between mutations affecting different rows. */ public BulkMutation add(@Nonnull ByteString rowKey, @Nonnull Mutation mutation) { Preconditions.checkNotNull(rowKey); Preconditions.checkNotNull(mutation); builder.addEntries( MutateRowsRequest.Entry.newBuilder() .setRowKey(rowKey) .addAllMutations(mutation.getMutations()) .build()); return this; }
return this; if (other.getRowKey() != com.google.protobuf.ByteString.EMPTY) { setRowKey(other.getRowKey());
public Builder mergeFrom(com.google.bigtable.v2.MutateRowsRequest.Entry other) { if (other == com.google.bigtable.v2.MutateRowsRequest.Entry.getDefaultInstance()) return this; if (other.getRowKey() != com.google.protobuf.ByteString.EMPTY) { setRowKey(other.getRowKey());
return this; if (other.getRowKey() != com.google.protobuf.ByteString.EMPTY) { setRowKey(other.getRowKey());
/** * This test ensures that protobuf creation and interactions with {@link BulkMutation} work as * expected. * * @throws IOException * @throws InterruptedException */ @Test public void testWrite() throws IOException, InterruptedException { BigtableService.Writer underTest = new BigtableServiceImpl.BigtableWriterImpl(mockSession, TABLE_NAME); Mutation mutation = Mutation.newBuilder() .setSetCell(SetCell.newBuilder().setFamilyName("Family").build()) .build(); ByteString key = ByteString.copyFromUtf8("key"); SettableFuture<MutateRowResponse> fakeResponse = SettableFuture.create(); when(mockBulkMutation.add(any(MutateRowsRequest.Entry.class))).thenReturn(fakeResponse); underTest.writeRecord(KV.of(key, ImmutableList.of(mutation))); Entry expected = MutateRowsRequest.Entry.newBuilder().setRowKey(key).addMutations(mutation).build(); verify(mockBulkMutation, times(1)).add(expected); underTest.close(); verify(mockBulkMutation, times(1)).flush(); } }
@Override public CompletionStage<MutateRowResponse> writeRecord(KV<ByteString, Iterable<Mutation>> record) throws IOException { MutateRowsRequest.Entry request = MutateRowsRequest.Entry.newBuilder() .setRowKey(record.getKey()) .addAllMutations(record.getValue()) .build(); CompletableFuture<MutateRowResponse> result = new CompletableFuture<>(); Futures.addCallback( bulkMutation.add(request), new FutureCallback<MutateRowResponse>() { @Override public void onSuccess(MutateRowResponse mutateRowResponse) { result.complete(mutateRowResponse); } @Override public void onFailure(Throwable throwable) { result.completeExceptionally(throwable); } }); return result; } }
/** * Creates a single entry bulk {@link com.google.bigtable.v2.MutateRowsRequest}, which will be * merged by the batching logic in the callable chain. */ @InternalApi public MutateRowsRequest toBulkProto(RequestContext requestContext) { String tableName = NameUtil.formatTableName( requestContext.getProjectId(), requestContext.getInstanceId(), tableId); return MutateRowsRequest.newBuilder() .setAppProfileId(requestContext.getAppProfileId()) .setTableName(tableName) .addEntries( Entry.newBuilder().setRowKey(key).addAllMutations(mutation.getMutations()).build()) .build(); } }
/** * Add mutation for a particular row. The changes in the mutation will be applied atomic. However * there is no guarantees about the relative ordering between mutations affecting different rows. */ public BulkMutation add(@Nonnull ByteString rowKey, @Nonnull Mutation mutation) { Preconditions.checkNotNull(rowKey); Preconditions.checkNotNull(mutation); builder.addEntries( MutateRowsRequest.Entry.newBuilder() .setRowKey(rowKey) .addAllMutations(mutation.getMutations()) .build()); return this; }
private static MutateRowsRequest.Entry convert(MutateRowRequest request) { if (request == null) { return null; } else { return MutateRowsRequest.Entry.newBuilder().setRowKey(request.getRowKey()) .addAllMutations(request.getMutationsList()).build(); } }
/** * Creates a single entry bulk {@link com.google.bigtable.v2.MutateRowsRequest}, which will be * merged by the batching logic in the callable chain. */ @InternalApi public MutateRowsRequest toBulkProto(RequestContext requestContext) { String tableName = NameUtil.formatTableName( requestContext.getProjectId(), requestContext.getInstanceId(), tableId); return MutateRowsRequest.newBuilder() .setAppProfileId(requestContext.getAppProfileId()) .setTableName(tableName) .addEntries( Entry.newBuilder().setRowKey(key).addAllMutations(mutation.getMutations()).build()) .build(); } }