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.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.ConcurrentHashMap<BookieId,PerChannelBookieClientPool>
channels
(package private) static org.slf4j.Logger
LOG
-
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 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)
Add an entry for ledgerledgerId
on the bookie at addressaddress
.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)
Batch read entries from bookie at addressaddress
.void
close()
Close the bookie client object.PerChannelBookieClient
create(BookieId address, PerChannelBookieClientPool pcbcPool, SecurityHandlerFactory shFactory, boolean forceUseV3)
Create aPerChannelBookieClient
to address.void
forceLedger(BookieId addr, long ledgerId, BookkeeperInternalCallbacks.ForceLedgerCallback cb, java.lang.Object ctx)
Send a force request to the server.void
getBookieInfo(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.long
getNumPendingRequests(BookieId address, long ledgerId)
Get the number of outstanding requests on the channel used to connect to a bookie ataddress
for a ledger withledgerId
.boolean
isClosed()
boolean
isWritable(BookieId address, long key)
Check whether the channel used to write to a bookie channel is writable.PerChannelBookieClientPool
lookupClient(BookieId addr)
static void
main(java.lang.String[] args)
void
readEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags)
Read entry with a null masterkey, disallowing failfast.void
readEntry(BookieId addr, long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey)
Read entry, disallowing failfast.void
readEntry(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
.void
readEntryWaitForLACUpdate(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.void
readLac(BookieId addr, long ledgerId, BookkeeperInternalCallbacks.ReadLacCallback cb, java.lang.Object ctx)
Read the last add confirmed for ledgerledgerId
from the bookie ataddress
.void
writeLac(BookieId addr, long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, java.lang.Object ctx)
Explicitly write the last add confirmed for ledgerledgerId
to 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:BookieClient
Get the list of bookies which have exhibited more error responses than a configured threshold.- Specified by:
getFaultyBookies
in interfaceBookieClient
- Returns:
- the list of faulty bookies
-
isWritable
public boolean isWritable(BookieId address, long key)
Description copied from interface:BookieClient
Check 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:
isWritable
in 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:BookieClient
Get the number of outstanding requests on the channel used to connect to a bookie ataddress
for 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_MASK
will be logically or'd with the returned value.- Specified by:
getNumPendingRequests
in 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:PerChannelBookieClientFactory
Create aPerChannelBookieClient
to address.- Specified by:
create
in 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:BookieClient
Send a force request to the server. When complete all entries which have been written forledgerId
to this bookie will be persisted on disk. This is for use withWriteFlag.DEFERRED_SYNC
.- Specified by:
forceLedger
in 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:BookieClient
Explicitly write the last add confirmed for ledgerledgerId
to the bookie ataddress
.- Specified by:
writeLac
in 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:BookieClient
Add an entry for ledgerledgerId
on the bookie at addressaddress
.- Specified by:
addEntry
in 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_*BookieProtocol
allowFastFail
- 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:BookieClient
Makes async request for getting list of entries of ledger from a bookie and returns Future for the result.- Specified by:
getListOfEntriesOfLedger
in 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:BookieClient
Read the last add confirmed for ledgerledgerId
from the bookie ataddress
.- Specified by:
readLac
in 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:BookieClient
Read entry with a null masterkey, disallowing failfast.- Specified by:
readEntry
in 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:BookieClient
Read entry, disallowing failfast.- Specified by:
readEntry
in 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:BookieClient
Read an entry from bookie at addressaddress
.- Specified by:
readEntry
in 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_*BookieProtocol
masterKey
- 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:BookieClient
Batch read entries from bookie at addressaddress
.- Specified by:
batchReadEntries
in 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_*BookieProtocol
masterKey
- 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:BookieClient
Send 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:
readEntryWaitForLACUpdate
in 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:BookieClient
Read information about the bookie, from the bookie.- Specified by:
getBookieInfo
in interfaceBookieClient
- Parameters:
addr
- the address of the bookie to request information fromrequested
- a bitset specifying which pieces of information to requestBookkeeperProtocol.GetBookieInfoRequest
cb
- 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:
isClosed
in interfaceBookieClient
- Returns:
- whether bookie client object has been closed
-
close
public void close()
Description copied from interface:BookieClient
Close the bookie client object.- Specified by:
close
in 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.IOException
java.lang.NumberFormatException
java.lang.InterruptedException
-
-