Class SpannerTableTailer.Builder
- java.lang.Object
-
- com.google.cloud.spanner.watcher.SpannerTableTailer.Builder
-
- Enclosing class:
- SpannerTableTailer
public static class SpannerTableTailer.Builder extends Object
Builder for aSpannerTableTailer.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SpannerTableTailerbuild()Creates theSpannerTableTailer.SpannerTableTailer.BuildersetCommitTimestampColumn(String column)This should only be set if your table contains more than one commit timestamp column.SpannerTableTailer.BuildersetCommitTimestampRepository(CommitTimestampRepository repository)Sets theCommitTimestampRepositoryto use with thisSpannerTableTailer.SpannerTableTailer.BuildersetExecutor(ScheduledExecutorService executor)Sets the executor to use to poll the table and to execute theSpannerTableChangeWatcher.RowChangeCallbacks.SpannerTableTailer.BuildersetFallbackToWithQuerySeconds(int seconds)ASpannerTableTailerthat uses aFixedShardProviderwith an array of values will by default execute a simple poll query that looks like this:SpannerTableTailer.BuildersetLimit(long limit)Sets the maximum number of changes to fetch for each poll query.SpannerTableTailer.BuildersetPollInterval(org.threeten.bp.Duration interval)Sets the poll interval for the table.SpannerTableTailer.BuildersetShardProvider(ShardProvider provider)Sets theShardProviderthat thisSpannerTableTailershould use.SpannerTableTailer.BuildersetTableHint(String tableHint)Sets an optional table hint to use for the poll query.
-
-
-
Method Detail
-
setTableHint
public SpannerTableTailer.Builder setTableHint(String tableHint)
Sets an optional table hint to use for the poll query. This could for example be a `@{FORCE_INDEX=Idx_SecondaryIndex}` hint to force the usage of a specific secondary index.
-
setLimit
public SpannerTableTailer.Builder setLimit(long limit)
Sets the maximum number of changes to fetch for each poll query. Default is 10,000. Iflimitnumber of changes are found during a poll, a new poll will be scheduled directly instead of aftersetPollInterval(Duration).Setting this limit to a lower value instructs the
SpannerTableTailerto execute more poll queries more quickly if it is not able to keep up with the modifications in the table that it is watching. Setting it too low can limit the overall throughput of theSpannerTableTaileras it cannot fetch enough rows in each poll.Recommended values are between 1,000 and 10,000.
-
setFallbackToWithQuerySeconds
public SpannerTableTailer.Builder setFallbackToWithQuerySeconds(int seconds)
ASpannerTableTailerthat uses aFixedShardProviderwith an array of values will by default execute a simple poll query that looks like this:SELECT * FROM Table WHERE LastModified > @lastSeenCommitTimestamp AND ShardId IS NOT NULL AND ShardId IN UNNEST(@shardIds) ORDER BY LastModified, PrimaryKeyCol1, PrimaryKeyCol2, ... LIMIT @limitIn some specific cases these queries can also automatically be re-written to a query that creates a WITH clause for each shard id. This can be more efficient, especially if there are many old mutations that have not yet been reported by the
SpannerTableTailer. Using such a query comes with the expense of a higher memory footprint on Cloud Spanner. This query is therefore only used if theSpannerTableTaileris more than 60 seconds behind. This default limit of 60 seconds can be increased or decreased with this setting.Recommended values are between 10 seconds and 24 hours. Setting the limit to multiple hours means that the WITH query should only be used when the
SpannerTableTaileris started after having been stopped for a while, while modifications to the watched table continued to be applied.
-
setShardProvider
public SpannerTableTailer.Builder setShardProvider(ShardProvider provider)
Sets theShardProviderthat thisSpannerTableTailershould use.
-
setCommitTimestampRepository
public SpannerTableTailer.Builder setCommitTimestampRepository(CommitTimestampRepository repository)
Sets theCommitTimestampRepositoryto use with thisSpannerTableTailer.If none is set, it will default to a
SpannerCommitTimestampRepositorywhich stores the last seen commit timestamp in a table named LAST_SEEN_COMMIT_TIMESTAMPS. The table will be created if it does not yet exist.
-
setPollInterval
public SpannerTableTailer.Builder setPollInterval(org.threeten.bp.Duration interval)
Sets the poll interval for the table. Defaults to 1 second.
-
setExecutor
public SpannerTableTailer.Builder setExecutor(ScheduledExecutorService executor)
Sets the executor to use to poll the table and to execute theSpannerTableChangeWatcher.RowChangeCallbacks. Defaults to a single daemon threaded executor that is exclusively used for thisSpannerTableTailer.
-
setCommitTimestampColumn
public SpannerTableTailer.Builder setCommitTimestampColumn(String column)
This should only be set if your table contains more than one commit timestamp column.Sets the commit timestamp column to use. It is only necessary to set this property if the table contains more than one column with the allow_commit_timestamp=true option. If the table only contains one column that can hold a commit timestamp, the
SpannerTableTailerwill find the column automatically.
-
build
public SpannerTableTailer build()
Creates theSpannerTableTailer.
-
-