Class WriteCache

java.lang.Object
org.apache.bookkeeper.bookie.storage.ldb.WriteCache
All Implemented Interfaces:
Closeable, AutoCloseable

public class WriteCache extends Object implements 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 
    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)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static int
    align64(int size)
     
    void
     
    void
     
    long
     
    void
    deleteLedger(long ledgerId)
     
    void
     
    io.netty.buffer.ByteBuf
    get(long ledgerId, long entryId)
     
    io.netty.buffer.ByteBuf
    getLastEntry(long ledgerId)
     
    boolean
    hasEntry(long ledgerId, long entryId)
     
    boolean
     
    boolean
    put(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry)
     
    long
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WriteCache

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

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

    • clear

      public void clear()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface 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 IOException
      Throws:
      IOException
    • size

      public long size()
    • count

      public long count()
    • isEmpty

      public boolean isEmpty()
    • align64

      static int align64(int size)