File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,16 +64,32 @@ public function lock(): void {
6464
6565 public function update (): void {
6666 if ($ this ->nextPing === -1 ) {
67- throw new LockException ('lock service not initiated on this process ' );
67+ throw new LockException ('Lock service not initiated on this process ' );
6868 }
6969
7070 $ time = time ();
7171
72- // update ping
73- if ($ this ->nextPing < $ time ) {
74- $ this ->nextPing = $ time + self ::LOCK_PING_DELAY ;
75- $ this ->appConfig ->setValueInt (Application::APP_ID , ConfigLexicon::LOCK_PING , $ this ->nextPing + self ::LOCK_TIMEOUT );
72+ // do not flood database
73+ if ($ this ->nextPing > $ time ) {
74+ return ;
75+ }
76+
77+ $ this ->appConfig ->clearCache (true );
78+ $ currentLockId = $ this ->appConfig ->getValueString (Application::APP_ID , ConfigLexicon::LOCK_ID );
79+
80+ // new lock; enforce ping on new lock
81+ if ($ currentLockId === '' ) {
82+ throw new LockException ('Index not locked ' );
7683 }
84+
85+ // confirm the lock belongs to the current process
86+ if ($ currentLockId !== $ this ->lockId ) {
87+ throw new LockException ('Index locked by another process ' );
88+ }
89+
90+ // update ping
91+ $ this ->nextPing = $ time + self ::LOCK_PING_DELAY ;
92+ $ this ->appConfig ->setValueInt (Application::APP_ID , ConfigLexicon::LOCK_PING , $ this ->nextPing + self ::LOCK_TIMEOUT );
7793 }
7894
7995 public function unlock (): void {
You can’t perform that action at this time.
0 commit comments