@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Begin standardizing garbage collectors

Summary: Ref T9494. Improve support infrastructure for garbage collectors.

Test Plan:
- Ran `bin/phd debug trigger`, saw collectors execute.

{F857852}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9494

Differential Revision: https://secure.phabricator.com/D14218

+364 -15
+2
src/__phutil_library_map__.php
··· 1829 1829 'PhabricatorConfigAllController' => 'applications/config/controller/PhabricatorConfigAllController.php', 1830 1830 'PhabricatorConfigApplication' => 'applications/config/application/PhabricatorConfigApplication.php', 1831 1831 'PhabricatorConfigCacheController' => 'applications/config/controller/PhabricatorConfigCacheController.php', 1832 + 'PhabricatorConfigCollectorsModule' => 'applications/config/module/PhabricatorConfigCollectorsModule.php', 1832 1833 'PhabricatorConfigColumnSchema' => 'applications/config/schema/PhabricatorConfigColumnSchema.php', 1833 1834 'PhabricatorConfigConfigPHIDType' => 'applications/config/phid/PhabricatorConfigConfigPHIDType.php', 1834 1835 'PhabricatorConfigController' => 'applications/config/controller/PhabricatorConfigController.php', ··· 5761 5762 'PhabricatorConfigAllController' => 'PhabricatorConfigController', 5762 5763 'PhabricatorConfigApplication' => 'PhabricatorApplication', 5763 5764 'PhabricatorConfigCacheController' => 'PhabricatorConfigController', 5765 + 'PhabricatorConfigCollectorsModule' => 'PhabricatorConfigModule', 5764 5766 'PhabricatorConfigColumnSchema' => 'PhabricatorConfigStorageSchema', 5765 5767 'PhabricatorConfigConfigPHIDType' => 'PhabricatorPHIDType', 5766 5768 'PhabricatorConfigController' => 'PhabricatorController',
+10
src/applications/auth/garbagecollector/PhabricatorAuthSessionGarbageCollector.php
··· 3 3 final class PhabricatorAuthSessionGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'auth.sessions'; 7 + 8 + public function getCollectorName() { 9 + return pht('Auth Sessions'); 10 + } 11 + 12 + public function hasAutomaticPolicy() { 13 + return true; 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $session_table = new PhabricatorAuthSession(); 8 18 $conn_w = $session_table->establishConnection('w');
+10
src/applications/auth/garbagecollector/PhabricatorAuthTemporaryTokenGarbageCollector.php
··· 3 3 final class PhabricatorAuthTemporaryTokenGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'auth.tokens'; 7 + 8 + public function getCollectorName() { 9 + return pht('Auth Tokens'); 10 + } 11 + 12 + public function hasAutomaticPolicy() { 13 + return true; 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $session_table = new PhabricatorAuthTemporaryToken(); 8 18 $conn_w = $session_table->establishConnection('w');
+10
src/applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php
··· 3 3 final class PhabricatorCacheGeneralGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'cache.general'; 7 + 8 + public function getCollectorName() { 9 + return pht('General Cache'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('30 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $key = 'gcdaemon.ttl.general-cache'; 8 18 $ttl = PhabricatorEnv::getEnvConfig($key);
+10
src/applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php
··· 3 3 final class PhabricatorCacheMarkupGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'cache.markup'; 7 + 8 + public function getCollectorName() { 9 + return pht('Markup Cache'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('30 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $key = 'gcdaemon.ttl.markup-cache'; 8 18 $ttl = PhabricatorEnv::getEnvConfig($key);
+10
src/applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php
··· 3 3 final class PhabricatorCacheTTLGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'cache.general.ttl'; 7 + 8 + public function getCollectorName() { 9 + return pht('General Cache (TTL)'); 10 + } 11 + 12 + public function hasAutomaticPolicy() { 13 + return true; 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $cache = new PhabricatorKeyValueDatabaseCache(); 8 18 $conn_w = $cache->establishConnection('w');
+10
src/applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php
··· 3 3 final class ConduitConnectionGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'conduit.connections'; 7 + 8 + public function getCollectorName() { 9 + return pht('Conduit Connections'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('180 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $key = 'gcdaemon.ttl.conduit-logs'; 8 18 $ttl = PhabricatorEnv::getEnvConfig($key);
+10
src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php
··· 3 3 final class ConduitLogGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'conduit.logs'; 7 + 8 + public function getCollectorName() { 9 + return pht('Conduit Logs'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('180 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $key = 'gcdaemon.ttl.conduit-logs'; 8 18 $ttl = PhabricatorEnv::getEnvConfig($key);
+10
src/applications/conduit/garbagecollector/ConduitTokenGarbageCollector.php
··· 3 3 final class ConduitTokenGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'conduit.tokens'; 7 + 8 + public function getCollectorName() { 9 + return pht('Conduit Tokens'); 10 + } 11 + 12 + public function hasAutomaticPolicy() { 13 + return true; 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $table = new PhabricatorConduitToken(); 8 18 $conn_w = $table->establishConnection('w');
+61
src/applications/config/module/PhabricatorConfigCollectorsModule.php
··· 1 + <?php 2 + 3 + final class PhabricatorConfigCollectorsModule extends PhabricatorConfigModule { 4 + 5 + public function getModuleKey() { 6 + return 'collectors'; 7 + } 8 + 9 + public function getModuleName() { 10 + return pht('Garbage Collectors'); 11 + } 12 + 13 + public function renderModuleStatus(AphrontRequest $request) { 14 + $viewer = $request->getViewer(); 15 + 16 + $collectors = PhabricatorGarbageCollector::getAllCollectors(); 17 + $collectors = msort($collectors, 'getCollectorConstant'); 18 + 19 + $rows = array(); 20 + foreach ($collectors as $key => $collector) { 21 + if ($collector->hasAutomaticPolicy()) { 22 + $policy_view = phutil_tag('em', array(), pht('Automatic')); 23 + } else { 24 + $policy = $collector->getDefaultRetentionPolicy(); 25 + if ($policy === null) { 26 + $policy_view = pht('Indefinite'); 27 + } else { 28 + $days = ceil($policy / phutil_units('1 day in seconds')); 29 + $policy_view = pht( 30 + '%s Day(s)', 31 + new PhutilNumber($days)); 32 + } 33 + } 34 + 35 + $rows[] = array( 36 + $collector->getCollectorConstant(), 37 + $collector->getCollectorName(), 38 + $policy_view, 39 + ); 40 + } 41 + 42 + $table = id(new AphrontTableView($rows)) 43 + ->setHeaders( 44 + array( 45 + pht('Constant'), 46 + pht('Name'), 47 + pht('Retention Policy'), 48 + )) 49 + ->setColumnClasses( 50 + array( 51 + null, 52 + 'pri wide', 53 + null, 54 + )); 55 + 56 + return id(new PHUIObjectBoxView()) 57 + ->setHeaderText(pht('Garbage Collectors')) 58 + ->setTable($table); 59 + } 60 + 61 + }
+10
src/applications/daemon/garbagecollector/PhabricatorDaemonLogEventGarbageCollector.php
··· 3 3 final class PhabricatorDaemonLogEventGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'daemon.processes'; 7 + 8 + public function getCollectorName() { 9 + return pht('Daemon Processes'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('7 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.daemon-logs'); 8 18 if ($ttl <= 0) {
+10
src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php
··· 3 3 final class PhabricatorDaemonLogGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'daemon.logs'; 7 + 8 + public function getCollectorName() { 9 + return pht('Daemon Logs'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('7 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.daemon-logs'); 8 18 if ($ttl <= 0) {
+10
src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
··· 3 3 final class PhabricatorDaemonTaskGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'worker.tasks'; 7 + 8 + public function getCollectorName() { 9 + return pht('Archived Tasks'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('14 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $key = 'gcdaemon.ttl.task-archive'; 8 18 $ttl = PhabricatorEnv::getEnvConfig($key);
+10
src/applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php
··· 3 3 final class DifferentialParseCacheGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'differential.parse'; 7 + 8 + public function getCollectorName() { 9 + return pht('Differential Parse Cache'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('14 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $key = 'gcdaemon.ttl.differential-parse-cache'; 8 18 $ttl = PhabricatorEnv::getEnvConfig($key);
+10
src/applications/drydock/garbagecollector/DrydockLogGarbageCollector.php
··· 3 3 final class DrydockLogGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'drydock.logs'; 7 + 8 + public function getCollectorName() { 9 + return pht('Drydock Logs'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('30 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $log_table = new DrydockLog(); 8 18 $conn_w = $log_table->establishConnection('w');
+10
src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php
··· 3 3 final class PhabricatorFileTemporaryGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'files.ttl'; 7 + 8 + public function getCollectorName() { 9 + return pht('Files (TTL)'); 10 + } 11 + 12 + public function hasAutomaticPolicy() { 13 + return true; 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $files = id(new PhabricatorFile())->loadAllWhere( 8 18 'ttl < %d LIMIT 100',
+10
src/applications/herald/garbagecollector/HeraldTranscriptGarbageCollector.php
··· 3 3 final class HeraldTranscriptGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'herald.transcripts'; 7 + 8 + public function getCollectorName() { 9 + return pht('Herald Transcripts'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('30 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.herald-transcripts'); 8 18 if ($ttl <= 0) {
+10
src/applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php
··· 3 3 final class MetaMTAMailReceivedGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'metamta.received'; 7 + 8 + public function getCollectorName() { 9 + return pht('Mail (Received)'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('90 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = phutil_units('90 days in seconds'); 8 18
+10
src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php
··· 3 3 final class MetaMTAMailSentGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'metamta.sent'; 7 + 8 + public function getCollectorName() { 9 + return pht('Mail (Sent)'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('90 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = phutil_units('90 days in seconds'); 8 18
+10
src/applications/multimeter/garbagecollector/MultimeterEventGarbageCollector.php
··· 3 3 final class MultimeterEventGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'multimeter.events'; 7 + 8 + public function getCollectorName() { 9 + return pht('Multimeter Events'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('90 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = phutil_units('90 days in seconds'); 8 18
+10
src/applications/notification/garbagecollector/FeedStoryNotificationGarbageCollector.php
··· 3 3 final class FeedStoryNotificationGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'feed.notifications'; 7 + 8 + public function getCollectorName() { 9 + return pht('Notifications'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('90 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = 90 * 24 * 60 * 60; 8 18
+10
src/applications/people/garbagecollector/PeopleUserLogGarbageCollector.php
··· 3 3 final class PeopleUserLogGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'user.logs'; 7 + 8 + public function getCollectorName() { 9 + return pht('User Activity Logs'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('180 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = phutil_units('180 days in seconds'); 8 18
+10
src/applications/system/garbagecollector/PhabricatorSystemActionGarbageCollector.php
··· 3 3 final class PhabricatorSystemActionGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'system.actions'; 7 + 8 + public function getCollectorName() { 9 + return pht('Rate Limiting Actions'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('3 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = phutil_units('3 days in seconds'); 8 18
+10
src/applications/system/garbagecollector/PhabricatorSystemDestructionGarbageCollector.php
··· 3 3 final class PhabricatorSystemDestructionGarbageCollector 4 4 extends PhabricatorGarbageCollector { 5 5 6 + const COLLECTORCONST = 'system.destruction.logs'; 7 + 8 + public function getCollectorName() { 9 + return pht('Destruction Logs'); 10 + } 11 + 12 + public function getDefaultRetentionPolicy() { 13 + return phutil_units('90 days in seconds'); 14 + } 15 + 6 16 public function collectGarbage() { 7 17 $ttl = phutil_units('90 days in seconds'); 8 18
+73
src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollector.php
··· 1 1 <?php 2 2 3 + /** 4 + * @task info Getting Collector Information 5 + * @task collect Collecting Garbage 6 + */ 3 7 abstract class PhabricatorGarbageCollector extends Phobject { 4 8 9 + 10 + /* -( Getting Collector Information )-------------------------------------- */ 11 + 12 + 13 + /** 14 + * Get a human readable name for what this collector cleans up, like 15 + * "User Activity Logs". 16 + * 17 + * @return string Human-readable collector name. 18 + * @task info 19 + */ 20 + abstract public function getCollectorName(); 21 + 22 + 23 + /** 24 + * Specify that the collector has an automatic retention policy and 25 + * is not configurable. 26 + * 27 + * @return bool True if the collector has an automatic retention policy. 28 + * @task info 29 + */ 30 + public function hasAutomaticPolicy() { 31 + return false; 32 + } 33 + 34 + 35 + /** 36 + * Get the default retention policy for this collector. 37 + * 38 + * Return the age (in seconds) when resources start getting collected, or 39 + * `null` to retain resources indefinitely. 40 + * 41 + * @return int|null Lifetime, or `null` for indefinite retention. 42 + * @task info 43 + */ 44 + public function getDefaultRetentionPolicy() { 45 + throw new PhutilMethodNotImplementedException(); 46 + } 47 + 48 + 49 + /** 50 + * Get a unique string constant identifying this collector. 51 + * 52 + * @return string Collector constant. 53 + * @task info 54 + */ 55 + final public function getCollectorConstant() { 56 + return $this->getPhobjectClassConstant('COLLECTORCONST', 64); 57 + } 58 + 59 + 60 + /* -( Collecting Garbage )------------------------------------------------- */ 61 + 62 + 5 63 /** 6 64 * Collect garbage from whatever source this GC handles. 7 65 * 8 66 * @return bool True if there is more garbage to collect. 67 + * @task collect 9 68 */ 10 69 abstract public function collectGarbage(); 70 + 71 + 72 + /** 73 + * Load all of the available garbage collectors. 74 + * 75 + * @return list<PhabricatorGarbageCollector> Garbage collectors. 76 + * @task collect 77 + */ 78 + final public static function getAllCollectors() { 79 + return id(new PhutilClassMapQuery()) 80 + ->setAncestorClass(__CLASS__) 81 + ->setUniqueMethod('getCollectorConstant') 82 + ->execute(); 83 + } 11 84 12 85 }
+3 -15
src/infrastructure/daemon/workers/PhabricatorTriggerDaemon.php
··· 348 348 $next = $this->nextCollection; 349 349 if ($next && (PhabricatorTime::getNow() >= $next)) { 350 350 $this->nextCollection = null; 351 - $this->garbageCollectors = $this->loadGarbageCollectors(); 351 + 352 + $all_collectors = PhabricatorGarbageCollector::getAllCollectors(); 353 + $this->garbageCollectors = $all_collectors; 352 354 } 353 355 354 356 // If we're in a collection cycle, continue collection. ··· 376 378 377 379 return false; 378 380 } 379 - 380 - 381 - /** 382 - * Load all of the available garbage collectors. 383 - * 384 - * @return list<PhabricatorGarbageCollector> Garbage collectors. 385 - * @task garbage 386 - */ 387 - private function loadGarbageCollectors() { 388 - return id(new PhutilClassMapQuery()) 389 - ->setAncestorClass('PhabricatorGarbageCollector') 390 - ->execute(); 391 - } 392 - 393 381 394 382 }
+5
src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
··· 1388 1388 'Mail sent in the last %s days.', 1389 1389 ), 1390 1390 1391 + '%s Day(s)' => array( 1392 + '%s Day', 1393 + '%s Days', 1394 + ), 1395 + 1391 1396 ); 1392 1397 } 1393 1398