Class 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.
    • 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()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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
      • deleteFromRegistrationManager

        public void deleteFromRegistrationManager​(RegistrationManager rm,
                                                  BookieId address,
                                                  Version version)
                                           throws BookieException
        Delete cookie from registration manager.
        Parameters:
        rm - registration manager
        address - bookie address
        version - 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,
                                                                    BookieId address)
                                                             throws BookieException
        Read cookie from registration manager for a given bookie address.
        Parameters:
        rm - registration manager
        address - 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 class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object