Package org.apache.bookkeeper.proto
Class BookieClientImpl
- java.lang.Object
-
- org.apache.bookkeeper.proto.BookieClientImpl
-
- All Implemented Interfaces:
BookieClient,PerChannelBookieClientFactory
public class BookieClientImpl extends java.lang.Object implements BookieClient, PerChannelBookieClientFactory
Implements the client-side part of the BookKeeper protocol.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classBookieClientImpl.ChannelReadyForAddEntryCallback
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.ConcurrentHashMap<BookieId,PerChannelBookieClientPool>channels(package private) static org.slf4j.LoggerLOG-
Fields inherited from interface org.apache.bookkeeper.proto.BookieClient
PENDINGREQ_NOTWRITABLE_MASK
-
-
Constructor Summary
Constructors Constructor Description BookieClientImpl(ClientConfiguration conf, io.netty.channel.EventLoopGroup eventLoopGroup, io.netty.buffer.ByteBufAllocator allocator, OrderedExecutor executor, java.util.concurrent.ScheduledExecutorService scheduler, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEntry(BookieId addr, long ledgerId, byte[] masterKey, long entryId, io.netty.util.ReferenceCounted toSend, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx, int options, boolean allowFastFail, java.util.EnumSet<WriteFlag> writeFlags)Add an entry for ledgerledgerIdon the bookie at addressaddress.voidbatchReadEntries(BookieId address, long ledgerId, long startEntryId, int maxCount, long maxSize, BookkeeperInternalCallbacks.BatchedReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)Batch read entries from bookie at addressaddress.voidclose()Close the bookie client object.PerChannelBookieClientcreate(BookieId address, PerChannelBookieClientPool pcbcPool, SecurityHandlerFactory shFactory, boolean forceUseV3)Create aPerChannelBookieClientto address.voidforceLedger(BookieId addr, long ledgerId, BookkeeperInternalCallbacks.ForceLedgerCallback cb, java.lang.Object ctx)Send a force request to the server.voidgetBookieInfo(BookieId addr, long requested, BookkeeperInternalCallbacks.GetBookieInfoCallback cb, java.lang.Object ctx)Read information about the bookie, from the bookie.java.util.List<BookieId>getFaultyBookies()Get the list of bookies which have exhibited more error responses than a configured threshold.java.util.concurrent.CompletableFuture<AvailabilityOfEntriesOfLedger>getListOfEntriesOfLedger(BookieId address, long ledgerId)Makes async request for getting list of entries of ledger from a bookie and returns Future for the result.longgetNumPendingRequests(BookieId address, long ledgerId)Get the number of outstanding requests on the channel used to connect to a bookie ataddressfor a ledger withledgerId.booleanisClosed()booleanisWritable(BookieId address, long key)Check whether the channel used to write to a bookie channel is writable.PerChannelBookieClientPoollookupClient(BookieId addr)static voidmain(java.lang.String[] args)voidreadEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags)Read entry with a null masterkey, disallowing failfast.voidreadEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey)Read entry, disallowing failfast.voidreadEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)Read an entry from bookie at addressaddress.voidreadEntryWaitForLACUpdate(BookieId addr, long ledgerId, long entryId, long previousLAC, long timeOutInMillis, boolean piggyBackEntry, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx)Send a long poll request to bookie, waiting for the last add confirmed to be updated.voidreadLac(BookieId addr, long ledgerId, BookkeeperInternalCallbacks.ReadLacCallback cb, java.lang.Object ctx)Read the last add confirmed for ledgerledgerIdfrom the bookie ataddress.voidwriteLac(BookieId addr, long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, java.lang.Object ctx)Explicitly write the last add confirmed for ledgerledgerIdto the bookie ataddress.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.bookkeeper.proto.BookieClient
batchReadEntries, batchReadEntries
-
-
-
-
Field Detail
-
LOG
static final org.slf4j.Logger LOG
-
channels
final java.util.concurrent.ConcurrentHashMap<BookieId,PerChannelBookieClientPool> channels
-
-
Constructor Detail
-
BookieClientImpl
public BookieClientImpl(ClientConfiguration conf, io.netty.channel.EventLoopGroup eventLoopGroup, io.netty.buffer.ByteBufAllocator allocator, OrderedExecutor executor, java.util.concurrent.ScheduledExecutorService scheduler, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getFaultyBookies
public java.util.List<BookieId> getFaultyBookies()
Description copied from interface:BookieClientGet the list of bookies which have exhibited more error responses than a configured threshold.- Specified by:
getFaultyBookiesin interfaceBookieClient- Returns:
- the list of faulty bookies
-
isWritable
public boolean isWritable(BookieId address, long key)
Description copied from interface:BookieClientCheck whether the channel used to write to a bookie channel is writable. A channel becomes non-writable when its buffer become full, and will stay non-writable until some of the buffer is cleared.This can be used to apply backpressure. If a channel is not writable, requests will end up queuing.
As as we use pooling, there may be multiple channels per bookie, so we also pass the ledger ID to check the writability of the correct channel.
This has nothing to do with the bookie read-only status.
- Specified by:
isWritablein interfaceBookieClient- Parameters:
address- the address of the bookiekey- the ledger we wish to send a request to
-
getNumPendingRequests
public long getNumPendingRequests(BookieId address, long ledgerId)
Description copied from interface:BookieClientGet the number of outstanding requests on the channel used to connect to a bookie ataddressfor a ledger withledgerId. It is necessary to specify the ledgerId as there may be multiple channels for a single bookie if pooling is in use. If the bookie is notwritable, then theBookieClient.PENDINGREQ_NOTWRITABLE_MASKwill be logically or'd with the returned value.- Specified by:
getNumPendingRequestsin interfaceBookieClient- Parameters:
address- the address of the bookieledgerId- the ledger whose channel we wish to query- Returns:
- the number of requests currently outstanding
-
create
public PerChannelBookieClient create(BookieId address, PerChannelBookieClientPool pcbcPool, SecurityHandlerFactory shFactory, boolean forceUseV3) throws SecurityException
Description copied from interface:PerChannelBookieClientFactoryCreate aPerChannelBookieClientto address.- Specified by:
createin interfacePerChannelBookieClientFactory- Returns:
- the client connected to address.
- Throws:
SecurityException
-
lookupClient
public PerChannelBookieClientPool lookupClient(BookieId addr)
-
forceLedger
public void forceLedger(BookieId addr, long ledgerId, BookkeeperInternalCallbacks.ForceLedgerCallback cb, java.lang.Object ctx)
Description copied from interface:BookieClientSend a force request to the server. When complete all entries which have been written forledgerIdto this bookie will be persisted on disk. This is for use withWriteFlag.DEFERRED_SYNC.- Specified by:
forceLedgerin interfaceBookieClient- Parameters:
addr- the address of the bookieledgerId- the ledger whose entries we want persistedcb- the callback notified when the request completesctx- a context object passed to the callback on completion
-
writeLac
public void writeLac(BookieId addr, long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, java.lang.Object ctx)
Description copied from interface:BookieClientExplicitly write the last add confirmed for ledgerledgerIdto the bookie ataddress.- Specified by:
writeLacin interfaceBookieClient- Parameters:
addr- the address of the bookieledgerId- the ledger whose last add confirm we wish to knowmasterKey- the master key of the ledgerlac- the last add confirmed we wish to writetoSend- a buffer also containing the lac, along with a digestcb- the callback notified when the request completesctx- a context object passed to the callback on completion
-
addEntry
public void addEntry(BookieId addr, long ledgerId, byte[] masterKey, long entryId, io.netty.util.ReferenceCounted toSend, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx, int options, boolean allowFastFail, java.util.EnumSet<WriteFlag> writeFlags)
Description copied from interface:BookieClientAdd an entry for ledgerledgerIdon the bookie at addressaddress.- Specified by:
addEntryin interfaceBookieClient- Parameters:
addr- the address of the bookieledgerId- the ledger to which we wish to add the entryentryId- the id of the entry we wish to addtoSend- a buffer containing the entry and its digestcb- the callback notified when the request completesctx- a context object passed to the callback on completionoptions- a bit mask of flags from BookieProtocol.FLAG_*BookieProtocolallowFastFail- fail the add immediately if the channel is non-writableBookieClient.isWritable(BookieId,long)writeFlags- a set of write flagsWriteFlag
-
getListOfEntriesOfLedger
public java.util.concurrent.CompletableFuture<AvailabilityOfEntriesOfLedger> getListOfEntriesOfLedger(BookieId address, long ledgerId)
Description copied from interface:BookieClientMakes async request for getting list of entries of ledger from a bookie and returns Future for the result.- Specified by:
getListOfEntriesOfLedgerin interfaceBookieClient- Parameters:
address- BookieId of the bookieledgerId- ledgerId- Returns:
- returns Future
-
readLac
public void readLac(BookieId addr, long ledgerId, BookkeeperInternalCallbacks.ReadLacCallback cb, java.lang.Object ctx)
Description copied from interface:BookieClientRead the last add confirmed for ledgerledgerIdfrom the bookie ataddress.- Specified by:
readLacin interfaceBookieClient- Parameters:
addr- the address of the bookieledgerId- the ledger whose last add confirm we wish to knowcb- the callback notified when the request completesctx- a context object passed to the callback on completion
-
readEntry
public void readEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags)
Description copied from interface:BookieClientRead entry with a null masterkey, disallowing failfast.- Specified by:
readEntryin interfaceBookieClient- See Also:
BookieClient.readEntry(BookieId,long,long,ReadEntryCallback,Object,int,byte[],boolean)
-
readEntry
public void readEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey)
Description copied from interface:BookieClientRead entry, disallowing failfast.- Specified by:
readEntryin interfaceBookieClient- See Also:
BookieClient.readEntry(BookieId,long,long,ReadEntryCallback,Object,int,byte[],boolean)
-
readEntry
public void readEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)
Description copied from interface:BookieClientRead an entry from bookie at addressaddress.- Specified by:
readEntryin interfaceBookieClient- Parameters:
addr- address of the bookie to read fromledgerId- id of the ledger the entry belongs toentryId- id of the entry we wish to readcb- the callback notified when the request completesctx- a context object passed to the callback on completionflags- a bit mask of flags from BookieProtocol.FLAG_*BookieProtocolmasterKey- the master key of the ledger being read from. This is only required if the FLAG_DO_FENCING is specified.allowFastFail- fail the read immediately if the channel is non-writableBookieClient.isWritable(BookieId,long)
-
batchReadEntries
public void batchReadEntries(BookieId address, long ledgerId, long startEntryId, int maxCount, long maxSize, BookkeeperInternalCallbacks.BatchedReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)
Description copied from interface:BookieClientBatch read entries from bookie at addressaddress.- Specified by:
batchReadEntriesin interfaceBookieClient- Parameters:
address- address of the bookie to read fromledgerId- id of the ledger the entry belongs tostartEntryId- id of the entry startedmaxCount- the total entries count in this batchmaxSize- the total entries size in this batchcb- the callback notified when the request completesctx- a context object passed to the callback on completionflags- a bit mask of flags from BookieProtocol.FLAG_*BookieProtocolmasterKey- the master key of the ledger being read from. This is only required if the FLAG_DO_FENCING is specified.allowFastFail- fail the read immediately if the channel is non-writableBookieClient.isWritable(BookieId,long)
-
readEntryWaitForLACUpdate
public void readEntryWaitForLACUpdate(BookieId addr, long ledgerId, long entryId, long previousLAC, long timeOutInMillis, boolean piggyBackEntry, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx)
Description copied from interface:BookieClientSend a long poll request to bookie, waiting for the last add confirmed to be updated. The client can also request that the full entry is returned with the new last add confirmed.- Specified by:
readEntryWaitForLACUpdatein interfaceBookieClient- Parameters:
addr- address of bookie to send the long poll address toledgerId- ledger whose last add confirmed we are interested inentryId- the id of the entry we expect to readpreviousLAC- the previous lac valuetimeOutInMillis- number of millis to wait for LAC updatepiggyBackEntry- whether to read the requested entry when LAC is updatedcb- the callback notified when the request completesctx- a context object passed to the callback on completion
-
getBookieInfo
public void getBookieInfo(BookieId addr, long requested, BookkeeperInternalCallbacks.GetBookieInfoCallback cb, java.lang.Object ctx)
Description copied from interface:BookieClientRead information about the bookie, from the bookie.- Specified by:
getBookieInfoin interfaceBookieClient- Parameters:
addr- the address of the bookie to request information fromrequested- a bitset specifying which pieces of information to requestBookkeeperProtocol.GetBookieInfoRequestcb- the callback notified when the request completesctx- a context object passed to the callback on completion- See Also:
BookieInfoReader.BookieInfo
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceBookieClient- Returns:
- whether bookie client object has been closed
-
close
public void close()
Description copied from interface:BookieClientClose the bookie client object.- Specified by:
closein interfaceBookieClient
-
main
public static void main(java.lang.String[] args) throws java.lang.NumberFormatException, java.io.IOException, java.lang.InterruptedException- Parameters:
args-- Throws:
java.io.IOExceptionjava.lang.NumberFormatExceptionjava.lang.InterruptedException
-
-