Class FileDurableLog

java.lang.Object
org.j7m.middleware.durablelog.FileDurableLog
All Implemented Interfaces:
AutoCloseable, org.j7m.middleware.api.durablelog.DurableLog

public final class FileDurableLog extends Object implements org.j7m.middleware.api.durablelog.DurableLog
File-backed append-only durable log.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a log using validated configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.j7m.middleware.api.durablelog.LogAppendResult
    append(org.j7m.middleware.api.durablelog.LogStreamId stream, List<org.j7m.middleware.api.durablelog.LogRecord> records, org.j7m.middleware.api.durablelog.AppendOptions options)
    void
    Returns config for tests and diagnostics.
    org.j7m.middleware.api.durablelog.LogSnapshot
    createSnapshot(org.j7m.middleware.api.durablelog.LogStreamId stream, org.j7m.middleware.api.durablelog.SnapshotOptions options)
    Optional<org.j7m.middleware.api.durablelog.LogOffset>
    findLatestOffsetByMetadata(org.j7m.middleware.api.durablelog.LogStreamId stream, String metadataKey, String metadataValue, int maxRecordsExamined)
    Finds the latest record offset in a stream whose header metadata contains the supplied key and value while examining at most a bounded number of records.
    org.j7m.middleware.api.durablelog.LogCursor
    openCursor(org.j7m.middleware.api.durablelog.LogStreamId stream, org.j7m.middleware.api.durablelog.LogOffset offset, org.j7m.middleware.api.durablelog.CursorOptions options)
    org.j7m.middleware.api.durablelog.LogRecoveryReport
    recover(org.j7m.middleware.api.durablelog.RecoveryOptions options)
    org.j7m.middleware.api.durablelog.LogStatus

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileDurableLog

      public FileDurableLog(DurableLogConfig config)
      Creates a log using validated configuration.
      Parameters:
      config - durable-log configuration
  • Method Details

    • append

      public org.j7m.middleware.api.durablelog.LogAppendResult append(org.j7m.middleware.api.durablelog.LogStreamId stream, List<org.j7m.middleware.api.durablelog.LogRecord> records, org.j7m.middleware.api.durablelog.AppendOptions options)
      Specified by:
      append in interface org.j7m.middleware.api.durablelog.DurableLog
    • openCursor

      public org.j7m.middleware.api.durablelog.LogCursor openCursor(org.j7m.middleware.api.durablelog.LogStreamId stream, org.j7m.middleware.api.durablelog.LogOffset offset, org.j7m.middleware.api.durablelog.CursorOptions options)
      Specified by:
      openCursor in interface org.j7m.middleware.api.durablelog.DurableLog
    • createSnapshot

      public org.j7m.middleware.api.durablelog.LogSnapshot createSnapshot(org.j7m.middleware.api.durablelog.LogStreamId stream, org.j7m.middleware.api.durablelog.SnapshotOptions options)
      Specified by:
      createSnapshot in interface org.j7m.middleware.api.durablelog.DurableLog
    • recover

      public org.j7m.middleware.api.durablelog.LogRecoveryReport recover(org.j7m.middleware.api.durablelog.RecoveryOptions options)
      Specified by:
      recover in interface org.j7m.middleware.api.durablelog.DurableLog
    • status

      public org.j7m.middleware.api.durablelog.LogStatus status()
      Specified by:
      status in interface org.j7m.middleware.api.durablelog.DurableLog
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface org.j7m.middleware.api.durablelog.DurableLog
    • config

      public DurableLogConfig config()
      Returns config for tests and diagnostics.
      Returns:
      durable-log configuration
    • findLatestOffsetByMetadata

      public Optional<org.j7m.middleware.api.durablelog.LogOffset> findLatestOffsetByMetadata(org.j7m.middleware.api.durablelog.LogStreamId stream, String metadataKey, String metadataValue, int maxRecordsExamined)
      Finds the latest record offset in a stream whose header metadata contains the supplied key and value while examining at most a bounded number of records.

      This operation is intended for bounded local recovery of higher-level services that publish authoritative checkpoint records. It scans the in-memory index in reverse order and reads only the fixed frame header and metadata prefix until a matching header is found or maxRecordsExamined records have been inspected. The method does not allocate, copy, interpret, or checksum payload bytes; full-frame checksum validation is performed by normal recovery and cursor reads. The returned offset is stable until retention removes the corresponding segment; callers that need replay from the offset should open a cursor promptly.

      Specified by:
      findLatestOffsetByMetadata in interface org.j7m.middleware.api.durablelog.DurableLog
      Parameters:
      stream - stream to inspect
      metadataKey - required metadata key
      metadataValue - required metadata value
      maxRecordsExamined - hard upper bound on inspected records
      Returns:
      latest matching offset, or empty when no record matches
      Throws:
      org.j7m.middleware.api.durablelog.DurableLogException - when the log is closed, arguments are invalid, or the underlying segment cannot be read