Class FileInfo

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

    class FileInfo
    extends Watchable<LastAddConfirmedUpdateNotification>
    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 formated 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 serveral entries which point to the offsets of data stored in entry loggers.

    • Constructor Detail

      • FileInfo

        public FileInfo​(java.io.File lf,
                        byte[] masterKey,
                        int fileInfoVersionToWrite)
                 throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getLastAddConfirmed

        java.lang.Long getLastAddConfirmed()
      • setLastAddConfirmed

        long setLastAddConfirmed​(long lac)
      • isClosed

        public boolean isClosed()
      • getLf

        public java.io.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 java.io.IOException
        Throws:
        java.io.IOException
      • isDeleted

        public boolean isDeleted()
      • checkOpen

        void checkOpen​(boolean create)
                throws java.io.IOException
        Throws:
        java.io.IOException
      • isFenced

        public boolean isFenced()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • setFenced

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

        public void flushHeader()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • size

        public long size()
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer bb,
                        long position,
                        boolean bestEffort)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close​(boolean force)
                   throws java.io.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:
        java.io.IOException
      • write

        public long write​(java.nio.ByteBuffer[] buffs,
                          long position)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • moveToNewLocation

        public void moveToNewLocation​(java.io.File newFile,
                                      long size)
                               throws java.io.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:
        java.io.IOException
      • getMasterKey

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

        public boolean delete()
      • isSameFile

        public boolean isSameFile​(java.io.File f)