@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.

Allow maintenance scripts to write synthetic events to the push log that act as repository updates

Summary:
Ref T13614. When a script holds the write lock but modifies the repository directly (rather than by pushing), the repository version won't change when the script releases the write lock. Thus, the writes may not propagate to other nodes (it depends which node lucks out and accepts the next write).

To guarantee that writes propagate, allow these scripts to pretend they pushed the repository. These are bare-bones valid events flagged as "Maintenance".

Test Plan:
- Wrote a script to hold the write lock, wait (or pretend to do something), then release the write lock.
- Applied patches, modified script to use new APIs ("newMaintenanceEvent()").
- Ran script, saw repository verison bump and relevant push logs:

{F8814923}

Maniphest Tasks: T13614

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

+56 -7
+1 -7
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 216 216 $event->setRejectCode($this->rejectCode); 217 217 $event->setRejectDetails($this->rejectDetails); 218 218 219 - $event->openTransaction(); 220 - $event->save(); 221 - foreach ($all_updates as $update) { 222 - $update->setPushEventPHID($event->getPHID()); 223 - $update->save(); 224 - } 225 - $event->saveTransaction(); 219 + $event->saveWithLogs($all_updates); 226 220 227 221 if ($caught) { 228 222 throw $caught;
+37
src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php
··· 901 901 new PhutilNumber($duration))); 902 902 } 903 903 904 + public function newMaintenanceEvent() { 905 + $viewer = $this->getViewer(); 906 + $repository = $this->getRepository(); 907 + $now = PhabricatorTime::getNow(); 908 + 909 + $event = PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) 910 + ->setRepositoryPHID($repository->getPHID()) 911 + ->setEpoch($now) 912 + ->setPusherPHID($this->getEffectiveActingAsPHID()) 913 + ->setRejectCode(PhabricatorRepositoryPushLog::REJECT_ACCEPT); 914 + 915 + return $event; 916 + } 917 + 918 + public function newMaintenanceLog() { 919 + $viewer = $this->getViewer(); 920 + $repository = $this->getRepository(); 921 + $now = PhabricatorTime::getNow(); 922 + 923 + $device = AlmanacKeys::getLiveDevice(); 924 + if ($device) { 925 + $device_phid = $device->getPHID(); 926 + } else { 927 + $device_phid = null; 928 + } 929 + 930 + return PhabricatorRepositoryPushLog::initializeNewLog($viewer) 931 + ->setDevicePHID($device_phid) 932 + ->setRepositoryPHID($repository->getPHID()) 933 + ->attachRepository($repository) 934 + ->setEpoch($now) 935 + ->setPusherPHID($this->getEffectiveActingAsPHID()) 936 + ->setChangeFlags(PhabricatorRepositoryPushLog::CHANGEFLAG_MAINTENANCE) 937 + ->setRefType(PhabricatorRepositoryPushLog::REFTYPE_MAINTENANCE) 938 + ->setRefNew(''); 939 + } 940 + 904 941 }
+15
src/applications/repository/storage/PhabricatorRepositoryPushEvent.php
··· 81 81 return $this->assertAttached($this->logs); 82 82 } 83 83 84 + public function saveWithLogs(array $logs) { 85 + assert_instances_of($logs, 'PhabricatorRepositoryPushLog'); 86 + 87 + $this->openTransaction(); 88 + $this->save(); 89 + foreach ($logs as $log) { 90 + $log->setPushEventPHID($this->getPHID()); 91 + $log->save(); 92 + } 93 + $this->saveTransaction(); 94 + 95 + $this->attachLogs($logs); 96 + 97 + return $this; 98 + } 84 99 85 100 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 86 101
+3
src/applications/repository/storage/PhabricatorRepositoryPushLog.php
··· 18 18 const REFTYPE_BOOKMARK = 'bookmark'; 19 19 const REFTYPE_COMMIT = 'commit'; 20 20 const REFTYPE_REF = 'ref'; 21 + const REFTYPE_MAINTENANCE = 'maintenance'; 21 22 22 23 const CHANGEFLAG_ADD = 1; 23 24 const CHANGEFLAG_DELETE = 2; ··· 27 28 const CHANGEFLAG_ENORMOUS = 32; 28 29 const CHANGEFLAG_OVERSIZED = 64; 29 30 const CHANGEFLAG_TOUCHES = 128; 31 + const CHANGEFLAG_MAINTENANCE = 256; 30 32 31 33 const REJECT_ACCEPT = 0; 32 34 const REJECT_DANGEROUS = 1; ··· 70 72 self::CHANGEFLAG_ENORMOUS => pht('Enormous'), 71 73 self::CHANGEFLAG_OVERSIZED => pht('Oversized'), 72 74 self::CHANGEFLAG_TOUCHES => pht('Touches Too Many Paths'), 75 + self::CHANGEFLAG_MAINTENANCE => pht('Maintenance'), 73 76 ); 74 77 } 75 78