From f7b061d63dec5e823a47c778d3df0caf99b62990 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Mon, 29 Jul 2024 13:11:05 +0100 Subject: [PATCH 1/4] Tell couchbase to reattach threads if needed, before preparing to fork --- lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php index d544fb7..c669ab3 100644 --- a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php +++ b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php @@ -164,6 +164,13 @@ public static function prepareToFork(): void } if (\version_compare(static::$extVersion, '4.2.1', '>=')) { + if (static::$prepareToForkPPID) { + if (static::$prepareToForkPPID === \posix_getpid()) { + Cluster::notifyFork(ForkEvent::PARENT); + } else { + Cluster::notifyFork(ForkEvent::CHILD); + } + } Cluster::notifyFork(ForkEvent::PREPARE); } From ac224cc2ea094b65f45eb35085af37accd04aa21 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Mon, 29 Jul 2024 13:25:30 +0100 Subject: [PATCH 2/4] Prepare for release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c9fd2..4a5bc1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 9.2.2 +#### 29 July 2024 +- __Driver Core__ + - `Couchbasev4` Allow calling of `prepareToFork()` when driver is not initialized to allow switch between drivers. + - `Couchbasev4` Tell couchbase to reattach its threads if needed, before preparing to forking. + ## 9.2.1 #### 25 April 2024 - __Driver Core__ From 9e5cc176d61ab98f2191e0a68442889d553a5347 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Mon, 29 Jul 2024 13:50:25 +0100 Subject: [PATCH 3/4] Tell couchbase to reattach threads if needed, before shutdown --- .../Extensions/Drivers/Couchbasev4/Driver.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php index c669ab3..332f016 100644 --- a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php +++ b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php @@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve $this->__parentConstruct($config, $instanceId, $em); } + public function __destruct() + { + static::handleNotifyFork(); + } + /** * @return bool @@ -164,13 +169,7 @@ public static function prepareToFork(): void } if (\version_compare(static::$extVersion, '4.2.1', '>=')) { - if (static::$prepareToForkPPID) { - if (static::$prepareToForkPPID === \posix_getpid()) { - Cluster::notifyFork(ForkEvent::PARENT); - } else { - Cluster::notifyFork(ForkEvent::CHILD); - } - } + static::handleNotifyFork(); Cluster::notifyFork(ForkEvent::PREPARE); } @@ -195,15 +194,20 @@ protected function handleForkedProcess(): void $this->connect(\posix_getppid()); } - if (\version_compare(static::$extVersion, '4.2.1', '>=')) { - if (static::$prepareToForkPPID === \posix_getpid()) { - Cluster::notifyFork(ForkEvent::PARENT); - } else { - Cluster::notifyFork(ForkEvent::CHILD); - } - static::$prepareToForkPPID = 0; - } + static::handleNotifyFork(); + } + } + } + + protected static function handleNotifyFork(): void + { + if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) { + if (static::$prepareToForkPPID === \posix_getpid()) { + Cluster::notifyFork(ForkEvent::PARENT); + } else { + Cluster::notifyFork(ForkEvent::CHILD); } + static::$prepareToForkPPID = 0; } } @@ -221,7 +225,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array /** * CouchbaseBucket::get() returns a GetResult interface */ - return $this->decodeDocument((array)$this->getCollection()->get($item->getEncodedKey())->content()); + return $this->decodeDocument((array) $this->getCollection()->get($item->getEncodedKey())->content()); } catch (DocumentNotFoundException) { return null; } From 7be58bd27c549d81cab96b2187ecf246c1a98353 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Mon, 29 Jul 2024 13:57:31 +0100 Subject: [PATCH 4/4] Tell couchbase to reattach threads if needed, before shutdown --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a5bc1c..2ffc38f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ #### 29 July 2024 - __Driver Core__ - `Couchbasev4` Allow calling of `prepareToFork()` when driver is not initialized to allow switch between drivers. - - `Couchbasev4` Tell couchbase to reattach its threads if needed, before preparing to forking. + - `Couchbasev4` Tell couchbase to reattach its threads if needed, while preparing to forking and on destruct. ## 9.2.1 #### 25 April 2024