Class PartitionMetadataDao
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.PartitionMetadataDao
-
public class PartitionMetadataDao extends java.lang.Object
Data access object for the Connector metadata tables.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PartitionMetadataDao.InTransactionContext
Represents the execution of a read / write transaction in Cloud Spanner.static class
PartitionMetadataDao.TransactionResult<T>
Represents a result from executing a Cloud Spanner read / write transaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
countPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp)
Counts all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_AT
less than the given timestamp.com.google.cloud.spanner.ResultSet
getAllPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp)
Fetches all partitions with aPartitionMetadataAdminDao.COLUMN_CREATED_AT
less than the given timestamp.com.google.cloud.spanner.Struct
getPartition(java.lang.String partitionToken)
Fetches the partition metadata row data for the given partition token.com.google.cloud.Timestamp
getUnfinishedMinWatermark()
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.<T> PartitionMetadataDao.TransactionResult<T>
runInTransaction(java.util.function.Function<PartitionMetadataDao.InTransactionContext,T> callable)
Runs a given function in a transaction context.boolean
tableExists()
Checks whether the metadata table already exists in the database.com.google.cloud.Timestamp
updateToFinished(java.lang.String partitionToken)
Updates a partition row toPartitionMetadata.State.FINISHED
state.com.google.cloud.Timestamp
updateToRunning(java.lang.String partitionToken)
Updates a partition row toPartitionMetadata.State.RUNNING
state.com.google.cloud.Timestamp
updateToScheduled(java.util.List<java.lang.String> partitionTokens)
Updates multiple partition row toPartitionMetadata.State.SCHEDULED
state.void
updateWatermark(java.lang.String partitionToken, com.google.cloud.Timestamp watermark)
Update the partition watermark to the given timestamp.
-
-
-
Method Detail
-
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.
-
getPartition
@Nullable public com.google.cloud.spanner.Struct getPartition(java.lang.String partitionToken)
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.
-
getUnfinishedMinWatermark
@Nullable public com.google.cloud.Timestamp getUnfinishedMinWatermark()
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
public com.google.cloud.spanner.ResultSet getAllPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp)
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
public com.google.cloud.Timestamp insert(PartitionMetadata row)
Inserts the partition metadata.- Parameters:
row
- the partition metadata to be inserted- Returns:
- the commit timestamp of the read / write transaction
-
updateToScheduled
public com.google.cloud.Timestamp updateToScheduled(java.util.List<java.lang.String> partitionTokens)
Updates multiple partition row toPartitionMetadata.State.SCHEDULED
state.- Parameters:
partitionTokens
- the partitions' unique identifiers- Returns:
- the commit timestamp of the read / write transaction
-
updateToRunning
public com.google.cloud.Timestamp updateToRunning(java.lang.String partitionToken)
Updates a partition row toPartitionMetadata.State.RUNNING
state.- Parameters:
partitionToken
- the partition unique identifier- Returns:
- the commit timestamp of the read / write transaction
-
updateToFinished
public com.google.cloud.Timestamp updateToFinished(java.lang.String partitionToken)
Updates a partition row toPartitionMetadata.State.FINISHED
state.- Parameters:
partitionToken
- the partition unique identifier- Returns:
- the commit timestamp of the read / write transaction
-
updateWatermark
public void updateWatermark(java.lang.String partitionToken, com.google.cloud.Timestamp watermark)
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(java.util.function.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
-
-