Package org.apache.bookkeeper.bookie
Class Cookie
- java.lang.Object
-
- org.apache.bookkeeper.bookie.Cookie
-
public class Cookie extends java.lang.Object
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 Modifier and Type Class Description static class
Cookie.Builder
Cookie builder.
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
CURRENT_COOKIE_LAYOUT_VERSION
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteFromRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version)
Deletes cookie from registration manager.void
deleteFromRegistrationManager(RegistrationManager rm, BookieId address, Version version)
Delete cookie from registration manager.static java.lang.String
encodeDirPaths(java.lang.String[] dirs)
boolean
equals(java.lang.Object other)
static Cookie.Builder
generateCookie(ServerConfiguration conf)
Generate cookie from the given configuration.(package private) java.lang.String[]
getIndexDirPathsFromCookie()
(package private) java.lang.String[]
getLedgerDirPathsFromCookie()
int
hashCode()
boolean
isBookieHostCreatedFromIp()
Check whether the 'bookieHost' was created using a hostname or an IP address.static Cookie.Builder
newBuilder()
Returns Cookie builder.static Cookie.Builder
newBuilder(Cookie oldCookie)
Returns Cookie builder with the copy of given oldCookie.static Cookie
parseFromBytes(byte[] bytes)
static Cookie
readFromDirectory(java.io.File directory)
Returns cookie from the given directory.static Versioned<Cookie>
readFromRegistrationManager(RegistrationManager rm, ServerConfiguration conf)
Read cookie from registration manager.static Versioned<Cookie>
readFromRegistrationManager(RegistrationManager rm, BookieId address)
Read cookie from registration manager for a given bookie address.java.lang.String
toString()
void
verify(Cookie c)
void
verifyIsSuperSet(Cookie c)
void
writeToDirectory(java.io.File directory)
void
writeToFile(java.io.File versionFile)
void
writeToRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version)
Writes cookie details to registration manager.
-
-
-
Field Detail
-
CURRENT_COOKIE_LAYOUT_VERSION
static final int CURRENT_COOKIE_LAYOUT_VERSION
- See Also:
- Constant Field Values
-
-
Method Detail
-
encodeDirPaths
public static java.lang.String encodeDirPaths(java.lang.String[] dirs)
-
getLedgerDirPathsFromCookie
java.lang.String[] getLedgerDirPathsFromCookie()
-
getIndexDirPathsFromCookie
java.lang.String[] getIndexDirPathsFromCookie()
-
verify
public void verify(Cookie c) throws BookieException.InvalidCookieException
-
verifyIsSuperSet
public void verifyIsSuperSet(Cookie c) throws BookieException.InvalidCookieException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
parseFromBytes
public static Cookie parseFromBytes(byte[] bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
writeToDirectory
public void writeToDirectory(java.io.File directory) throws java.io.IOException
- Throws:
java.io.IOException
-
writeToFile
public void writeToFile(java.io.File versionFile) throws java.io.IOException
- Throws:
java.io.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
public static Cookie.Builder generateCookie(ServerConfiguration conf) throws java.net.UnknownHostException
Generate cookie from the given configuration.- Parameters:
conf
- configuration- Returns:
- cookie builder object
- Throws:
java.net.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
public static Cookie readFromDirectory(java.io.File directory) throws java.io.IOException, java.io.FileNotFoundException
Returns cookie from the given directory.- Parameters:
directory
- directory- Returns:
- cookie object
- Throws:
java.io.IOException
java.io.FileNotFoundException
-
isBookieHostCreatedFromIp
public boolean isBookieHostCreatedFromIp() throws java.io.IOException
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:
java.io.IOException
-
newBuilder
public static Cookie.Builder newBuilder()
Returns Cookie builder.- Returns:
- cookie builder
-
newBuilder
public static Cookie.Builder newBuilder(Cookie oldCookie)
Returns Cookie builder with the copy of given oldCookie.- Parameters:
oldCookie
- build new cookie from this cookie- Returns:
- cookie builder
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-