Class PartitionMetadataDao

java.lang.Object
org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.PartitionMetadataDao

public class PartitionMetadataDao extends Object
Data access object for the Connector metadata tables.
  • 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

      public List<String> findAllTableIndexes()
      Finds all indexes for the metadata table.
      Returns:
      a list of index names for the metadata table.
    • getPartition

      @Nullable public Struct getPartition(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.
    • 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 a PartitionMetadata.State.FINISHED state.
      Returns:
      the earliest partition watermark which is not in a PartitionMetadata.State.FINISHED state.
    • getAllPartitionsCreatedAfter

      public ResultSet getAllPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp)
      Fetches all partitions with a PartitionMetadataAdminDao.COLUMN_CREATED_AT less than the given timestamp. The results are ordered by the PartitionMetadataAdminDao.COLUMN_CREATED_AT and PartitionMetadataAdminDao.COLUMN_START_TIMESTAMP columns in ascending order.
    • countPartitionsCreatedAfter

      public long countPartitionsCreatedAfter(com.google.cloud.Timestamp timestamp)
      Counts all partitions with a PartitionMetadataAdminDao.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(List<String> partitionTokens)
      Updates multiple partition row to PartitionMetadata.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(String partitionToken)
      Updates a partition row to PartitionMetadata.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(String partitionToken)
      Updates a partition row to PartitionMetadata.State.FINISHED state.
      Parameters:
      partitionToken - the partition unique identifier
      Returns:
      the commit timestamp of the read / write transaction
    • updateWatermark

      public void updateWatermark(String partitionToken, com.google.cloud.Timestamp watermark)
      Update the partition watermark to the given timestamp.
      Parameters:
      partitionToken - the partition unique identifier
      watermark - the new partition watermark
    • runInTransaction

      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