Package org.apache.bookkeeper.bookie
Class Cookie
java.lang.Object
org.apache.bookkeeper.bookie.Cookie
When a bookie starts for the first time it generates a cookie, and stores
the cookie in registration manager as well as in the each of the local filesystem
directories it uses. This cookie is used to ensure that for the life of the
bookie, its configuration stays the same. If any of the bookie directories
becomes unavailable, the bookie becomes unavailable. If the bookie changes
port, it must also reset all of its data.
This is done to ensure data integrity. Without the cookie a bookie could
start with one of its ledger directories missing, so data would be missing,
but the bookie would be up, so the client would think that everything is ok
with the cluster. It's better to fail early and obviously.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteFromRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version) Deletes cookie from registration manager.voiddeleteFromRegistrationManager(RegistrationManager rm, BookieId address, Version version) Delete cookie from registration manager.static StringencodeDirPaths(String[] dirs) booleanstatic Cookie.BuilderGenerate cookie from the given configuration.(package private) String[](package private) String[]inthashCode()booleanCheck whether the 'bookieHost' was created using a hostname or an IP address.static Cookie.BuilderReturns Cookie builder.static Cookie.BuildernewBuilder(Cookie oldCookie) Returns Cookie builder with the copy of given oldCookie.static CookieparseFromBytes(byte[] bytes) static CookiereadFromDirectory(File directory) Returns cookie from the given directory.Read cookie from registration manager.readFromRegistrationManager(RegistrationManager rm, BookieId address) Read cookie from registration manager for a given bookie address.toString()voidvoidvoidwriteToDirectory(File directory) voidwriteToFile(File versionFile) voidwriteToRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version) Writes cookie details to registration manager.
-
Field Details
-
CURRENT_COOKIE_LAYOUT_VERSION
static final int CURRENT_COOKIE_LAYOUT_VERSION- See Also:
-
-
Method Details
-
encodeDirPaths
-
getLedgerDirPathsFromCookie
String[] getLedgerDirPathsFromCookie() -
getIndexDirPathsFromCookie
String[] getIndexDirPathsFromCookie() -
verify
-
verifyIsSuperSet
-
toString
-
parseFromBytes
- Throws:
IOException
-
writeToDirectory
- Throws:
IOException
-
writeToFile
- Throws:
IOException
-
writeToRegistrationManager
public void writeToRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version) throws BookieException Writes cookie details to registration manager.- Parameters:
rm- registration managerconf- configurationversion- version- Throws:
BookieException- when fail to write the cookie.
-
deleteFromRegistrationManager
public void deleteFromRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version) throws BookieException Deletes cookie from registration manager.- Parameters:
rm- registration managerconf- configurationversion- cookie version- Throws:
BookieException- when fail to delete cookie.
-
deleteFromRegistrationManager
public void deleteFromRegistrationManager(RegistrationManager rm, BookieId address, Version version) throws BookieException Delete cookie from registration manager.- Parameters:
rm- registration manageraddress- bookie addressversion- cookie version- Throws:
BookieException- when fail to delete cookie.
-
generateCookie
Generate cookie from the given configuration.- Parameters:
conf- configuration- Returns:
- cookie builder object
- Throws:
UnknownHostException
-
readFromRegistrationManager
public static Versioned<Cookie> readFromRegistrationManager(RegistrationManager rm, ServerConfiguration conf) throws BookieException Read cookie from registration manager.- Parameters:
rm- registration managerconf- configuration- Returns:
- versioned cookie object
- Throws:
BookieException- when fail to read cookie
-
readFromRegistrationManager
public static Versioned<Cookie> readFromRegistrationManager(RegistrationManager rm, BookieId address) throws BookieException Read cookie from registration manager for a given bookie address.- Parameters:
rm- registration manageraddress- bookie address- Returns:
- versioned cookie object
- Throws:
BookieException- when fail to read cookie
-
readFromDirectory
Returns cookie from the given directory.- Parameters:
directory- directory- Returns:
- cookie object
- Throws:
IOExceptionFileNotFoundException
-
isBookieHostCreatedFromIp
Check whether the 'bookieHost' was created using a hostname or an IP address. Represent as 'hostname/IPaddress' if the InetSocketAddress was created using hostname. Represent as '/IPaddress' if the InetSocketAddress was created using an IPaddress- Returns:
- true if the 'bookieHost' was created using an IP address, false if the 'bookieHost' was created using a hostname
- Throws:
IOException
-
newBuilder
Returns Cookie builder.- Returns:
- cookie builder
-
newBuilder
Returns Cookie builder with the copy of given oldCookie.- Parameters:
oldCookie- build new cookie from this cookie- Returns:
- cookie builder
-
equals
-
hashCode
public int hashCode()
-