Skip to content

Commit a8d068c

Browse files
Add docs for Zookeeper Data Store.
1 parent fb3b7bd commit a8d068c

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

components/lock.rst

Lines changed: 45 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,28 @@ 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+
The ZookeeperStore saves locks on a Zookeeper server, it requires a Zookeeper
334+
connection implementing the ``\Zookeeper`` class. This store does not
335+
support blocking and expiration but the lock is automatically released when the
336+
PHP process is terminated::
337+
338+
use Symfony\Component\Lock\Store\ZookeeperStore;
339+
340+
$zookeeper_server = 'localhost:2181'; // For High Availablity Cluster you can pass 'localhost1:2181,localhost2:2181,localhost3:2181'
341+
$zookeeper = new \Zookeeper($zookeeper_server);
342+
343+
$store = new ZookeeperStore($zookeeper);
344+
345+
.. note::
346+
347+
Zookeeper does not require a TTL as the nodes used for locking are ephemeral and die when the PHP process is terminated.
348+
349+
327350
Reliability
328351
-----------
329352

@@ -334,8 +357,8 @@ Remote Stores
334357
~~~~~~~~~~~~~
335358

336359
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
360+
:ref:`PdoStore <lock-store-pdo>`, :ref:`RedisStore <lock-store-redis>`) and :ref:`ZookeeperStore <lock-store-zookeeper>`)
361+
use a unique token to recognize the true owner of the lock. This token is stored
339362
in the :class:`Symfony\\Component\\Lock\\Key` object and is used internally by
340363
the ``Lock``, therefore this key must not be shared between processes (session,
341364
caching, fork, ...).
@@ -560,6 +583,26 @@ can be two running containers in parallel.
560583
concurrent process on a new machine, check that other process are stopped
561584
on the old one.
562585

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

0 commit comments

Comments
 (0)