All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
DiskTierProducerAgent, MemoryTierProducerAgent, RemoteTierProducerAgent

public interface TierProducerAgent extends AutoCloseable
The producer-side agent of a Tier.

Note that when writing a buffer to a tier, the TierProducerAgent should first call tryStartNewSegment to start a new segment. The agent can then continue writing the buffer to the tier as long as the return value of write is true. If the return value of write is false, it indicates that the current segment can no longer store the buffer, and the agent should try to start a new segment before writing the buffer.

  • Method Details

    • tryStartNewSegment

      boolean tryStartNewSegment(TieredStorageSubpartitionId subpartitionId, int segmentId, int minNumBuffers)
      Try to start a new segment in the Tier.
      Parameters:
      subpartitionId - subpartition id that the new segment belongs to
      segmentId - id of the new segment
      minNumBuffers - the minimum number of buffers that are expected to be written to the newly created segment.
      Returns:
      true if the segment can be started, false otherwise.
    • tryWrite

      boolean tryWrite(TieredStorageSubpartitionId subpartitionId, Buffer finishedBuffer, Object bufferOwner, int numRemainingConsecutiveBuffers)
      Writes the finished Buffer to the consumer.

      Note that the method is successfully executed (without throwing any exception), the buffer should be released by the caller, otherwise the tier should be responsible to recycle the buffer.

      Parameters:
      subpartitionId - the subpartition id that the buffer is writing to
      finishedBuffer - the writing buffer
      bufferOwner - the current owner of this writing buffer
      numRemainingConsecutiveBuffers - number of buffers that would be passed in the following invocations and should be written to the same segment as this one
      Returns:
      return true if the buffer is written successfully, return false if the current segment can not store this buffer(and the following consecutive ones) and the current segment is finished. When returning false, the agent should try start a new segment before writing the buffer.
    • close

      void close()
      Close the agent.

      Note this only releases resources directly hold by the agent, which excludes resources managed by the resource registry.

      Specified by:
      close in interface AutoCloseable