Class NotNullShardProvider

  • All Implemented Interfaces:
    ShardProvider

    public class NotNullShardProvider
    extends Object
    implements ShardProvider
    A ShardProvider that will add a WHERE ShardId IS NOT NULL clause to the filter of a polling operation.

    This ShardProvider can be used in combination with a NULL_FILTERED secondary index on the ShardId and the commit timestamp columns. The value inserted into the ShardId column can be anything as long as it is not null.

    It is recommended to use this ShardProvider in combination with a table hint that forces the use of the secondary index during polling. See below for an example.

    The value of ShardId can be set to null by another process for rows that have not been updated recently. This will keep the NULL_FILTERED secondary index small as all entries with a null value in one of the index columns will be left out of the secondary index. See https://cloud.google.com/spanner/docs/secondary-indexes#null-indexing-disable for more information on NULL_FILTERED secondary indexes.

    Example usage in combination with a SpannerTableTailer:

    
     SpannerTableTailer tailer =
         SpannerTableTailer.newBuilder(
                 spanner, TableId.of(databaseId, "TABLE_NAME"))
             .setShardProvider(NotNullShardProvider.create("SHARD_COLUMN"))
             .setTableHint("@{FORCE_INDEX=IDX_SHARD_COLUMN_COMMIT_TIMESTAMP}")
             .build();
     
    • Method Detail

      • appendShardFilter

        public void appendShardFilter​(com.google.cloud.spanner.Statement.Builder statementBuilder)
        Description copied from interface: ShardProvider
        Appends the required sharding filter to the given statement. This could be an SQL fragment or one or more parameters or a combination of both.
        Specified by:
        appendShardFilter in interface ShardProvider
      • getShardValue

        public com.google.cloud.spanner.Value getShardValue()
        Always returns null as the watcher will always search for changes in all shards.
        Specified by:
        getShardValue in interface ShardProvider