From 9f35c7cc2675d607b355063229202a38d9770dbd Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 15 Jan 2014 10:02:31 -0800 Subject: [PATCH] Complete modularization of the GC daemon Summary: This modularizes the rest of the GC submethods. Turned out there was nothing tricky. Test Plan: Ran `bin/phd debug garbage` and got reasonable looking behavior and output. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7971 --- src/__phutil_library_map__.php | 18 ++ ...habricatorCacheGeneralGarbageCollector.php | 26 ++ ...PhabricatorCacheMarkupGarbageCollector.php | 25 ++ .../PhabricatorCacheTTLGarbageCollector.php | 20 ++ .../ConduitConnectionGarbageCollector.php | 25 ++ .../ConduitLogGarbageCollector.php | 25 ++ .../PhabricatorDaemonLogGarbageCollector.php | 24 ++ .../PhabricatorDaemonTaskGarbageCollector.php | 48 ++++ ...DifferentialParseCacheGarbageCollector.php | 25 ++ ...abricatorFileTemporaryGarbageCollector.php | 18 ++ .../PhabricatorGarbageCollectorDaemon.php | 239 +----------------- 11 files changed, 259 insertions(+), 234 deletions(-) create mode 100644 src/applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php create mode 100644 src/applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php create mode 100644 src/applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php create mode 100644 src/applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php create mode 100644 src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php create mode 100644 src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php create mode 100644 src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php create mode 100644 src/applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php create mode 100644 src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 58eb35f0a8..0be73ee579 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -259,7 +259,9 @@ phutil_register_library_map(array( 'ConduitAPI_user_whoami_Method' => 'applications/people/conduit/ConduitAPI_user_whoami_Method.php', 'ConduitCall' => 'applications/conduit/call/ConduitCall.php', 'ConduitCallTestCase' => 'applications/conduit/call/__tests__/ConduitCallTestCase.php', + 'ConduitConnectionGarbageCollector' => 'applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php', 'ConduitException' => 'applications/conduit/protocol/ConduitException.php', + 'ConduitLogGarbageCollector' => 'applications/conduit/garbagecollector/ConduitLogGarbageCollector.php', 'ConduitSSHWorkflow' => 'applications/conduit/ssh/ConduitSSHWorkflow.php', 'ConpherenceActionMenuEventListener' => 'applications/conpherence/events/ConpherenceActionMenuEventListener.php', 'ConpherenceConfigOptions' => 'applications/conpherence/config/ConpherenceConfigOptions.php', @@ -413,6 +415,7 @@ phutil_register_library_map(array( 'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php', 'DifferentialPHIDTypeDiff' => 'applications/differential/phid/DifferentialPHIDTypeDiff.php', 'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php', + 'DifferentialParseCacheGarbageCollector' => 'applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php', 'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php', 'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php', 'DifferentialPrimaryPaneView' => 'applications/differential/view/DifferentialPrimaryPaneView.php', @@ -1236,8 +1239,11 @@ phutil_register_library_map(array( 'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php', 'PhabricatorBusyExample' => 'applications/uiexample/examples/PhabricatorBusyExample.php', 'PhabricatorCacheDAO' => 'applications/cache/storage/PhabricatorCacheDAO.php', + 'PhabricatorCacheGeneralGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php', 'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php', 'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php', + 'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php', + 'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php', 'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php', 'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/PhabricatorCalendarBrowseController.php', 'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php', @@ -1350,6 +1356,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonLogEvent' => 'applications/daemon/storage/PhabricatorDaemonLogEvent.php', 'PhabricatorDaemonLogEventViewController' => 'applications/daemon/controller/PhabricatorDaemonLogEventViewController.php', 'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php', + 'PhabricatorDaemonLogGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php', 'PhabricatorDaemonLogListController' => 'applications/daemon/controller/PhabricatorDaemonLogListController.php', 'PhabricatorDaemonLogListView' => 'applications/daemon/view/PhabricatorDaemonLogListView.php', 'PhabricatorDaemonLogQuery' => 'applications/daemon/query/PhabricatorDaemonLogQuery.php', @@ -1364,6 +1371,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonManagementStopWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStopWorkflow.php', 'PhabricatorDaemonManagementWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementWorkflow.php', 'PhabricatorDaemonReference' => 'infrastructure/daemon/control/PhabricatorDaemonReference.php', + 'PhabricatorDaemonTaskGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php', 'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php', 'PhabricatorDebugController' => 'applications/system/PhabricatorDebugController.php', 'PhabricatorDefaultFileStorageEngineSelector' => 'applications/files/engineselector/PhabricatorDefaultFileStorageEngineSelector.php', @@ -1472,6 +1480,7 @@ phutil_register_library_map(array( 'PhabricatorFileStorageConfigurationException' => 'applications/files/exception/PhabricatorFileStorageConfigurationException.php', 'PhabricatorFileStorageEngine' => 'applications/files/engine/PhabricatorFileStorageEngine.php', 'PhabricatorFileStorageEngineSelector' => 'applications/files/engineselector/PhabricatorFileStorageEngineSelector.php', + 'PhabricatorFileTemporaryGarbageCollector' => 'applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php', 'PhabricatorFileTestCase' => 'applications/files/storage/__tests__/PhabricatorFileTestCase.php', 'PhabricatorFileTestDataGenerator' => 'applications/files/lipsum/PhabricatorFileTestDataGenerator.php', 'PhabricatorFileTransaction' => 'applications/files/storage/PhabricatorFileTransaction.php', @@ -2699,7 +2708,9 @@ phutil_register_library_map(array( 'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method', 'ConduitCallTestCase' => 'PhabricatorTestCase', + 'ConduitConnectionGarbageCollector' => 'PhabricatorGarbageCollector', 'ConduitException' => 'Exception', + 'ConduitLogGarbageCollector' => 'PhabricatorGarbageCollector', 'ConduitSSHWorkflow' => 'PhabricatorSSHWorkflow', 'ConpherenceActionMenuEventListener' => 'PhabricatorEventListener', 'ConpherenceConfigOptions' => 'PhabricatorApplicationConfigOptions', @@ -2847,6 +2858,7 @@ phutil_register_library_map(array( 'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail', 'DifferentialPHIDTypeDiff' => 'PhabricatorPHIDType', 'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType', + 'DifferentialParseCacheGarbageCollector' => 'PhabricatorGarbageCollector', 'DifferentialParseRenderTestCase' => 'PhabricatorTestCase', 'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialPrimaryPaneView' => 'AphrontView', @@ -3803,8 +3815,11 @@ phutil_register_library_map(array( 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', 'PhabricatorBusyExample' => 'PhabricatorUIExample', 'PhabricatorCacheDAO' => 'PhabricatorLiskDAO', + 'PhabricatorCacheGeneralGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorCacheManagementWorkflow', 'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow', + 'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector', + 'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController', 'PhabricatorCalendarController' => 'PhabricatorController', 'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO', @@ -3944,6 +3959,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO', 'PhabricatorDaemonLogEventViewController' => 'PhabricatorDaemonController', 'PhabricatorDaemonLogEventsView' => 'AphrontView', + 'PhabricatorDaemonLogGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorDaemonLogListController' => 'PhabricatorDaemonController', 'PhabricatorDaemonLogListView' => 'AphrontView', 'PhabricatorDaemonLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -3957,6 +3973,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow', 'PhabricatorDaemonManagementStopWorkflow' => 'PhabricatorDaemonManagementWorkflow', 'PhabricatorDaemonManagementWorkflow' => 'PhabricatorManagementWorkflow', + 'PhabricatorDaemonTaskGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorDataNotAttachedException' => 'Exception', 'PhabricatorDebugController' => 'PhabricatorController', 'PhabricatorDefaultFileStorageEngineSelector' => 'PhabricatorFileStorageEngineSelector', @@ -4079,6 +4096,7 @@ phutil_register_library_map(array( 'PhabricatorFileShortcutController' => 'PhabricatorFileController', 'PhabricatorFileStorageBlob' => 'PhabricatorFileDAO', 'PhabricatorFileStorageConfigurationException' => 'Exception', + 'PhabricatorFileTemporaryGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorFileTestCase' => 'PhabricatorTestCase', 'PhabricatorFileTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorFileTransaction' => 'PhabricatorApplicationTransaction', diff --git a/src/applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php b/src/applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php new file mode 100644 index 0000000000..29ad8ffb18 --- /dev/null +++ b/src/applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php @@ -0,0 +1,26 @@ +establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE cacheCreated < %d + ORDER BY cacheCreated ASC LIMIT 100', + $cache->getTableName(), + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php b/src/applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php new file mode 100644 index 0000000000..75b25e2530 --- /dev/null +++ b/src/applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php @@ -0,0 +1,25 @@ +establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', + $table->getTableName(), + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php b/src/applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php new file mode 100644 index 0000000000..c459553396 --- /dev/null +++ b/src/applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php @@ -0,0 +1,20 @@ +establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE cacheExpires < %d + ORDER BY cacheExpires ASC LIMIT 100', + $cache->getTableName(), + time()); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php b/src/applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php new file mode 100644 index 0000000000..14467af2bf --- /dev/null +++ b/src/applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php @@ -0,0 +1,25 @@ +establishConnection('w'); + queryfx( + $conn_w, + 'DELETE FROM %T WHERE dateCreated < %d + ORDER BY dateCreated ASC LIMIT 100', + $table->getTableName(), + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php b/src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php new file mode 100644 index 0000000000..9ed39d5832 --- /dev/null +++ b/src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php @@ -0,0 +1,25 @@ +establishConnection('w'); + queryfx( + $conn_w, + 'DELETE FROM %T WHERE dateCreated < %d + ORDER BY dateCreated ASC LIMIT 100', + $table->getTableName(), + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php b/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php new file mode 100644 index 0000000000..22a11523ae --- /dev/null +++ b/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php @@ -0,0 +1,24 @@ +establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE epoch < %d LIMIT 100', + $table->getTableName(), + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php b/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php new file mode 100644 index 0000000000..331462323d --- /dev/null +++ b/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php @@ -0,0 +1,48 @@ +establishConnection('w'); + + $rows = queryfx_all( + $conn_w, + 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100', + $table->getTableName(), + time() - $ttl); + + if (!$rows) { + return false; + } + + $data_ids = array_filter(ipull($rows, 'dataID')); + $task_ids = ipull($rows, 'id'); + + $table->openTransaction(); + if ($data_ids) { + queryfx( + $conn_w, + 'DELETE FROM %T WHERE id IN (%Ld)', + $data_table->getTableName(), + $data_ids); + } + queryfx( + $conn_w, + 'DELETE FROM %T WHERE id IN (%Ld)', + $table->getTableName(), + $task_ids); + $table->saveTransaction(); + + return (count($task_ids) == 100); + } + +} diff --git a/src/applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php b/src/applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php new file mode 100644 index 0000000000..08cdfe97db --- /dev/null +++ b/src/applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php @@ -0,0 +1,25 @@ +establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', + DifferentialChangeset::TABLE_CACHE, + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php b/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php new file mode 100644 index 0000000000..624ec01097 --- /dev/null +++ b/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php @@ -0,0 +1,18 @@ +loadAllWhere( + 'ttl < %d LIMIT 100', + time()); + + foreach ($files as $file) { + $file->delete(); + } + + return (count($files) == 100); + } + +} diff --git a/src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollectorDaemon.php b/src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollectorDaemon.php index 917bd6792c..5982a8de8a 100644 --- a/src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollectorDaemon.php +++ b/src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollectorDaemon.php @@ -3,8 +3,6 @@ /** * Collects old logs and caches to reduce the amount of data stored in the * database. - * - * @group daemon */ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon { @@ -14,40 +12,6 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon { ->loadObjects(); do { - $n_daemon = $this->collectDaemonLogs(); - $n_parse = $this->collectParseCaches(); - $n_markup = $this->collectMarkupCaches(); - $n_tasks = $this->collectArchivedTasks(); - $n_cache_ttl = $this->collectGeneralCacheTTL(); - $n_cache = $this->collectGeneralCaches(); - $n_files = $this->collectExpiredFiles(); - $n_clogs = $this->collectExpiredConduitLogs(); - $n_ccons = $this->collectExpiredConduitConnections(); - - $collected = array( - 'Daemon Log' => $n_daemon, - 'Differential Parse Cache' => $n_parse, - 'Markup Cache' => $n_markup, - 'Archived Tasks' => $n_tasks, - 'General Cache TTL' => $n_cache_ttl, - 'General Cache Entries' => $n_cache, - 'Temporary Files' => $n_files, - 'Conduit Logs' => $n_clogs, - 'Conduit Connections' => $n_ccons, - ); - $collected = array_filter($collected); - - foreach ($collected as $thing => $count) { - $count = number_format($count); - $this->log("Garbage collected {$count} '{$thing}' objects."); - } - - $total = array_sum($collected); - - // TODO: This logic is unnecessarily complex for now to facilitate a - // gradual conversion to the new GC infrastructure. - - $had_more_garbage = false; foreach ($collectors as $name => $collector) { $more_garbage = false; do { @@ -58,210 +22,17 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon { } $more_garbage = $collector->collectGarbage(); - if ($more_garbage) { - $had_more_garbage = true; - } $this->stillWorking(); } while ($more_garbage); } - if ($had_more_garbage) { - $total += 100; - } - - if ($total < 100) { - // We didn't max out any of the GCs so we're basically caught up. Ease - // off the GC loop so we don't keep doing table scans just to delete - // a handful of rows; wake up in a few hours. - $this->sleep(4 * (60 * 60)); - } else { - $this->stillWorking(); - } + // We made it to the end of the run cycle of every GC, so we're more or + // less caught up. Ease off the GC loop so we don't keep doing table + // scans just to delete a handful of rows; wake up in a few hours. + $this->log(pht('All caught up, waiting for more garbage.')); + $this->sleep(4 * (60 * 60)); } while (true); } - private function collectDaemonLogs() { - $ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.daemon-logs'); - if ($ttl <= 0) { - return 0; - } - - $table = new PhabricatorDaemonLogEvent(); - $conn_w = $table->establishConnection('w'); - - queryfx( - $conn_w, - 'DELETE FROM %T WHERE epoch < %d LIMIT 100', - $table->getTableName(), - time() - $ttl); - - return $conn_w->getAffectedRows(); - } - - private function collectParseCaches() { - $key = 'gcdaemon.ttl.differential-parse-cache'; - $ttl = PhabricatorEnv::getEnvConfig($key); - if ($ttl <= 0) { - return 0; - } - - $table = new DifferentialChangeset(); - $conn_w = $table->establishConnection('w'); - - queryfx( - $conn_w, - 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', - DifferentialChangeset::TABLE_CACHE, - time() - $ttl); - - return $conn_w->getAffectedRows(); - } - - private function collectMarkupCaches() { - $key = 'gcdaemon.ttl.markup-cache'; - $ttl = PhabricatorEnv::getEnvConfig($key); - if ($ttl <= 0) { - return 0; - } - - $table = new PhabricatorMarkupCache(); - $conn_w = $table->establishConnection('w'); - - queryfx( - $conn_w, - 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', - $table->getTableName(), - time() - $ttl); - - return $conn_w->getAffectedRows(); - } - - private function collectArchivedTasks() { - $key = 'gcdaemon.ttl.task-archive'; - $ttl = PhabricatorEnv::getEnvConfig($key); - if ($ttl <= 0) { - return 0; - } - - $table = new PhabricatorWorkerArchiveTask(); - $data_table = new PhabricatorWorkerTaskData(); - $conn_w = $table->establishConnection('w'); - - $rows = queryfx_all( - $conn_w, - 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100', - $table->getTableName(), - time() - $ttl); - - if (!$rows) { - return 0; - } - - $data_ids = array_filter(ipull($rows, 'dataID')); - $task_ids = ipull($rows, 'id'); - - $table->openTransaction(); - if ($data_ids) { - queryfx( - $conn_w, - 'DELETE FROM %T WHERE id IN (%Ld)', - $data_table->getTableName(), - $data_ids); - } - queryfx( - $conn_w, - 'DELETE FROM %T WHERE id IN (%Ld)', - $table->getTableName(), - $task_ids); - $table->saveTransaction(); - - return count($task_ids); - } - - - private function collectGeneralCacheTTL() { - $cache = new PhabricatorKeyValueDatabaseCache(); - $conn_w = $cache->establishConnection('w'); - - queryfx( - $conn_w, - 'DELETE FROM %T WHERE cacheExpires < %d - ORDER BY cacheExpires ASC LIMIT 100', - $cache->getTableName(), - time()); - - return $conn_w->getAffectedRows(); - } - - - private function collectGeneralCaches() { - $key = 'gcdaemon.ttl.general-cache'; - $ttl = PhabricatorEnv::getEnvConfig($key); - if ($ttl <= 0) { - return 0; - } - - $cache = new PhabricatorKeyValueDatabaseCache(); - $conn_w = $cache->establishConnection('w'); - - queryfx( - $conn_w, - 'DELETE FROM %T WHERE cacheCreated < %d - ORDER BY cacheCreated ASC LIMIT 100', - $cache->getTableName(), - time() - $ttl); - - return $conn_w->getAffectedRows(); - } - - private function collectExpiredFiles() { - $files = id(new PhabricatorFile())->loadAllWhere('ttl < %d LIMIT 100', - time()); - - foreach ($files as $file) { - $file->delete(); - } - - return count($files); - } - - private function collectExpiredConduitLogs() { - $key = 'gcdaemon.ttl.conduit-logs'; - $ttl = PhabricatorEnv::getEnvConfig($key); - if ($ttl <= 0) { - return 0; - } - - $table = new PhabricatorConduitMethodCallLog(); - $conn_w = $table->establishConnection('w'); - queryfx( - $conn_w, - 'DELETE FROM %T WHERE dateCreated < %d - ORDER BY dateCreated ASC LIMIT 100', - $table->getTableName(), - time() - $ttl); - - return $conn_w->getAffectedRows(); - } - - private function collectExpiredConduitConnections() { - $key = 'gcdaemon.ttl.conduit-logs'; - $ttl = PhabricatorEnv::getEnvConfig($key); - if ($ttl <= 0) { - return 0; - } - - $table = new PhabricatorConduitConnectionLog(); - $conn_w = $table->establishConnection('w'); - queryfx( - $conn_w, - 'DELETE FROM %T WHERE dateCreated < %d - ORDER BY dateCreated ASC LIMIT 100', - $table->getTableName(), - time() - $ttl); - - return $conn_w->getAffectedRows(); - } - }