Class LedgerMetadataImpl

  • All Implemented Interfaces:
    LedgerMetadata

    class LedgerMetadataImpl
    extends java.lang.Object
    implements LedgerMetadata
    This class encapsulates all the ledger metadata that is persistently stored in metadata store.

    It provides parsing and serialization methods of such metadata.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static org.slf4j.Logger LOG  
      (package private) boolean storeCtime  
    • Constructor Summary

      Constructors 
      Constructor Description
      LedgerMetadataImpl​(long ledgerId, int metadataFormatVersion, int ensembleSize, int writeQuorumSize, int ackQuorumSize, LedgerMetadata.State state, java.util.Optional<java.lang.Long> lastEntryId, java.util.Optional<java.lang.Long> length, java.util.Map<java.lang.Long,​java.util.List<BookieId>> ensembles, java.util.Optional<DigestType> digestType, java.util.Optional<byte[]> password, long ctime, boolean storeCtime, long cToken, java.util.Map<java.lang.String,​byte[]> customMetadata)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean canEqual​(java.lang.Object other)  
      boolean equals​(java.lang.Object o)  
      int getAckQuorumSize()
      Returns the ack quorum size of this ledger.
      java.util.NavigableMap<java.lang.Long,​? extends java.util.List<BookieId>> getAllEnsembles()
      Returns all the ensembles of this ledger.
      long getCtime()
      Returns the creation timestamp of this ledger.
      long getCToken()
      Get the unique creator token of the Ledger.
      java.util.Map<java.lang.String,​byte[]> getCustomMetadata()
      Returns the custom metadata stored with the ledgers.
      DigestType getDigestType()
      Returns the digest type used by this ledger.
      java.util.List<BookieId> getEnsembleAt​(long entryId)
      Returns the ensemble at the given entryId.
      int getEnsembleSize()
      Returns the ensemble size of this ledger.
      long getLastEntryId()
      Returns the last entry id of this ledger.
      long getLedgerId()
      Returns the id of this ledger.
      long getLength()
      Returns the length of this ledger.
      int getMetadataFormatVersion()
      Get the format version which should be used to serialize the metadata.
      byte[] getPassword()
      Get the password for the ledger.
      LedgerMetadata.State getState()
      Returns the state of the metadata.
      int getWriteQuorumSize()
      Returns the write quorum size of this ledger.
      int hashCode()  
      boolean hasPassword()
      In versions 4.1.0 and below, the digest type and password were not stored in the metadata.
      boolean isClosed()
      Returns whether the ledger is sealed or not.
      (package private) boolean shouldStoreCtime()  
      java.lang.String toSafeString()
      Returns a string representation of this LedgerMetadata object by filtering out the password field.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • LOG

        static final org.slf4j.Logger LOG
      • storeCtime

        final boolean storeCtime
    • Constructor Detail

      • LedgerMetadataImpl

        LedgerMetadataImpl​(long ledgerId,
                           int metadataFormatVersion,
                           int ensembleSize,
                           int writeQuorumSize,
                           int ackQuorumSize,
                           LedgerMetadata.State state,
                           java.util.Optional<java.lang.Long> lastEntryId,
                           java.util.Optional<java.lang.Long> length,
                           java.util.Map<java.lang.Long,​java.util.List<BookieId>> ensembles,
                           java.util.Optional<DigestType> digestType,
                           java.util.Optional<byte[]> password,
                           long ctime,
                           boolean storeCtime,
                           long cToken,
                           java.util.Map<java.lang.String,​byte[]> customMetadata)
    • Method Detail

      • getLedgerId

        public long getLedgerId()
        Description copied from interface: LedgerMetadata
        Returns the id of this ledger.
        Specified by:
        getLedgerId in interface LedgerMetadata
        Returns:
        the id of this ledger.
      • getAllEnsembles

        public java.util.NavigableMap<java.lang.Long,​? extends java.util.List<BookieId>> getAllEnsembles()
        Description copied from interface: LedgerMetadata
        Returns all the ensembles of this ledger.
        Specified by:
        getAllEnsembles in interface LedgerMetadata
        Returns:
        all the ensembles of this ledger.
      • getEnsembleSize

        public int getEnsembleSize()
        Description copied from interface: LedgerMetadata
        Returns the ensemble size of this ledger.
        Specified by:
        getEnsembleSize in interface LedgerMetadata
        Returns:
        the ensemble size of this ledger.
      • getWriteQuorumSize

        public int getWriteQuorumSize()
        Description copied from interface: LedgerMetadata
        Returns the write quorum size of this ledger.
        Specified by:
        getWriteQuorumSize in interface LedgerMetadata
        Returns:
        the write quorum size of this ledger.
      • getAckQuorumSize

        public int getAckQuorumSize()
        Description copied from interface: LedgerMetadata
        Returns the ack quorum size of this ledger.
        Specified by:
        getAckQuorumSize in interface LedgerMetadata
        Returns:
        the ack quorum size of this ledger.
      • getCtime

        public long getCtime()
        Description copied from interface: LedgerMetadata
        Returns the creation timestamp of this ledger.
        Specified by:
        getCtime in interface LedgerMetadata
        Returns:
        the creation timestamp of this ledger.
      • hasPassword

        public boolean hasPassword()
        In versions 4.1.0 and below, the digest type and password were not stored in the metadata.
        Specified by:
        hasPassword in interface LedgerMetadata
        Returns:
        whether the password has been stored in the metadata
      • getPassword

        public byte[] getPassword()
        Description copied from interface: LedgerMetadata
        Get the password for the ledger. For ledgers created with version 4.1.0 or older, an empty byte array is returned.
        Specified by:
        getPassword in interface LedgerMetadata
        Returns:
        the password for the ledger.
      • getDigestType

        public DigestType getDigestType()
        Description copied from interface: LedgerMetadata
        Returns the digest type used by this ledger. May return null if the ledger was created with version 4.1.0 or below.
        Specified by:
        getDigestType in interface LedgerMetadata
        Returns:
        the digest type used by this ledger.
      • getLastEntryId

        public long getLastEntryId()
        Description copied from interface: LedgerMetadata
        Returns the last entry id of this ledger.

        If this ledger is not sealed LedgerMetadata.isClosed(), it returns -1L.

        Specified by:
        getLastEntryId in interface LedgerMetadata
        Returns:
        the last entry id of this ledger if it is sealed, otherwise -1.
      • getLength

        public long getLength()
        Description copied from interface: LedgerMetadata
        Returns the length of this ledger.

        If this ledger is not sealed LedgerMetadata.isClosed(), it returns 0.

        Specified by:
        getLength in interface LedgerMetadata
        Returns:
        the length of this ledger if it is sealed, otherwise 0.
      • isClosed

        public boolean isClosed()
        Description copied from interface: LedgerMetadata
        Returns whether the ledger is sealed or not.
        Specified by:
        isClosed in interface LedgerMetadata
        Returns:
        true if the ledger is sealed, otherwise false.
      • getEnsembleAt

        public java.util.List<BookieId> getEnsembleAt​(long entryId)
        Description copied from interface: LedgerMetadata
        Returns the ensemble at the given entryId.
        Specified by:
        getEnsembleAt in interface LedgerMetadata
        Parameters:
        entryId - the entry id to retrieve its ensemble information
        Returns:
        the ensemble which contains the given entryId.
      • getCustomMetadata

        public java.util.Map<java.lang.String,​byte[]> getCustomMetadata()
        Description copied from interface: LedgerMetadata
        Returns the custom metadata stored with the ledgers.
        Specified by:
        getCustomMetadata in interface LedgerMetadata
        Returns:
        the custom metadata stored with the ledgers.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toSafeString

        public java.lang.String toSafeString()
        Returns a string representation of this LedgerMetadata object by filtering out the password field.
        Specified by:
        toSafeString in interface LedgerMetadata
        Returns:
        a string representation of the object without password field in it.
      • getMetadataFormatVersion

        public int getMetadataFormatVersion()
        Description copied from interface: LedgerMetadata
        Get the format version which should be used to serialize the metadata.
        Specified by:
        getMetadataFormatVersion in interface LedgerMetadata
        Returns:
        the format version.
      • shouldStoreCtime

        boolean shouldStoreCtime()
      • getCToken

        public long getCToken()
        Description copied from interface: LedgerMetadata
        Get the unique creator token of the Ledger.
        Specified by:
        getCToken in interface LedgerMetadata
        Returns:
        the creator token
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • canEqual

        protected boolean canEqual​(java.lang.Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object