Skip to content

Commit 6218472

Browse files
committed
minor #10043 Add documentation for using Zookeeper data store for lock component (Ganesh Chandrasekaran)
This PR was merged into the master branch. Discussion ---------- Add documentation for using Zookeeper data store for lock component This is a documentation update for new Feature of the Lock Component. This will be linked to the PR which will be created in https://github.com/symfony/symfony Corresponding code PR: symfony/symfony#27920 Commits ------- 2ba70f0 Add docs for Zookeeper Data Store.
2 parents aec2882 + 2ba70f0 commit 6218472

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

components/lock.rst

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Store Scope Blocking Expiring
176176
:ref:`PdoStore <lock-store-pdo>` remote no yes
177177
:ref:`RedisStore <lock-store-redis>` remote no yes
178178
:ref:`SemaphoreStore <lock-store-semaphore>` local yes no
179+
:ref:`ZookeeperStore <lock-store-zookeeper>` remote no no
179180
============================================ ====== ======== ========
180181

181182
.. _lock-store-flock:
@@ -324,6 +325,31 @@ the stores.
324325
working when a single server fails (because this strategy requires that the
325326
lock is acquired in more than half of the servers).
326327

328+
.. _lock-store-zookeeper:
329+
330+
ZookeeperStore
331+
~~~~~~~~~~~~~~
332+
333+
.. versionadded:: 4.2
334+
The ZookeeperStore was introduced Symfony 4.2.
335+
336+
The ZookeeperStore saves locks on a Zookeeper server, it requires a Zookeeper
337+
connection implementing the ``\Zookeeper`` class. This store does not
338+
support blocking and expiration but the lock is automatically released when the
339+
PHP process is terminated::
340+
341+
use Symfony\Component\Lock\Store\ZookeeperStore;
342+
343+
$zookeeper_server = 'localhost:2181'; // For High Availablity Cluster you can pass 'localhost1:2181,localhost2:2181,localhost3:2181'
344+
$zookeeper = new \Zookeeper($zookeeper_server);
345+
346+
$store = new ZookeeperStore($zookeeper);
347+
348+
.. note::
349+
350+
Zookeeper does not require a TTL as the nodes used for locking are ephemeral and die when the PHP process is terminated.
351+
352+
327353
Reliability
328354
-----------
329355

@@ -334,8 +360,8 @@ Remote Stores
334360
~~~~~~~~~~~~~
335361

336362
Remote stores (:ref:`MemcachedStore <lock-store-memcached>`,
337-
:ref:`PdoStore <lock-store-pdo>` and :ref:`RedisStore <lock-store-redis>`) use
338-
a unique token to recognize the true owner of the lock. This token is stored
363+
:ref:`PdoStore <lock-store-pdo>`, :ref:`RedisStore <lock-store-redis>`) and :ref:`ZookeeperStore <lock-store-zookeeper>`)
364+
use a unique token to recognize the true owner of the lock. This token is stored
339365
in the :class:`Symfony\\Component\\Lock\\Key` object and is used internally by
340366
the ``Lock``, therefore this key must not be shared between processes (session,
341367
caching, fork, ...).
@@ -560,6 +586,26 @@ can be two running containers in parallel.
560586
concurrent process on a new machine, check that other process are stopped
561587
on the old one.
562588

589+
ZookeeperStore
590+
~~~~~~~~~~~~~~
591+
592+
The way ZookeeperStore works is by maintaining locks as ephemeral nodes on the server. That means that by using
593+
the :ref:`ZookeeperStore <lock-store-zookeeper>` the locks will be automatically released at the end of the session
594+
in case the client cannot unlock for any reason.
595+
596+
If the Zookeeper service or the machine hosting it restarts, every lock would
597+
be lost without notifying the running processes.
598+
599+
.. tip::
600+
601+
To use Zookeeper's High Availability feature, you can setup a cluster of multiple servers so that in case one of
602+
the server goes down, the majority will still be up and serving the requests. All the available servers in the
603+
cluster will see the same state.
604+
605+
.. note::
606+
As this store does not support multi-level node locks,
607+
since the clean up of intermediate nodes becomes an overhead, all locks are maintained at the root level.
608+
563609
Overall
564610
~~~~~~~
565611

0 commit comments

Comments
 (0)