Class DigestManager

java.lang.Object
org.apache.bookkeeper.proto.checksum.DigestManager
Direct Known Subclasses:
CRC32CDigestManager, CRC32DigestManager, DummyDigestManager, MacDigestManager

public abstract class DigestManager extends Object
This class takes an entry, attaches a digest to it and packages it with relevant data so that it can be shipped to the bookie. On the return side, it also gets a packet, checks that the digest matches, and extracts the original entry for the packet. Currently 3 types of digests are supported: MAC (based on SHA-1) and CRC32 and CRC32C.
  • Field Details

    • METADATA_LENGTH

      public static final int METADATA_LENGTH
      See Also:
    • LAC_METADATA_LENGTH

      public static final int LAC_METADATA_LENGTH
      See Also:
    • ledgerId

      final long ledgerId
    • useV2Protocol

      final boolean useV2Protocol
    • macCodeLength

      final int macCodeLength
  • Constructor Details

    • DigestManager

      public DigestManager(long ledgerId, boolean useV2Protocol, io.netty.buffer.ByteBufAllocator allocator)
  • Method Details

    • getMacCodeLength

      abstract int getMacCodeLength()
    • internalUpdate

      abstract int internalUpdate(int digest, io.netty.buffer.ByteBuf buffer, int offset, int len)
    • internalUpdate

      abstract int internalUpdate(int digest, byte[] buffer, int offset, int len)
    • update

      final int update(int digest, io.netty.buffer.ByteBuf buffer, int offset, int len)
    • populateValueAndReset

      abstract void populateValueAndReset(int digest, io.netty.buffer.ByteBuf buffer)
    • isInt32Digest

      abstract boolean isInt32Digest()
    • instantiate

      public static DigestManager instantiate(long ledgerId, byte[] passwd, DataFormats.LedgerMetadataFormat.DigestType digestType, io.netty.buffer.ByteBufAllocator allocator, boolean useV2Protocol) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • generateMasterKey

      public static byte[] generateMasterKey(byte[] password) throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException
    • computeDigestAndPackageForSending

      public io.netty.util.ReferenceCounted computeDigestAndPackageForSending(long entryId, long lastAddConfirmed, long length, io.netty.buffer.ByteBuf data, byte[] masterKey, int flags)
      Computes the digest for an entry and put bytes together for sending.
      Parameters:
      entryId -
      lastAddConfirmed -
      length -
      data -
      Returns:
    • computeDigestAndPackageForSendingLac

      public ByteBufList computeDigestAndPackageForSendingLac(long lac)
      Computes the digest for writeLac for sending.
      Parameters:
      lac -
      Returns:
    • verifyDigestAndReturnLac

      public long verifyDigestAndReturnLac(io.netty.buffer.ByteBuf dataReceived) throws BKException.BKDigestMatchException
      Throws:
      BKException.BKDigestMatchException
    • verifyDigestAndReturnData

      public io.netty.buffer.ByteBuf verifyDigestAndReturnData(long entryId, io.netty.buffer.ByteBuf dataReceived) throws BKException.BKDigestMatchException
      Verify that the digest matches and returns the data in the entry.
      Parameters:
      entryId -
      dataReceived -
      Returns:
      Throws:
      BKException.BKDigestMatchException
    • verifyDigestAndReturnLastConfirmed

      public DigestManager.RecoveryData verifyDigestAndReturnLastConfirmed(io.netty.buffer.ByteBuf dataReceived) throws BKException.BKDigestMatchException
      Throws:
      BKException.BKDigestMatchException
    • acceptsMemoryAddressBuffer

      abstract boolean acceptsMemoryAddressBuffer()