From 69950da66679cc6e4412eb18c83e08bd75dc7b76 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 9 Jan 2020 14:10:08 -0800 Subject: [PATCH] objectcache: split out StorageAwareness/ExpirationAwareness from IExpiringStore Add more detailed QOS_* constants while at it Bug: T236412 Change-Id: Ia862c5111a3daf10a34fc78163301629228efa6b --- autoload.php | 4 +- includes/libs/MapCacheLRU.php | 3 +- includes/libs/objectcache/BagOStuff.php | 9 +- includes/libs/objectcache/IExpiringStore.php | 66 -------------- .../objectcache/utils/ExpirationAwareness.php | 57 +++++++++++++ .../libs/objectcache/utils/IExpiringStore.php | 15 ++++ .../objectcache/utils/StorageAwareness.php | 85 +++++++++++++++++++ .../objectcache/wancache/WANObjectCache.php | 12 ++- .../wancache/WANObjectCacheReaper.php | 2 +- 9 files changed, 179 insertions(+), 74 deletions(-) delete mode 100644 includes/libs/objectcache/IExpiringStore.php create mode 100644 includes/libs/objectcache/utils/ExpirationAwareness.php create mode 100644 includes/libs/objectcache/utils/IExpiringStore.php create mode 100644 includes/libs/objectcache/utils/StorageAwareness.php diff --git a/autoload.php b/autoload.php index fa8b3ef5727..522ab7e6cfe 100644 --- a/autoload.php +++ b/autoload.php @@ -645,7 +645,7 @@ $wgAutoloadLocalClasses = [ 'IDBAccessObject' => __DIR__ . '/includes/dao/IDBAccessObject.php', 'IDatabase' => __DIR__ . '/includes/libs/rdbms/database/IDatabase.php', 'IEContentAnalyzer' => __DIR__ . '/includes/libs/mime/IEContentAnalyzer.php', - 'IExpiringStore' => __DIR__ . '/includes/libs/objectcache/IExpiringStore.php', + 'IExpiringStore' => __DIR__ . '/includes/libs/objectcache/utils/IExpiringStore.php', 'IJobSpecification' => __DIR__ . '/includes/jobqueue/IJobSpecification.php', 'ILanguageConverter' => __DIR__ . '/includes/language/ILanguageConverter.php', 'ILocalizedException' => __DIR__ . '/includes/exception/ILocalizedException.php', @@ -1650,6 +1650,8 @@ $wgAutoloadLocalClasses = [ 'Wikimedia\\DependencyStore\\SqlModuleDependencyStore' => __DIR__ . '/includes/resourceloader/dependencystore/SqlModuleDependencyStore.php', 'Wikimedia\\Http\\HttpAcceptNegotiator' => __DIR__ . '/includes/libs/http/HttpAcceptNegotiator.php', 'Wikimedia\\Http\\HttpAcceptParser' => __DIR__ . '/includes/libs/http/HttpAcceptParser.php', + 'Wikimedia\\LightweightObjectStore\\ExpirationAwareness' => __DIR__ . '/includes/libs/objectcache/utils/ExpirationAwareness.php', + 'Wikimedia\\LightweightObjectStore\\StorageAwareness' => __DIR__ . '/includes/libs/objectcache/utils/StorageAwareness.php', 'Wikimedia\\Rdbms\\AtomicSectionIdentifier' => __DIR__ . '/includes/libs/rdbms/database/utils/AtomicSectionIdentifier.php', 'Wikimedia\\Rdbms\\Blob' => __DIR__ . '/includes/libs/rdbms/encasing/Blob.php', 'Wikimedia\\Rdbms\\ChronologyProtector' => __DIR__ . '/includes/libs/rdbms/ChronologyProtector.php', diff --git a/includes/libs/MapCacheLRU.php b/includes/libs/MapCacheLRU.php index e0c81eddba1..2662e97412f 100644 --- a/includes/libs/MapCacheLRU.php +++ b/includes/libs/MapCacheLRU.php @@ -21,6 +21,7 @@ * @ingroup Cache */ use Wikimedia\Assert\Assert; +use Wikimedia\LightweightObjectStore\ExpirationAwareness; /** * Handles a simple LRU key/value map with a maximum number of entries @@ -34,7 +35,7 @@ use Wikimedia\Assert\Assert; * @ingroup Cache * @since 1.23 */ -class MapCacheLRU implements IExpiringStore, Serializable { +class MapCacheLRU implements ExpirationAwareness, Serializable { /** @var array Map of (key => value) */ private $cache = []; /** @var array Map of (key => (UNIX timestamp, (field => UNIX timestamp))) */ diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index 6561acc1079..4a47c66c832 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -29,6 +29,8 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Wikimedia\LightweightObjectStore\ExpirationAwareness; +use Wikimedia\LightweightObjectStore\StorageAwareness; use Wikimedia\ScopedCallback; /** @@ -60,7 +62,12 @@ use Wikimedia\ScopedCallback; * * @ingroup Cache */ -abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInterface { +abstract class BagOStuff implements + ExpirationAwareness, + StorageAwareness, + IStoreKeyEncoder, + LoggerAwareInterface +{ /** @var LoggerInterface */ protected $logger; diff --git a/includes/libs/objectcache/IExpiringStore.php b/includes/libs/objectcache/IExpiringStore.php deleted file mode 100644 index 1566c07925e..00000000000 --- a/includes/libs/objectcache/IExpiringStore.php +++ /dev/null @@ -1,66 +0,0 @@ - N - const QOS_SYNCWRITES_SS = 4; // strict-serializable, nodes refuse reads if possible stale - - // Generic "unknown" value that is useful for comparisons (e.g. always good enough) - const QOS_UNKNOWN = INF; - - const ERR_NONE = 0; // no error - const ERR_NO_RESPONSE = 1; // no response - const ERR_UNREACHABLE = 2; // can't connect - const ERR_UNEXPECTED = 3; // response gave some error -} diff --git a/includes/libs/objectcache/utils/ExpirationAwareness.php b/includes/libs/objectcache/utils/ExpirationAwareness.php new file mode 100644 index 00000000000..2ea1c174bc4 --- /dev/null +++ b/includes/libs/objectcache/utils/ExpirationAwareness.php @@ -0,0 +1,57 @@ + quorum */ + public const QOS_SYNCWRITES_QC = 3; + /** @var int Synchronous; strict serializable */ + public const QOS_SYNCWRITES_SS = 4; + + /** @var int Data is replicated accross a wide area network */ + public const QOS_LOCALITY_WAN = 1; + /** @var int Data is stored on servers within the local area network */ + public const QOS_LOCALITY_LAN = 2; + /** @var int Data is stored in RAM owned by another process or in the local filesystem */ + public const QOS_LOCALITY_SRV = 3; + /** @var int Data is stored in RAM owned by this process */ + public const QOS_LOCALITY_PROC = 4; + + /** @var int Data is never saved to begin with (blackhole store) */ + public const QOS_DURABILITY_NONE = 1; + /** @var int Data is lost at the end of the current web request or CLI script */ + public const QOS_DURABILITY_SCRIPT = 2; + /** @var int Data is lost once the service storing the data restarts */ + public const QOS_DURABILITY_SERVICE = 3; + /** @var int Data is saved to disk, though without immediate fsync() */ + public const QOS_DURABILITY_DISK = 4; + /** @var int Data is saved to disk via an RDBMS, usually with immediate fsync() */ + public const QOS_DURABILITY_RDBMS = 5; + + /** @var int Generic "unknown" value; useful for comparisons (always "good enough") */ + public const QOS_UNKNOWN = INF; +} diff --git a/includes/libs/objectcache/wancache/WANObjectCache.php b/includes/libs/objectcache/wancache/WANObjectCache.php index f143d798930..4d051952472 100644 --- a/includes/libs/objectcache/wancache/WANObjectCache.php +++ b/includes/libs/objectcache/wancache/WANObjectCache.php @@ -23,6 +23,8 @@ use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Wikimedia\LightweightObjectStore\ExpirationAwareness; +use Wikimedia\LightweightObjectStore\StorageAwareness; /** * Multi-datacenter aware caching interface @@ -113,7 +115,12 @@ use Psr\Log\NullLogger; * @ingroup Cache * @since 1.26 */ -class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInterface { +class WANObjectCache implements + ExpirationAwareness, + StorageAwareness, + IStoreKeyEncoder, + LoggerAwareInterface +{ /** @var BagOStuff The local datacenter cache */ protected $cache; /** @var MapCacheLRU[] Map of group PHP instance caches */ @@ -157,9 +164,6 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt /** @var int Seconds to tombstone keys on delete() and treat as volatile after invalidation */ const HOLDOFF_TTL = self::MAX_COMMIT_DELAY + self::MAX_READ_LAG + 1; - /** @var int Idiom for getWithSetCallback() meaning "do not store the callback result" */ - const TTL_UNCACHEABLE = -1; - /** @var int Consider regeneration if the key will expire within this many seconds */ const LOW_TTL = 30; /** @var int Max TTL, in seconds, to store keys when a data sourced is lagged */ diff --git a/includes/libs/objectcache/wancache/WANObjectCacheReaper.php b/includes/libs/objectcache/wancache/WANObjectCacheReaper.php index fb8a75469e7..ff421e94f35 100644 --- a/includes/libs/objectcache/wancache/WANObjectCacheReaper.php +++ b/includes/libs/objectcache/wancache/WANObjectCacheReaper.php @@ -171,7 +171,7 @@ class WANObjectCacheReaper implements LoggerAwareInterface { 'ctime' => $curValue ? $curValue['ctime'] : date( 'c' ) ]; }, - IExpiringStore::TTL_INDEFINITE + BagOStuff::TTL_INDEFINITE ); $pos = $lastOkEvent['pos'];