

{"id":21306,"date":"2018-07-28T04:05:18","date_gmt":"2018-07-28T04:05:18","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=21306"},"modified":"2021-05-19T18:23:59","modified_gmt":"2021-05-19T12:53:59","slug":"zookeeper-sessions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/","title":{"rendered":"ZooKeeper Sessions | Process of Sessions in ZooKeeper"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In our last <strong>ZooKeeper tutorial<\/strong>, we discussed <strong>ZooKeeper watches<\/strong>. Today, we will see ZooKeeper Sessions. Moreover, we will discuss the complete working process of Sessions in ZooKeeper, which contains ZooKeeper sessions timeout, how to create a client session.<\/span><\/p>\n<p>So, let&#8217;s start ZooKeeper Sessions.<\/p>\n<h2><span style=\"font-weight: 400\">What are ZooKeeper Sessions?<\/span><\/h2>\n<p><span style=\"font-weight: 400\">As we know for the operation of ZooKeeper, Sessions in ZooKeeper play the very important role. In FIFO order, all requests execute in session. Basically, the session establishes as soon as a ZooKeeper Client connects to a Server. After that, it assigns a session id to the client.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, to keep the ZooKeeper Sessions valid, the client sends heartbeats at a particular time interval. <\/span><\/p>\n<p><span style=\"font-weight: 400\">However if for more than the period (ZooKeeper Session Timeout- specified at the starting of the service) the ZooKeeper ensemble does not receive heartbeats from a client, then it assumes that the client died.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Detailed Description of ZooKeeper Sessions<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Basically, with the ZooKeeper service by creating a handle to the service using a language binding, a ZooKeeper client establishes a session in ZooKeeper. <\/span><\/p>\n<p><span style=\"font-weight: 400\">To one of the servers\u00a0which<\/span><span style=\"font-weight: 400\">\u00a0make up the ZooKeeper service at which point it switches to the CONNECTED state, the client library tries to connect. It happens as soon as the handle starts off in the CONNECTING state,<\/span><span style=\"font-weight: 400\"> once created<\/span><span style=\"font-weight: 400\">. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In addition, the handle will move to the CLOSED state if an unrecoverable error occurs. Errors can be of any type:\u00a0if the application explicitly closes the handle, ZooKeeper Sessions expiration or authentication failure.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now you can see the figure\u00a0above explains the possible state transitions of a ZooKeeper client.<\/span><\/p>\n<h3>\u00a0a. How to Create A Client Session<\/h3>\n<p><span style=\"font-weight: 400\">However, it is must that the application code offers a string (connection string)\u00a0which consists of a comma-separated list of host: port pairs, in order to create a client session, though, each corresponds to a ZooKeeper server.<\/span><span style=\"font-weight: 400\"> For e.g. &#8220;127.0.0.1:4545&#8221; or &#8220;127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002&#8221;.<\/span><br \/>\n<span style=\"font-weight: 400\">Added in 3.2.0: <\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, to the connection string, an optional chroot suffix may append. So,\u00a0when interpreting all paths relative to this root,\u00a0it will run the client commands. <\/span><\/p>\n<p><span style=\"font-weight: 400\">On using the example would look like: 127.0.0.1:4545\/app\/a or 127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002\/app\/a. Here at \u201c\/app\/a\u201d, the client will\u00a0get root.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Particularly, in multi-tenant environments this feature is useful. Especially, where each user of a particular ZooKeeper service could be rooted differently. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This makes reuse much simpler as each user can code his\/her application as if it were rooted at \/, while actual location (say \/app\/a) could be determined at deployment time.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">b. What Happens in Session Creation<\/span><\/h3>\n<p><span style=\"font-weight: 400\">After that client library of ZooKeeper will pick an arbitrary server and further try to connect to it. Until a connection (re-)establishes, the client will automatically try the next server in the list, if this connection fails, or if the client disconnects from the server for any reason.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">c. The server creates Session Id<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Now, ZooKeeper creates sessions in ZooKeeper, when a client gets a handle on the ZooKeeper service, which is a 64-bit number, and that assigns to the client.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">d. Server creates the password and sends it to client<\/span><\/h3>\n<p><span style=\"font-weight: 400\">As a part of the connection handshake,\u00a0the client will send the session id, if the client connects to a different ZooKeeper server. However, the server creates a password for the session id that any <strong>ZooKeeper server<\/strong> can validate, as a security measure. <\/span><\/p>\n<p><span style=\"font-weight: 400\">And, when the client establishes the session, the password is sent to the client with the session id. Moreover, with the session id, the client sends this password at the time it reestablishes the session with a new server.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">e. Client Specifies Timeout<\/span><\/h3>\n<p><span style=\"font-weight: 400\">However, the ZooKeeper session timeout is in milliseconds, as soon as the parameters to the <strong>ZooKeeper client<\/strong> library calls to create a ZooKeeper session. Basically, the server responds with the ZooKeeper session Timeout that it can give the client as the client sends a requested timeout.<\/span><\/p>\n<h3>f. Session Re-establishment<\/h3>\n<p>The session will either again transition to the connected state or it will transition to the expired state when connectivity between the client and at least one of the servers is re-established.<\/p>\n<h3><span style=\"font-weight: 400\">g. Session Expiration<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Though itself,\u00a0<strong>ZooKeeper cluster<\/strong> manages Session expiration.<\/span><br \/>\n<span style=\"font-weight: 400\">In addition, if the ZooKeeper Cluster does not hear (i.e. no heartbeat) within the specified ZooKeeper Sessions Timeout period from the client, expirations happens.\u00a0<\/span><span style=\"font-weight: 400\">As a result, the ZooKeeper Cluster deletes ephemeral nodes\u00a0of that session by itself.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">However, until\/unless it is able to re-establish a connection to the cluster in ZooKeeper, it will not be notified of the session expiration, at this point the client of the expired session is still disconnected from the cluster. <\/span><\/p>\n<p><span style=\"font-weight: 400\">And, until the TCP connection re-establishes with the cluster, the client will stay in the disconnected state. Hence,\u00a0 at\u00a0that time the\u00a0session expired notification will be sent to the watcher.<\/span><br \/>\nSo, this was all in ZooKeeper sessions. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion<\/span><\/h2>\n<p>Hence, we have seen the whole about Zookeeper Sessions. Though, if any doubt occurs regarding Sessions in ZooKeeper, feel free to ask in the comment tab. We are happy to help!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last ZooKeeper tutorial, we discussed ZooKeeper watches. Today, we will see ZooKeeper Sessions. Moreover, we will discuss the complete working process of Sessions in ZooKeeper, which contains ZooKeeper sessions timeout, how to&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":21655,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[2569,2570,6022,12760,12761,12764,14684,16378,16416,16417],"class_list":["post-21306","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-zookeeper","tag-client-session","tag-client-specifies-timeout","tag-how-to-create-a-client-session","tag-session-expiration","tag-session-re-establishment","tag-sessions-in-zookeeper","tag-the-server-creates-session-id","tag-zookeeper-client","tag-zookeeper-session-timeout","tag-zookeeper-sessions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ZooKeeper Sessions | Process of Sessions in ZooKeeper - DataFlair<\/title>\n<meta name=\"description\" content=\"ZooKeeper sessions Tutorial,Sessions in ZooKeeper,process of zookeeper session,how to create a client session,ZooKeeper Sessions Timeout\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ZooKeeper Sessions | Process of Sessions in ZooKeeper - DataFlair\" \/>\n<meta property=\"og:description\" content=\"ZooKeeper sessions Tutorial,Sessions in ZooKeeper,process of zookeeper session,how to create a client session,ZooKeeper Sessions Timeout\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-28T04:05:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-19T12:53:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/ZooKeeper-Sessions-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ZooKeeper Sessions | Process of Sessions in ZooKeeper - DataFlair","description":"ZooKeeper sessions Tutorial,Sessions in ZooKeeper,process of zookeeper session,how to create a client session,ZooKeeper Sessions Timeout","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/","og_locale":"en_US","og_type":"article","og_title":"ZooKeeper Sessions | Process of Sessions in ZooKeeper - DataFlair","og_description":"ZooKeeper sessions Tutorial,Sessions in ZooKeeper,process of zookeeper session,how to create a client session,ZooKeeper Sessions Timeout","og_url":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-28T04:05:18+00:00","article_modified_time":"2021-05-19T12:53:59+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/ZooKeeper-Sessions-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"ZooKeeper Sessions | Process of Sessions in ZooKeeper","datePublished":"2018-07-28T04:05:18+00:00","dateModified":"2021-05-19T12:53:59+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/"},"wordCount":850,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/ZooKeeper-Sessions-01.jpg","keywords":["client session","Client Specifies Timeout","How to Create A Client Session","Session Expiration","Session Re-establishment","Sessions in ZooKeeper","The server creates Session Id","zooKeeper client","ZooKeeper session Timeout","ZooKeeper Sessions"],"articleSection":["Zookeeper Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/","url":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/","name":"ZooKeeper Sessions | Process of Sessions in ZooKeeper - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/ZooKeeper-Sessions-01.jpg","datePublished":"2018-07-28T04:05:18+00:00","dateModified":"2021-05-19T12:53:59+00:00","description":"ZooKeeper sessions Tutorial,Sessions in ZooKeeper,process of zookeeper session,how to create a client session,ZooKeeper Sessions Timeout","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/ZooKeeper-Sessions-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/ZooKeeper-Sessions-01.jpg","width":1200,"height":628,"caption":"ZooKeeper Sessions | Process of Sessions in ZooKeeper"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/zookeeper-sessions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Zookeeper Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/zookeeper\/"},{"@type":"ListItem","position":3,"name":"ZooKeeper Sessions | Process of Sessions in ZooKeeper"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/21306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=21306"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/21306\/revisions"}],"predecessor-version":[{"id":94155,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/21306\/revisions\/94155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/21655"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=21306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=21306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=21306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}