Class LogAggregatorWriterStandard

java.lang.Object
com.illumon.iris.db.v2.logaggregator.LogAggregatorWriterStandard
All Implemented Interfaces:
SinglePartitionWriter, Closeable, AutoCloseable

public final class LogAggregatorWriterStandard extends Object implements SinglePartitionWriter
Write binary rows to a log aggregation service. This implementation is for column partition values that are not determined by row-level data. They may still change, for example based on the current date.
After construction, this will contain an authenticated and accepted connection to the LAS for the given identifiers. If the channel connection is broken, attempts will be made to reconnect. Once either the client or server requests/indicates termination, or the client initiates a terminating command, the connection will be permanently closed.
This object is expected to be used by a single thread. Synchronization is to ensure that multiple commands don't occur at the same time, and to ensure that we don't close and check connections at the same time.
  • Field Details

  • Constructor Details

    • LogAggregatorWriterStandard

      public LogAggregatorWriterStandard(@NotNull @NotNull ByteBuffer header, @NotNull @NotNull com.fishlib.io.logger.Logger log, @NotNull @NotNull InetSocketAddress serverAddress, @NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull TableIdentifier.NamespaceSet namespaceSet, @NotNull @NotNull String internalPartition, @NotNull @NotNull String columnPartition, TokenFactoryFactory tokenFactorySource) throws IOException
      Parameters:
      header -
      log - the Logger instance
      serverAddress - the LAS server's address
      namespace - the namespace
      tableName - the table name
      namespaceSet - the namespace set
      internalPartition - the internal partition
      columnPartition - the column partition; if NULL_PARTITION is specified, then the current date column partition factory will be used to determine column partition values
      tokenFactorySource - a token source for authentication
      Throws:
      IOException - from initialization
    • LogAggregatorWriterStandard

      public LogAggregatorWriterStandard(@NotNull @NotNull ByteBuffer header, @NotNull @NotNull com.fishlib.io.logger.Logger log, @NotNull @NotNull InetSocketAddress serverAddress, @NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull TableIdentifier.NamespaceSet namespaceSet, @NotNull @NotNull String internalPartition, @NotNull @NotNull String columnPartition, ZoneId zoneId, TokenFactoryFactory tokenFactorySource, @Nullable @Nullable BiFunction<String,ZoneId,ExpirationManager<String>> columnPartitionFactory) throws IOException
      Create a BinaryStoreAggregatorWriterStandard for the specified time zone. This is for a specific table location (i.e. namespace/table name/namespace set/internal partition), with column partition values either specified explicitly or determined by a current-date column partition factory.
      Parameters:
      header -
      log - the Logger instance
      serverAddress - the LAS server's address
      namespace - the namespace
      tableName - the table name
      namespaceSet - the namespace set
      internalPartition - the internal partition
      columnPartition - the column partition; if NULL_PARTITION is specified, then the current date column partition factory will be used to determine column partition values
      zoneId - the time zone ID for standard partition determination, or null to use the system default zone
      tokenFactorySource - a token source for authentication
      Throws:
      IOException - from initialization
  • Method Details

    • getChannel

      @NotNull public @NotNull GatheringByteChannel getChannel() throws IOException
      Open a channel to the Log Aggregator Service and initialize it with table identifiers and binary header. This getChannel implementation only works for standard-column-partition-determination instances.
      Returns:
      non-null, open channel to the server, else an exception
      Throws:
      IOException
    • close

      public void close() throws IOException
      Send FLUSH message, poll for ACK, CLIENT_FINISHED message, poll for an ACK and close the channel.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface SinglePartitionWriter
      Throws:
      IOException - if an error occurred while closing this writer
    • flush

      public void flush() throws IOException
      Throws:
      IOException
    • sendDeletePartition

      public void sendDeletePartition() throws IOException
      Send a command message to the Log Aggregator, requesting that the current partition be deleted. The connection will be closed by the server, no further data or commands are allowed.
      Throws:
      IOException
    • makeColumnPartitionFactory

      protected static ExpirationManager<String> makeColumnPartitionFactory(String columnPartition, ZoneId zoneid)
      Injection point for testing.
      Parameters:
      columnPartition - the column partition passed into the caller, or NULL_PARTITION if the partition should be determined by the date
      zoneid - the ZoneId needed to create a DailyExpiration
      Returns:
      an ExpirationManager appropriate to the member variables
    • writeDataToPartition

      public void writeDataToPartition(int numRows, @NotNull @NotNull ByteBuffer buffer) throws IOException
      Description copied from interface: SinglePartitionWriter
      Write all the row data to the partition.

      A write operation will return only after writing all the bytes, with the buffer's position moved to its limit.

      On error, the buffer's position will have been updated to account for the data that was successfully written; though, it is not safe to reuse this interface in an attempt to re-write the data (given the stateful nature of this interface).

      This is not meant to be called by third parties; the signature and documentation for this method is subject to change at any time.

      This method is not guaranteed to be thread-safe. The assumption is that the caller only calls this method from exactly one thread, or uses concurrency control primitives that create a happens-before barrier between calls.

      Specified by:
      writeDataToPartition in interface SinglePartitionWriter
      Parameters:
      numRows - the number of rows represented in buffer, must be positive
      buffer - the buffer to write
      Throws:
      IOException - if an IO error occurred