Class PartitionMetadataDao


  • public class PartitionMetadataDao
    extends java.lang.Object
    Data access object for the Connector metadata tables.
    • 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 a PartitionMetadata.State.FINISHED state.
        Returns:
        the earliest partition watermark which is not in a PartitionMetadata.State.FINISHED state.
      • 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​(java.util.List<java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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

        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