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 classRepresents the execution of a read / write transaction in Cloud Spanner.static classRepresents a result from executing a Cloud Spanner read / write transaction. -
Method Summary
Modifier and TypeMethodDescriptionlongcountPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp) Counts all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_ATless than the given timestamp.Finds all indexes for the metadata table.getAllPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp) Fetches all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_ATless than the given timestamp.getPartition(String partitionToken) Fetches the partition metadata row data for the given partition token.com.google.cloud.TimestampgetUnfinishedMinWatermarkFrom(com.google.cloud.Timestamp sinceTimestamp) Fetches the earliest partition watermark from the partition metadata table that is not in aPartitionMetadata.State.FINISHEDstate.com.google.cloud.Timestampinsert(PartitionMetadata row) Inserts the partition metadata.Runs a given function in a transaction context.runInTransaction(Function<PartitionMetadataDao.InTransactionContext, T> callable, String tagName) booleanChecks whether the metadata table already exists in the database.com.google.cloud.TimestampupdateToFinished(String partitionToken) Updates a partition row toPartitionMetadata.State.FINISHEDstate.com.google.cloud.TimestampupdateToRunning(String partitionToken) Updates a partition row toPartitionMetadata.State.RUNNINGstate.com.google.cloud.TimestampupdateToScheduled(List<String> partitionTokens) Updates multiple partition row toPartitionMetadata.State.SCHEDULEDstate.voidupdateWatermark(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.FINISHEDstate.- Returns:
- the earliest partition watermark which is not in a
PartitionMetadata.State.FINISHEDstate.
-
getAllPartitionsCreatedAfter
Fetches all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_ATless than the given timestamp. The results are ordered by thePartitionMetadataAdminDao.COLUMN_CREATED_ATandPartitionMetadataAdminDao.COLUMN_START_TIMESTAMPcolumns in ascending order. -
countPartitionsCreatedAfter
public long countPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp) Counts all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_ATless 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.SCHEDULEDstate.- Parameters:
partitionTokens- the partitions' unique identifiers- Returns:
- the commit timestamp of the read / write transaction
-
updateToRunning
Updates a partition row toPartitionMetadata.State.RUNNINGstate.- Parameters:
partitionToken- the partition unique identifier- Returns:
- the commit timestamp of the read / write transaction
-
updateToFinished
Updates a partition row toPartitionMetadata.State.FINISHEDstate.- 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)
-