Class SpannerSinkBuilder<T>
- Type Parameters:
T- type of the records written by the sink
SpannerSink.builder().
database(DatabaseDestination) and serializer(SpannerMutationSerializationSchema) are required; everything else is defaulted.
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.api.connector.sink2.Sink<T>build()Builds the sink.constraintViolationPolicy(ConstraintViolationPolicy constraintViolationPolicy) Sets what happens to a mutation Spanner refuses for violating a constraint — aNULLin aNOT NULLcolumn, an over-long value, aCHECKor foreign-key constraint.database(DatabaseDestination database) Sets the database to write to.emulatorEndpoint(String emulatorEndpoint) Points the sink at a Spanner emulator instead of the real service.exportClientMetricsToCloudMonitoring(boolean exportClientMetricsToCloudMonitoring) Sets whether the Spanner client takes part in its built-in export of client-side metrics to Cloud Monitoring.exportClientMetricsToFlink(boolean exportClientMetricsToFlink) Exports the Spanner client's own metrics through Flink's metric system, so that every configured Flink metric reporter sees them.failedMutationHandler(FailureHandler<? super FailedMutation> failedMutationHandler) Sets what happens to a mutation the service terminally refused.serializer(SpannerMutationSerializationSchema<? super T> serializer) Sets the schema turning records into mutations.serviceAccountKeyFile(String serviceAccountKeyFile) Authenticates the sink with the service-account JSON key at the given path instead of application-default credentials.writerOptions(SpannerWriterOptions writerOptions) Sets the writer's tuning options.
-
Method Details
-
database
Sets the database to write to. Required.- Parameters:
database- the database- Returns:
- this builder
-
serializer
Sets the schema turning records into mutations. Required.- Parameters:
serializer- the serialization schema- Returns:
- this builder
-
writerOptions
Sets the writer's tuning options. Optional; defaults toSpannerWriterOptions.defaults().- Parameters:
writerOptions- the writer options- Returns:
- this builder
-
failedMutationHandler
public SpannerSinkBuilder<T> failedMutationHandler(FailureHandler<? super FailedMutation> failedMutationHandler) Sets what happens to a mutation the service terminally refused. Optional; defaults toFailureHandler.failJob().- Parameters:
failedMutationHandler- the failure handler- Returns:
- this builder
-
constraintViolationPolicy
public SpannerSinkBuilder<T> constraintViolationPolicy(ConstraintViolationPolicy constraintViolationPolicy) Sets what happens to a mutation Spanner refuses for violating a constraint — aNULLin aNOT NULLcolumn, an over-long value, aCHECKor foreign-key constraint. Optional; defaults toConstraintViolationPolicy.FAIL_JOB.Under
ConstraintViolationPolicy.ROUTE_TO_FAILURE_HANDLERsuch a mutation reachesfailedMutationHandler(FailureHandler), so that handler decides whether it fails the job, is dropped or is dead-lettered.- Parameters:
constraintViolationPolicy- the policy- Returns:
- this builder
-
serviceAccountKeyFile
Authenticates the sink with the service-account JSON key at the given path instead of application-default credentials. The file is read on each TaskManager when its writer is created, so every TaskManager that can run the sink must see the same path. Optional; when unset the real-service path uses application-default credentials.Service-account keys are long-lived secrets. Prefer an attached service account or Workload Identity where the deployment supports one. This setting cannot be combined with
emulatorEndpoint(String), whose plaintext channel carries no credentials.- Parameters:
serviceAccountKeyFile- the service-account JSON key-file path- Returns:
- this builder
-
emulatorEndpoint
Points the sink at a Spanner emulator instead of the real service. Optional; for tests.The emulator needs no credentials, so setting this also stops the client from looking for any.
- Parameters:
emulatorEndpoint- the emulator's gRPC endpoint ashost:port- Returns:
- this builder
- Throws:
IllegalArgumentException- if the endpoint is nothost:portwith a port in 1..65535
-
exportClientMetricsToFlink
Exports the Spanner client's own metrics through Flink's metric system, so that every configured Flink metric reporter sees them. Optional; off by default.The writer registers them under its metric group as
rpcMethod.METHOD.leaf, for the RPC methods its client calls: per method, the client's operation and attempt counts and latencies, and per attempt the Google front end's and the Spanner API front end's timing and the attempts that arrived without it. Latencies are reported as a count and a millisecond sum, so a backend divides their rates for the mean over any window; no percentile is reported. Against an emulator the client records nothing, so the series stay at zero.This does not stop the client's built-in export of the same metrics to Cloud Monitoring;
exportClientMetricsToCloudMonitoring(boolean)does.- Parameters:
exportClientMetricsToFlink- whether to export the client's metrics to Flink- Returns:
- this builder
-
exportClientMetricsToCloudMonitoring
public SpannerSinkBuilder<T> exportClientMetricsToCloudMonitoring(boolean exportClientMetricsToCloudMonitoring) Sets whether the Spanner client takes part in its built-in export of client-side metrics to Cloud Monitoring. Optional; on by default, unless theSPANNER_DISABLE_BUILTIN_METRICSenvironment variable turns the export off.The client exports through one exporter per class loader, which the first client that takes part starts and which stays until the JVM exits. Off, this sink's client neither starts it nor records into it; an exporter another client started keeps running. It is independent of
exportClientMetricsToFlink(boolean), which neither needs nor stops this export.- Parameters:
exportClientMetricsToCloudMonitoring- whether the client exports to Cloud Monitoring- Returns:
- this builder
-
build
Builds the sink.- Returns:
- the sink
- Throws:
IllegalStateException- if a required option is missing
-