Class WriteCache

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class WriteCache
    extends java.lang.Object
    implements java.io.Closeable
    Write cache implementation.

    The write cache will allocate the requested size from direct memory and it will break it down into multiple segments.

    The entries are appended in a common buffer and indexed though a hashmap, until the cache is cleared.

    There is the possibility to iterate through the stored entries in an ordered way, by (ledgerId, entry).

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  WriteCache.EntryConsumer
      Consumer that is used to scan the entire write cache.
    • Constructor Summary

      Constructors 
      Constructor Description
      WriteCache​(io.netty.buffer.ByteBufAllocator allocator, long maxCacheSize)  
      WriteCache​(io.netty.buffer.ByteBufAllocator allocator, long maxCacheSize, int maxSegmentSize)  
    • Constructor Detail

      • WriteCache

        public WriteCache​(io.netty.buffer.ByteBufAllocator allocator,
                          long maxCacheSize)
      • WriteCache

        public WriteCache​(io.netty.buffer.ByteBufAllocator allocator,
                          long maxCacheSize,
                          int maxSegmentSize)
    • Method Detail

      • clear

        public void clear()
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • put

        public boolean put​(long ledgerId,
                           long entryId,
                           io.netty.buffer.ByteBuf entry)
      • get

        public io.netty.buffer.ByteBuf get​(long ledgerId,
                                           long entryId)
      • hasEntry

        public boolean hasEntry​(long ledgerId,
                                long entryId)
      • getLastEntry

        public io.netty.buffer.ByteBuf getLastEntry​(long ledgerId)
      • deleteLedger

        public void deleteLedger​(long ledgerId)
      • forEach

        public void forEach​(WriteCache.EntryConsumer consumer)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • size

        public long size()
      • count

        public long count()
      • isEmpty

        public boolean isEmpty()
      • align64

        static int align64​(int size)