Package org.apache.bookkeeper.discover
Class ZKRegistrationManager
- java.lang.Object
-
- org.apache.bookkeeper.discover.ZKRegistrationManager
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,RegistrationManager
public class ZKRegistrationManager extends java.lang.Object implements RegistrationManager
ZooKeeper BasedRegistrationManager
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.discover.RegistrationManager
RegistrationManager.RegistrationListener
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
bookieReadonlyRegistrationPath
protected java.lang.String
bookieRegistrationPath
-
Constructor Summary
Constructors Constructor Description ZKRegistrationManager(ServerConfiguration conf, org.apache.zookeeper.ZooKeeper zk)
ZKRegistrationManager(ServerConfiguration conf, org.apache.zookeeper.ZooKeeper zk, java.lang.String ledgersRootPath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRegistrationListener(RegistrationManager.RegistrationListener listener)
Add a listener to be triggered when an registration event occurs.protected boolean
checkRegNodeAndWaitExpired(java.lang.String regPath)
Check existence of regPath and wait it expired if possible.void
close()
boolean
format()
Do format boolean.java.lang.String
getClusterInstanceId()
Return the cluster instance id.java.lang.String
getCookiePath(BookieId bookieId)
Returns the CookiePath of the bookie in the ZooKeeper.boolean
initNewCluster()
Initializes new cluster by creating required znodes for the cluster.boolean
isBookieRegistered(BookieId bookieId)
Checks if Bookie with the given BookieId is registered as readwrite or readonly bookie.boolean
nukeExistingCluster()
Nukes existing cluster metadata.boolean
prepareFormat()
Prepare ledgers root node, availableNode, readonly node..Versioned<byte[]>
readCookie(BookieId bookieId)
Read the cookie data, which will be used for verifying the integrity of the bookie environment.void
registerBookie(BookieId bookieId, boolean readOnly, BookieServiceInfo bookieServiceInfo)
Registering the bookie server as bookieId.void
removeCookie(BookieId bookieId, Version version)
Remove the cookie data.(package private) static byte[]
serializeBookieServiceInfo(BookieServiceInfo bookieServiceInfo)
void
unregisterBookie(BookieId bookieId, boolean readOnly)
Unregistering the bookie server as bookieId.void
writeCookie(BookieId bookieId, Versioned<byte[]> cookieData)
Write the cookie data, which will be used for verifying the integrity of the bookie environment.
-
-
-
Constructor Detail
-
ZKRegistrationManager
public ZKRegistrationManager(ServerConfiguration conf, org.apache.zookeeper.ZooKeeper zk)
-
ZKRegistrationManager
public ZKRegistrationManager(ServerConfiguration conf, org.apache.zookeeper.ZooKeeper zk, java.lang.String ledgersRootPath)
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceRegistrationManager
-
getCookiePath
public java.lang.String getCookiePath(BookieId bookieId)
Returns the CookiePath of the bookie in the ZooKeeper.- Parameters:
bookieId
- bookie id- Returns:
-
checkRegNodeAndWaitExpired
protected boolean checkRegNodeAndWaitExpired(java.lang.String regPath) throws java.io.IOException
Check existence of regPath and wait it expired if possible.- Parameters:
regPath
- reg node path.- Returns:
- true if regPath exists, otherwise return false
- Throws:
java.io.IOException
- if can't create reg path
-
registerBookie
public void registerBookie(BookieId bookieId, boolean readOnly, BookieServiceInfo bookieServiceInfo) throws BookieException
Description copied from interface:RegistrationManager
Registering the bookie server as bookieId.- Specified by:
registerBookie
in interfaceRegistrationManager
- Parameters:
bookieId
- bookie idreadOnly
- whether to register it as writable or readonlybookieServiceInfo
- information about services exposed by the Bookie- Throws:
BookieException
- when fail to register a bookie.
-
serializeBookieServiceInfo
static byte[] serializeBookieServiceInfo(BookieServiceInfo bookieServiceInfo)
-
unregisterBookie
public void unregisterBookie(BookieId bookieId, boolean readOnly) throws BookieException
Description copied from interface:RegistrationManager
Unregistering the bookie server as bookieId.- Specified by:
unregisterBookie
in interfaceRegistrationManager
- Parameters:
bookieId
- bookie idreadOnly
- whether to register it as writable or readonly- Throws:
BookieException
- when fail to unregister a bookie.
-
writeCookie
public void writeCookie(BookieId bookieId, Versioned<byte[]> cookieData) throws BookieException
Description copied from interface:RegistrationManager
Write the cookie data, which will be used for verifying the integrity of the bookie environment.- Specified by:
writeCookie
in interfaceRegistrationManager
- Parameters:
bookieId
- bookie idcookieData
- cookie data- Throws:
BookieException
- when fail to write cookie
-
readCookie
public Versioned<byte[]> readCookie(BookieId bookieId) throws BookieException
Description copied from interface:RegistrationManager
Read the cookie data, which will be used for verifying the integrity of the bookie environment.- Specified by:
readCookie
in interfaceRegistrationManager
- Parameters:
bookieId
- bookie id- Returns:
- versioned cookie data
- Throws:
BookieException
- when fail to read cookie
-
removeCookie
public void removeCookie(BookieId bookieId, Version version) throws BookieException
Description copied from interface:RegistrationManager
Remove the cookie data.- Specified by:
removeCookie
in interfaceRegistrationManager
- Parameters:
bookieId
- bookie idversion
- version of the cookie data- Throws:
BookieException
- when fail to remove cookie
-
getClusterInstanceId
public java.lang.String getClusterInstanceId() throws BookieException
Description copied from interface:RegistrationManager
Return the cluster instance id.- Specified by:
getClusterInstanceId
in interfaceRegistrationManager
- Returns:
- the cluster instance id.
- Throws:
BookieException
-
prepareFormat
public boolean prepareFormat() throws java.lang.Exception
Description copied from interface:RegistrationManager
Prepare ledgers root node, availableNode, readonly node..- Specified by:
prepareFormat
in interfaceRegistrationManager
- Returns:
- Returns true if old data exists, false if not.
- Throws:
java.lang.Exception
-
initNewCluster
public boolean initNewCluster() throws java.lang.Exception
Description copied from interface:RegistrationManager
Initializes new cluster by creating required znodes for the cluster. If ledgersrootpath is already existing then it will error out.- Specified by:
initNewCluster
in interfaceRegistrationManager
- Returns:
- returns true if new cluster is successfully created or false if it failed to initialize.
- Throws:
java.lang.Exception
-
nukeExistingCluster
public boolean nukeExistingCluster() throws java.lang.Exception
Description copied from interface:RegistrationManager
Nukes existing cluster metadata.- Specified by:
nukeExistingCluster
in interfaceRegistrationManager
- Returns:
- returns true if cluster metadata is successfully nuked or false if it failed to nuke the cluster metadata.
- Throws:
java.lang.Exception
-
format
public boolean format() throws java.lang.Exception
Description copied from interface:RegistrationManager
Do format boolean.- Specified by:
format
in interfaceRegistrationManager
- Returns:
- Returns true if success do format, false if not.
- Throws:
java.lang.Exception
-
isBookieRegistered
public boolean isBookieRegistered(BookieId bookieId) throws BookieException
Description copied from interface:RegistrationManager
Checks if Bookie with the given BookieId is registered as readwrite or readonly bookie.- Specified by:
isBookieRegistered
in interfaceRegistrationManager
- Parameters:
bookieId
- bookie id- Returns:
- returns true if a bookie with bookieid is currently registered as readwrite or readonly bookie.
- Throws:
BookieException
-
addRegistrationListener
public void addRegistrationListener(RegistrationManager.RegistrationListener listener)
Description copied from interface:RegistrationManager
Add a listener to be triggered when an registration event occurs.- Specified by:
addRegistrationListener
in interfaceRegistrationManager
- Parameters:
listener
- the listener to be added
-
-