Interface ReplicationStream

All Superinterfaces:
AutoCloseable

public interface ReplicationStream extends AutoCloseable
A stream from which messages sent by a logical decoding plugin can be consumed over a replication connection.
Author:
Horia Chiorean (hchiorea@redhat.com)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    //TODO author=Horia Chiorean date=13/10/2016 description=Don't use this for now, because of the bug from the PG server This is stream is closed atm.
    void
    Sends a message to the server informing it about that latest position in the WAL that has successfully been processed.
    Returns the value for the latest server received LSN during a read operation.
    void
    Blocks and waits for a replication message to be sent over a replication connection.
    boolean
    Attempts to read a replication message from a replication connection, processing that message if it's available or returning false if nothing is available.
    void
    Starts a background thread to ensure the slot is kept alive, useful for when temporarily stopping reads from the stream such as querying metadata, etc
    Returns the value for the LSN form which the streaming is executed.
    void
    Stops the background thread that is used to ensure the slot is kept alive.
  • Method Details

    • read

      Blocks and waits for a replication message to be sent over a replication connection. Once a message has been received, the value of the last received LSN will also be updated accordingly.
      Parameters:
      processor - - a callback to which the arrived message is passed
      Throws:
      SQLException - if anything unexpected fails
      InterruptedException
      See Also:
      • PGReplicationStream.read()
    • readPending

      Attempts to read a replication message from a replication connection, processing that message if it's available or returning false if nothing is available. Once a message has been received, the value of the last received LSN will also be updated accordingly.
      Parameters:
      processor - - a callback to which the arrived message is passed
      Returns:
      true if a message was received and processed
      Throws:
      SQLException - if anything unexpected fails
      InterruptedException
      See Also:
      • PGReplicationStream.readPending()
    • flushLsn

      void flushLsn(Lsn lsn) throws SQLException
      Sends a message to the server informing it about that latest position in the WAL that has successfully been processed. Due to the internal buffering the messages sent to Kafka (and thus committed offsets) will usually lag behind the latest received LSN, which is why this method must only be called after the accompanying event has been sent to Kafka and the offset has been committed there.

      This essentially tells the server that this stream has successfully processed messages up to the current read cursor and so the server is free to discard older segments with earlier LSNs. It also affects the catch-up behavior once a slot is restarted and the server attempt to bring it up-to-date.

      Throws:
      SQLException - if anything goes wrong
    • lastReceivedLsn

      Lsn lastReceivedLsn()
      Returns the value for the latest server received LSN during a read operation. The value is always updated once messages are read via the
      invalid reference
      ReplicationConnection#startStreaming()
      or
      invalid reference
      ReplicationConnection#startStreaming(Long)
      methods.
      Returns:
      a Long value, possibly null if this is called before anything has been read
    • startLsn

      Lsn startLsn()
      Returns the value for the LSN form which the streaming is executed.
      Returns:
      a Long value, possibly null if starting LSN is undefined
    • startKeepAlive

      void startKeepAlive(ExecutorService service)
      Starts a background thread to ensure the slot is kept alive, useful for when temporarily stopping reads from the stream such as querying metadata, etc
    • stopKeepAlive

      void stopKeepAlive()
      Stops the background thread that is used to ensure the slot is kept alive.
    • close

      void close() throws Exception
      //TODO author=Horia Chiorean date=13/10/2016 description=Don't use this for now, because of the bug from the PG server This is stream is closed atm. once the replication connection which created it is closed.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
      See Also:
      • PGReplicationStream.close()