/** * 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; }
/** * * * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder addEntries( int index, com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.add(index, builderForValue.build()); onChanged(); } else { entriesBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder setEntries( int index, com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.set(index, builderForValue.build()); onChanged(); } else { entriesBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder setEntries( int index, com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.set(index, builderForValue.build()); onChanged(); } else { entriesBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
@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; } }
/** * * * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder addEntries( int index, com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.add(index, builderForValue.build()); onChanged(); } else { entriesBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder addEntries( int index, com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.add(index, builderForValue.build()); onChanged(); } else { entriesBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder addEntries( com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.add(builderForValue.build()); onChanged(); } else { entriesBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * 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(); } }
/** * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder setEntries( int index, com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.set(index, builderForValue.build()); onChanged(); } else { entriesBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder addEntries( com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.add(builderForValue.build()); onChanged(); } else { entriesBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * 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(); } }
/** * * * <pre> * The row keys and corresponding mutations to be applied in bulk. * Each entry is applied as an atomic mutation, but the entries may be * applied in arbitrary order (even between entries for the same row). * At least one entry must be specified, and in total the entries can * contain at most 100000 mutations. * </pre> * * <code>repeated .google.bigtable.v2.MutateRowsRequest.Entry entries = 2;</code> */ public Builder addEntries( com.google.bigtable.v2.MutateRowsRequest.Entry.Builder builderForValue) { if (entriesBuilder_ == null) { ensureEntriesIsMutable(); entries_.add(builderForValue.build()); onChanged(); } else { entriesBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * 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(); } }