assertThat(builder.bulkMutateRowsSettings().getBatchingSettings()).isSameAs(batchingSettings); assertThat(builder.build().bulkMutateRowsSettings().getRetryableCodes()) .containsAllOf(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.build().bulkMutateRowsSettings().getRetrySettings()) .isEqualTo(retrySettings); assertThat(builder.build().bulkMutateRowsSettings().getBatchingSettings()) .isSameAs(batchingSettings);
/** * Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for automatic * batching with flow control. The chain will: * * <ul> * <li>Convert a {@link RowMutation} into a {@link MutateRowsRequest} with a single entry. * <li>Using gax's {@link com.google.api.gax.rpc.BatchingCallable} to spool the requests and * aggregate the {@link MutateRowsRequest.Entry}s. * <li>Process the response and schedule retries. At the end of each attempt, entries that have * been applied, are filtered from the next attempt. Also, any entries that failed with a * nontransient error, are filtered from the next attempt. This will continue until there * are no more entries or there are no more retry attempts left. * <li>Wrap batch failures in a {@link * com.google.cloud.bigtable.data.v2.models.MutateRowsException}. * <li>Split the responses using {@link MutateRowsBatchingDescriptor}. * </ul> */ private UnaryCallable<RowMutation, Void> createBulkMutateRowsBatchingCallable() { UnaryCallable<MutateRowsRequest, Void> baseCallable = createMutateRowsBaseCallable(); BatchingCallSettings.Builder<MutateRowsRequest, Void> batchingCallSettings = BatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()) .setBatchingSettings(settings.bulkMutateRowsSettings().getBatchingSettings()); UnaryCallable<MutateRowsRequest, Void> batching = Callables.batching(baseCallable, batchingCallSettings.build(), clientContext); MutateRowsUserFacingCallable userFacing = new MutateRowsUserFacingCallable(batching, requestContext); return userFacing.withDefaultCallContext(clientContext.getDefaultCallContext()); }
protected Builder(LoggingServiceV2StubSettings settings) { super(settings); deleteLogSettings = settings.deleteLogSettings.toBuilder(); writeLogEntriesSettings = settings.writeLogEntriesSettings.toBuilder(); listLogEntriesSettings = settings.listLogEntriesSettings.toBuilder(); listMonitoredResourceDescriptorsSettings = settings.listMonitoredResourceDescriptorsSettings.toBuilder(); listLogsSettings = settings.listLogsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, listMonitoredResourceDescriptorsSettings, listLogsSettings); }
/** * Internal helper to create the base MutateRows callable chain. The chain is responsible for * retrying individual entry in case of error. * * @see MutateRowsRetryingCallable for more details */ private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() { RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>( new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm( settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock())); RetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new MutateRowsRetryingCallable( clientContext.getDefaultCallContext(), stub.mutateRowsCallable(), retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes()); }
@Test public void testEmptyBuilder() { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); Truth.assertThat(builder.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(builder.getBatchingSettings()).isNull(); Truth.assertThat(builder.getFlowController()).isNull(); Truth.assertThat(builder.getRetryableCodes().size()).isEqualTo(0); Truth.assertThat(builder.getRetrySettings()).isNotNull(); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); builder.setBatchingSettings(batchingSettings); BatchingCallSettings settings = builder.build(); Truth.assertThat(settings.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(settings.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(settings.getFlowController()).isNotNull(); Truth.assertThat(settings.getRetryableCodes().size()).isEqualTo(0); Truth.assertThat(settings.getRetrySettings()).isNotNull(); }
static <RequestT, ResponseT> BatchingCreateResult<RequestT, ResponseT> batchingImpl( UnaryCallable<RequestT, ResponseT> innerCallable, BatchingCallSettings<RequestT, ResponseT> batchingCallSettings, ClientContext clientContext) { BatcherFactory<RequestT, ResponseT> batcherFactory = new BatcherFactory<>( batchingCallSettings.getBatchingDescriptor(), batchingCallSettings.getBatchingSettings(), clientContext.getExecutor(), batchingCallSettings.getFlowController()); UnaryCallable<RequestT, ResponseT> callable = new BatchingCallable<>( innerCallable, batchingCallSettings.getBatchingDescriptor(), batcherFactory); return new BatchingCreateResult<>(batcherFactory, callable); }
protected Builder(ClientContext clientContext) { super(clientContext); deleteLogSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); writeLogEntriesSettings = BatchingCallSettings.newBuilder(WRITE_LOG_ENTRIES_BATCHING_DESC) .setBatchingSettings(BatchingSettings.newBuilder().build()); listLogEntriesSettings = PagedCallSettings.newBuilder(LIST_LOG_ENTRIES_PAGE_STR_FACT); listMonitoredResourceDescriptorsSettings = PagedCallSettings.newBuilder(LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT); listLogsSettings = PagedCallSettings.newBuilder(LIST_LOGS_PAGE_STR_FACT); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, listMonitoredResourceDescriptorsSettings, listLogsSettings); initDefaults(this); }
private static <RequestT, ResponseT> void assertIsReflectionEqual( BatchingCallSettings<RequestT, ResponseT> settingsA, BatchingCallSettings<RequestT, ResponseT> settingsB) { assertIsReflectionEqual( settingsA, settingsB, new String[] {"retrySettings", "batchingDescriptor", "batchingSettings", "flowController"}); assertIsReflectionEqual(settingsA.getRetrySettings(), settingsA.getRetrySettings()); assertIsReflectionEqual(settingsB.getBatchingSettings(), settingsB.getBatchingSettings()); // TODO compare other batching things (batchingDescriptor, flowController) }
@Test public void testBuilderFromSettings() throws Exception { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); FlowController flowController = Mockito.mock(FlowController.class); Set<StatusCode.Code> retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder().build(); builder.setBatchingSettings(batchingSettings); builder.setFlowController(flowController); builder.setRetryableCodes(retryCodes); builder.setRetrySettings(retrySettings); BatchingCallSettings settings = builder.build(); BatchingCallSettings.Builder newBuilder = settings.toBuilder(); Truth.assertThat(newBuilder.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(newBuilder.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(newBuilder.getFlowController()).isSameAs(flowController); Truth.assertThat(newBuilder.getRetryableCodes().size()).isEqualTo(1); Truth.assertThat(newBuilder.getRetrySettings()).isSameAs(retrySettings); }
@Test public void testNoFlowControlSettings() throws Exception { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); builder.setBatchingSettings(batchingSettings); BatchingCallSettings settings = builder.build(); Truth.assertThat(settings.getFlowController()).isNotNull(); } }
.mutateRowsSettings() .setSimpleTimeoutNoRetries(Duration.ofMinutes(10)) .setRetryableCodes(settings.bulkMutateRowsSettings().getRetryableCodes()) .setIdleTimeout(Duration.ZERO);
/** * Create a callable object that represents a batching API method. Designed for use by generated * code. * * @param grpcCallSettings the gRPC call settings * @param batchingCallSettings {@link BatchingCallSettings} to configure the batching related * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @return {@link UnaryCallable} callable object. */ @BetaApi("The surface for batching is not stable yet and may change in the future.") public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createBatchingCallable( GrpcCallSettings<RequestT, ResponseT> grpcCallSettings, BatchingCallSettings<RequestT, ResponseT> batchingCallSettings, ClientContext clientContext) { UnaryCallable<RequestT, ResponseT> baseCallable = createBaseUnaryCallable(grpcCallSettings, batchingCallSettings, clientContext); // NOTE: Since batching happens asynchronously and the outermost callable simply buffers the // request. Tracing will only start on the inner callable that accepts the batch. UnaryCallable<RequestT, ResponseT> tracedCallable = new TracedBatchingCallable<>( baseCallable, clientContext.getTracerFactory(), getSpanName(grpcCallSettings.getMethodDescriptor()), batchingCallSettings.getBatchingDescriptor()); UnaryCallable<RequestT, ResponseT> batchingCallable = Callables.batching(tracedCallable, batchingCallSettings, clientContext); return batchingCallable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
@Override public BatchingCallSettings<RequestT, ResponseT> build() { return new BatchingCallSettings<>(this); } }
@Test public void testBuilder() { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); FlowController flowController = Mockito.mock(FlowController.class); Set<StatusCode.Code> retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder().build(); builder.setBatchingSettings(batchingSettings); builder.setFlowController(flowController); builder.setRetryableCodes(retryCodes); builder.setRetrySettings(retrySettings); Truth.assertThat(builder.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(builder.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(builder.getFlowController()).isSameAs(flowController); Truth.assertThat(builder.getRetryableCodes().size()).isEqualTo(1); Truth.assertThat(builder.getRetrySettings()).isSameAs(retrySettings); BatchingCallSettings settings = builder.build(); Truth.assertThat(settings.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(settings.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(settings.getFlowController()).isSameAs(flowController); Truth.assertThat(settings.getRetryableCodes().size()).isEqualTo(1); Truth.assertThat(settings.getRetrySettings()).isSameAs(retrySettings); }
static <RequestT, ResponseT> BatchingCreateResult<RequestT, ResponseT> batchingImpl( UnaryCallable<RequestT, ResponseT> innerCallable, BatchingCallSettings<RequestT, ResponseT> batchingCallSettings, ClientContext clientContext) { BatcherFactory<RequestT, ResponseT> batcherFactory = new BatcherFactory<>( batchingCallSettings.getBatchingDescriptor(), batchingCallSettings.getBatchingSettings(), clientContext.getExecutor(), batchingCallSettings.getFlowController()); UnaryCallable<RequestT, ResponseT> callable = new BatchingCallable<>( innerCallable, batchingCallSettings.getBatchingDescriptor(), batcherFactory); return new BatchingCreateResult<>(batcherFactory, callable); }
protected Builder(ClientContext clientContext) { super(clientContext); createTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); updateTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); publishSettings = BatchingCallSettings.newBuilder(PUBLISH_BATCHING_DESC) .setBatchingSettings(BatchingSettings.newBuilder().build()); getTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); listTopicsSettings = PagedCallSettings.newBuilder(LIST_TOPICS_PAGE_STR_FACT); listTopicSubscriptionsSettings = PagedCallSettings.newBuilder(LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_FACT); deleteTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( createTopicSettings, updateTopicSettings, publishSettings, getTopicSettings, listTopicsSettings, listTopicSubscriptionsSettings, deleteTopicSettings, setIamPolicySettings, getIamPolicySettings, testIamPermissionsSettings); initDefaults(this); }
/** * Internal helper to create the base MutateRows callable chain. The chain is responsible for * retrying individual entry in case of error. * * @see MutateRowsRetryingCallable for more details */ private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() { RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>( new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm( settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock())); RetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new MutateRowsRetryingCallable( clientContext.getDefaultCallContext(), stub.mutateRowsCallable(), retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes()); }
.mutateRowsSettings() .setSimpleTimeoutNoRetries(Duration.ofMinutes(10)) .setRetryableCodes(settings.bulkMutateRowsSettings().getRetryableCodes()) .setIdleTimeout(Duration.ZERO);
@Override public BatchingCallSettings<RequestT, ResponseT> build() { return new BatchingCallSettings<>(this); } }
/** * Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for automatic * batching with flow control. The chain will: * * <ul> * <li>Convert a {@link RowMutation} into a {@link MutateRowsRequest} with a single entry. * <li>Using gax's {@link com.google.api.gax.rpc.BatchingCallable} to spool the requests and * aggregate the {@link MutateRowsRequest.Entry}s. * <li>Process the response and schedule retries. At the end of each attempt, entries that have * been applied, are filtered from the next attempt. Also, any entries that failed with a * nontransient error, are filtered from the next attempt. This will continue until there * are no more entries or there are no more retry attempts left. * <li>Wrap batch failures in a {@link * com.google.cloud.bigtable.data.v2.models.MutateRowsException}. * <li>Split the responses using {@link MutateRowsBatchingDescriptor}. * </ul> */ private UnaryCallable<RowMutation, Void> createBulkMutateRowsBatchingCallable() { UnaryCallable<MutateRowsRequest, Void> baseCallable = createMutateRowsBaseCallable(); BatchingCallSettings.Builder<MutateRowsRequest, Void> batchingCallSettings = BatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()) .setBatchingSettings(settings.bulkMutateRowsSettings().getBatchingSettings()); UnaryCallable<MutateRowsRequest, Void> batching = Callables.batching(baseCallable, batchingCallSettings.build(), clientContext); MutateRowsUserFacingCallable userFacing = new MutateRowsUserFacingCallable(batching, requestContext); return userFacing.withDefaultCallContext(clientContext.getDefaultCallContext()); }