Class FileInfo

All Implemented Interfaces:
Recyclable
Direct Known Subclasses:
FileInfoBackingCache.CachedFileInfo, ReadOnlyFileInfo

This is the file handle for a ledger's index file that maps entry ids to location. It is used by LedgerCache.

Ledger index file is made of a header and several fixed-length index pages, which records the offsets of data stored in entry loggers

<header><index pages>
Header is formatted as below:
<magic bytes><len of master key><master key>
  • magic bytes: 4 bytes, 'BKLE', version: 4 bytes
  • len of master key: indicates length of master key. -1 means no master key stored in header.
  • master key: master key
  • state: bit map to indicate the state, 32 bits.
Index page is a fixed-length page, which contains several entries which point to the offsets of data stored in entry loggers.

  • Field Details

  • Constructor Details

  • Method Details

    • getLastAddConfirmed

      Long getLastAddConfirmed()
    • setLastAddConfirmed

      long setLastAddConfirmed(long lac)
    • waitForLastAddConfirmedUpdate

      boolean waitForLastAddConfirmedUpdate(long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher)
    • cancelWaitForLastAddConfirmedUpdate

      void cancelWaitForLastAddConfirmedUpdate(Watcher<LastAddConfirmedUpdateNotification> watcher)
    • isClosed

      public boolean isClosed()
    • getLf

      public File getLf()
    • getSizeSinceLastWrite

      public long getSizeSinceLastWrite()
    • getExplicitLac

      public io.netty.buffer.ByteBuf getExplicitLac()
    • setExplicitLac

      public void setExplicitLac(io.netty.buffer.ByteBuf lac)
    • readHeader

      public void readHeader() throws IOException
      Throws:
      IOException
    • isDeleted

      public boolean isDeleted()
    • checkOpen

      void checkOpen(boolean create) throws IOException
      Throws:
      IOException
    • isFenced

      public boolean isFenced() throws IOException
      Throws:
      IOException
    • setFenced

      public boolean setFenced() throws IOException
      Returns:
      true if set fence succeed, otherwise false when it already fenced or failed to set fenced.
      Throws:
      IOException
    • flushHeader

      public void flushHeader() throws IOException
      Throws:
      IOException
    • size

      public long size() throws IOException
      Throws:
      IOException
    • read

      public int read(ByteBuffer bb, long position, boolean bestEffort) throws IOException
      Throws:
      IOException
    • close

      public void close(boolean force) throws IOException
      Close a file info. Generally, force should be set to true. If set to false metadata will not be flushed and accessing metadata before restart and recovery will be unsafe (since reloading from the index file will cause metadata to be lost). Setting force=false helps avoid expensive file create during shutdown with many dirty ledgers, and is safe because ledger metadata will be recovered before being accessed again.
      Parameters:
      force - if set to true, the index is forced to create before closed, if set to false, the index is not forced to create.
      Throws:
      IOException
    • write

      public long write(ByteBuffer[] buffs, long position) throws IOException
      Throws:
      IOException
    • moveToNewLocation

      public void moveToNewLocation(File newFile, long size) throws IOException
      Copies current file contents upto specified size to the target file and deletes the current file. If size not known then pass size as Long.MAX_VALUE to copy complete file.
      Throws:
      IOException
    • getMasterKey

      public byte[] getMasterKey() throws IOException
      Throws:
      IOException
    • delete

      public boolean delete()
    • isSameFile

      public boolean isSameFile(File f)