Class PartitionMetadataDao
java.lang.Object
org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.PartitionMetadataDao
Data access object for the Connector metadata tables.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Represents the execution of a read / write transaction in Cloud Spanner.static class
Represents a result from executing a Cloud Spanner read / write transaction. -
Method Summary
Modifier and TypeMethodDescriptionlong
countPartitionsCreatedAfter
(com.google.cloud.Timestamp timestamp) Counts all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_AT
less than the given timestamp.Finds all indexes for the metadata table.getAllPartitionsCreatedAfter
(com.google.cloud.Timestamp timestamp) Fetches all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_AT
less than the given timestamp.getPartition
(String partitionToken) Fetches the partition metadata row data for the given partition token.com.google.cloud.Timestamp
getUnfinishedMinWatermarkFrom
(com.google.cloud.Timestamp sinceTimestamp) Fetches the earliest partition watermark from the partition metadata table that is not in aPartitionMetadata.State.FINISHED
state.com.google.cloud.Timestamp
insert
(PartitionMetadata row) Inserts the partition metadata.Runs a given function in a transaction context.runInTransaction
(Function<PartitionMetadataDao.InTransactionContext, T> callable, String tagName) boolean
Checks whether the metadata table already exists in the database.com.google.cloud.Timestamp
updateToFinished
(String partitionToken) Updates a partition row toPartitionMetadata.State.FINISHED
state.com.google.cloud.Timestamp
updateToRunning
(String partitionToken) Updates a partition row toPartitionMetadata.State.RUNNING
state.com.google.cloud.Timestamp
updateToScheduled
(List<String> partitionTokens) Updates multiple partition row toPartitionMetadata.State.SCHEDULED
state.void
updateWatermark
(String partitionToken, com.google.cloud.Timestamp watermark) Update the partition watermark to the given timestamp.
-
Method Details
-
tableExists
public boolean tableExists()Checks whether the metadata table already exists in the database.- Returns:
- true if the table exists, false if the table does not exist.
-
findAllTableIndexes
Finds all indexes for the metadata table.- Returns:
- a list of index names for the metadata table.
-
getPartition
Fetches the partition metadata row data for the given partition token.- Parameters:
partitionToken
- the partition unique identifier- Returns:
- the partition metadata for the given token if it exists as a struct. Otherwise, it returns null.
-
getUnfinishedMinWatermarkFrom
@Nullable public com.google.cloud.Timestamp getUnfinishedMinWatermarkFrom(com.google.cloud.Timestamp sinceTimestamp) Fetches the earliest partition watermark from the partition metadata table that is not in aPartitionMetadata.State.FINISHED
state.- Returns:
- the earliest partition watermark which is not in a
PartitionMetadata.State.FINISHED
state.
-
getAllPartitionsCreatedAfter
Fetches all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_AT
less than the given timestamp. The results are ordered by thePartitionMetadataAdminDao.COLUMN_CREATED_AT
andPartitionMetadataAdminDao.COLUMN_START_TIMESTAMP
columns in ascending order. -
countPartitionsCreatedAfter
public long countPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp) Counts all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_AT
less than the given timestamp. -
insert
Inserts the partition metadata.- Parameters:
row
- the partition metadata to be inserted- Returns:
- the commit timestamp of the read / write transaction
-
updateToScheduled
Updates multiple partition row toPartitionMetadata.State.SCHEDULED
state.- Parameters:
partitionTokens
- the partitions' unique identifiers- Returns:
- the commit timestamp of the read / write transaction
-
updateToRunning
Updates a partition row toPartitionMetadata.State.RUNNING
state.- Parameters:
partitionToken
- the partition unique identifier- Returns:
- the commit timestamp of the read / write transaction
-
updateToFinished
Updates a partition row toPartitionMetadata.State.FINISHED
state.- Parameters:
partitionToken
- the partition unique identifier- Returns:
- the commit timestamp of the read / write transaction
-
updateWatermark
Update the partition watermark to the given timestamp.- Parameters:
partitionToken
- the partition unique identifierwatermark
- the new partition watermark
-
runInTransaction
public <T> PartitionMetadataDao.TransactionResult<T> runInTransaction(Function<PartitionMetadataDao.InTransactionContext, T> callable) Runs a given function in a transaction context. The transaction object is given as the parameter to the input function. If the function returns successfully, it will be committed. If the function throws an exception it will be rolled back.- Type Parameters:
T
- the return type to be returned from the input transactional function- Parameters:
callable
- the function to be executed within the transaction context- Returns:
- a transaction result containing the result from the function and a commit timestamp for the read / write transaction
-
runInTransaction
public <T> PartitionMetadataDao.TransactionResult<T> runInTransaction(Function<PartitionMetadataDao.InTransactionContext, T> callable, String tagName)
-