@@ -273,21 +273,21 @@ Remote stores (:ref:`MemcachedStore <lock-store-memcached>` and
273
273
:ref: `RedisStore <lock-store-redis >`) use an unique token to recognize the true
274
274
owner of the lock. This token is stored in the
275
275
:class: `Symfony\\ Component\\ Lock\\ Key ` object and is used internally by the
276
- ``Lock ``, therefore this Key must not be shared between processes (Session ,
277
- Caching , fork, ...).
276
+ ``Lock ``, therefore this key must not be shared between processes (session ,
277
+ caching , fork, ...).
278
278
279
279
.. caution ::
280
280
281
- Do not share a Key between processes.
281
+ Do not share a key between processes.
282
282
283
- Every concurrent process must store the ``Lock `` in the same Server otherwise two
284
- distinguished machines may allow two distinguished process to acquire the same ``Lock ``.
283
+ Every concurrent process must store the ``Lock `` in the same server. Otherwise two
284
+ different machines may allow two different processes to acquire the same ``Lock ``.
285
285
286
286
.. caution ::
287
287
288
- To guarantee that the same Server will always be sure , do not use Memcached
288
+ To guarantee that the same server will always be safe , do not use Memcached
289
289
behind a LoadBalancer, a cluster or round-robin DNS. Even if the main server
290
- is Down , the calls must not be forwarded to a backup or failover server.
290
+ is down , the calls must not be forwarded to a backup or failover server.
291
291
292
292
Expiring Stores
293
293
~~~~~~~~~~~~~~~
@@ -298,11 +298,11 @@ only for the defined duration of time. If the task takes longer to be
298
298
accomplished, then the lock can be released by the store and acquired by
299
299
someone else.
300
300
301
- The ``Lock `` provide several methods to check it health. The ``isExpired ``
302
- method provide an quick way to check whether or not it lifetime is over.
303
- While the `` getRemainingLifetime `` method returns it time to live in seconds.
301
+ The ``Lock `` provides several methods to check its health. The ``isExpired() ``
302
+ method checks whether or not it lifetime is over and the `` getRemainingLifetime() ``
303
+ method returns its time to live in seconds.
304
304
305
- With the above methods, a more robust code would be::
305
+ Using the above methods, a more robust code would be::
306
306
307
307
// ...
308
308
$lock = $factory->createLock('invoice-publication', 30);
@@ -311,7 +311,7 @@ With the above methods, a more robust code would be::
311
311
while (!$finished) {
312
312
if ($lock->getRemainingLifetime() <= 5) {
313
313
if ($lock->isExpired()) {
314
- // reliability was lost, perform a rollback or send a notification
314
+ // lock was lost, perform a rollback or send a notification
315
315
throw new \RuntimeException('Lock lost during the overall process');
316
316
}
317
317
@@ -323,49 +323,48 @@ With the above methods, a more robust code would be::
323
323
324
324
.. caution ::
325
325
326
- Choose wisely the lifetime of the ``Lock ``. And check if it remaining
326
+ Choose wisely the lifetime of the ``Lock `` and check whether its remaining
327
327
time to leave is enough to perform the task.
328
328
329
329
.. caution ::
330
330
331
- Storing a ``Lock `` could take time. Even if, most of the time, it take
332
- few milliseconds, Network, may have trouble and the duration to perform
333
- this simple task could be up to few seconds. Take it into accound when
334
- choosing the right TTL.
331
+ Storing a ``Lock `` usually takes a few milliseconds, but network conditions
332
+ may increase that time a lot (up to a few seconds). Take that into account
333
+ when choosing the right TTL.
335
334
336
- By design, Lock are stored in Server with a defined Lifetime . If the date or
337
- time of the machine changes, a Lock could be released sooner than expected.
335
+ By design, locks are stored in servers with a defined lifetime . If the date or
336
+ time of the machine changes, a lock could be released sooner than expected.
338
337
339
338
.. caution ::
340
339
341
- To guarantee that date wouldn 't change, the NTP service should be disabled
342
- and the date should be updated when while the service is stopped.
340
+ To guarantee that date won 't change, the NTP service should be disabled
341
+ and the date should be updated when the service is stopped.
343
342
344
343
FlockStore
345
344
~~~~~~~~~~
346
345
347
346
By using the file system, this ``Store `` is reliable as long as concurrent
348
347
processes use the same physical directory to stores locks.
349
348
350
- Processes must run on the same Machine, Virtual Machine or Container .
349
+ Processes must run on the same machine, virtual machine or container .
351
350
Be careful when updating a Kubernetes or Swarm service because for a short
352
- period of time, there can be 2 running containers in parallel.
351
+ period of time, there can be two running containers in parallel.
353
352
354
- The absolute path to the directory must remain the same. Be careful to
355
- symlinks on the path that could change at anytime: Capistrano and blue/green
356
- deployment often use that trick. Be careful when the path to that directory
357
- change between 2 deployments.
353
+ The absolute path to the directory must remain the same. Be careful of symlinks
354
+ that could change at anytime: Capistrano and blue/green deployment often use
355
+ that trick. Be careful when the path to that directory changes between two
356
+ deployments.
358
357
359
358
Some file systems (such as some types of NFS) do not support locking.
360
359
361
360
.. caution ::
362
361
363
- All concurrent processes MUST use the same physical file system by running
362
+ All concurrent processes must use the same physical file system by running
364
363
on the same machine and using the same absolute path to locks directory.
365
364
366
365
By definition, usage of ``FlockStore `` in an HTTP context is incompatible
367
- with multiple front server , unless to be sure that the same resource will
368
- alway be locked on the same machine or to use a well configured shared file
366
+ with multiple front servers , unless to ensure that the same resource will
367
+ always be locked on the same machine or to use a well configured shared file
369
368
system.
370
369
371
370
Files on file system can be removed during a maintenance operation. For instance
@@ -375,26 +374,26 @@ it is in case of ``Lock`` reused between requests.
375
374
376
375
.. caution ::
377
376
378
- Do not store locks on a volatil file system if they have to be reused during
377
+ Do not store locks on a volatile file system if they have to be reused in
379
378
several requests.
380
379
381
380
MemcachedStore
382
381
~~~~~~~~~~~~~~
383
382
384
- The way Memcached works is to store items in Memory, that's means that by using
383
+ The way Memcached works is to store items in memory. That means that by using
385
384
the :ref: `MemcachedStore <lock-store-memcached >` the locks are not persisted
386
385
and may disappear by mistake at anytime.
387
386
388
- If the Memcached service or the machine hosting it restarts, every locks would
389
- be lost without notify running processes.
387
+ If the Memcached service or the machine hosting it restarts, every lock would
388
+ be lost without notifying the running processes.
390
389
391
390
.. caution ::
392
391
393
- To avoid that someone else acquires a lock after a restart, we recommend
394
- to delayed service start and wait at least as long as the longest lock TTL.
392
+ To avoid that someone else acquires a lock after a restart, it's recommended
393
+ to delay service start and wait at least as long as the longest lock TTL.
395
394
396
- By default Memcached use a LRU mechanism to remove old entries when the service
397
- need space to add new items.
395
+ By default Memcached uses a LRU mechanism to remove old entries when the service
396
+ needs space to add new items.
398
397
399
398
.. caution ::
400
399
@@ -403,73 +402,73 @@ need space to add new items.
403
402
Memcached service away from Cache.
404
403
405
404
When the Memcached service is shared and used for multiple usage, Locks could be
406
- removed by mistake. For instance some implementation of the PSR-6 ``clear ``
407
- method use the Memcached's ``flush `` method which purge and remove everything.
405
+ removed by mistake. For instance some implementation of the PSR-6 ``clear() ``
406
+ method uses the Memcached's ``flush() `` method which purges and removes everything.
408
407
409
408
.. caution ::
410
409
411
- The method ``flush `` MUST not be called, or Locks should be stored in a
410
+ The method ``flush() `` must not be called, or locks should be stored in a
412
411
dedicated Memcached service away from Cache.
413
412
414
413
RedisStore
415
414
~~~~~~~~~~
416
415
417
- The way Redis works is to store items in Memory, that's means that by using
416
+ The way Redis works is to store items in memory. That means that by using
418
417
the :ref: `RedisStore <lock-store-redis >` the locks are not persisted
419
418
and may disappear by mistake at anytime.
420
419
421
420
If the Redis service or the machine hosting it restarts, every locks would
422
- be lost without notify running processes.
421
+ be lost without notifying the running processes.
423
422
424
423
.. caution ::
425
424
426
- To avoid that someone else acquires a lock after a restart, we recommend
427
- to delayed service start and wait at least as long as the longest lock TTL.
425
+ To avoid that someone else acquires a lock after a restart, it's recommended
426
+ to delay service start and wait at least as long as the longest lock TTL.
428
427
429
428
.. tips ::
430
429
431
430
Redis can be configured to persist items on disk, but this option would
432
431
slow down writes on the service. This could go against other uses of the
433
432
server.
434
433
435
- When the Redis service is shared and used for multiple usage, Locks could be
434
+ When the Redis service is shared and used for multiple usages, locks could be
436
435
removed by mistake.
437
436
438
437
.. caution ::
439
438
440
- The command ``FLUSHDB `` MUST not be called, or Locks should be stored in a
439
+ The command ``FLUSHDB `` must not be called, or locks should be stored in a
441
440
dedicated Redis service away from Cache.
442
441
443
442
CombinedStore
444
443
~~~~~~~~~~~~~
445
444
446
- Combined stores allows to store locks across several backend . It's a common
445
+ Combined stores allow to store locks across several backends . It's a common
447
446
mistake to think that the lock mechanism will be more reliable. This is wrong
448
- The ``CombinedStore `` will be, at best, as reliable than the less reliable of
447
+ The ``CombinedStore `` will be, at best, as reliable as the least reliable of
449
448
all managed stores. As soon as one managed store returns erroneous information,
450
- the ``CombinedStore `` would be not reliable.
449
+ the ``CombinedStore `` won't be reliable.
451
450
452
451
.. caution ::
453
452
454
- All concurrent processes MUST use the same configuration. with the same
453
+ All concurrent processes must use the same configuration, with the same
455
454
amount of managed stored and the same endpoint.
456
455
457
456
.. tips ::
458
457
459
- Instead of using Cluster of Redis or memcached servers, we recommend to use
460
- a ``CombinedStore `` with & single server per managed store.
458
+ Instead of using a cluster of Redis or Memcached servers, it's better to use
459
+ a ``CombinedStore `` with a single server per managed store.
461
460
462
461
SemaphoreStore
463
462
~~~~~~~~~~~~~~
464
463
465
- Semaphore are handled by the Kernel level, to be reliable, processes must run
466
- on the same Machine, Virtual Machine or Container.
467
- Be careful when updating a Kubernetes or Swarm service because for a short
468
- period of time, there can be 2 running containers in parallel.
464
+ Semaphores are handled by the Kernel level. In order to be reliable, processes
465
+ must run on the same machine, virtual machine or container. Be careful when
466
+ updating a Kubernetes or Swarm service because for a short period of time, there
467
+ can be two running containers in parallel.
469
468
470
469
.. caution ::
471
470
472
- All concurrent processes MUST use the same machine. Before starting a
471
+ All concurrent processes must use the same machine. Before starting a
473
472
concurrent process on a new machine, check that other process are stopped
474
473
on the old one.
475
474
@@ -478,8 +477,8 @@ Overall
478
477
479
478
Changing the configuration of stores should be done very carefully. For
480
479
instance, during the deployment of a new version. Processes with new
481
- configuration MUST NOT be started while Old processes with old configuration
482
- are still running
480
+ configuration must not be started while old processes with old configuration
481
+ are still running.
483
482
484
483
.. _`locks` : https://en.wikipedia.org/wiki/Lock_(computer_science)
485
484
.. _Packagist : https://packagist.org/packages/symfony/lock
0 commit comments