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

Use "w" transactions for reading if they exist, so we can do transactional reads

Summary: Generally moves us toward having a sane approach to transaction handling.

Test Plan: See test case, which fails before this patch and passes afterwards.

Reviewers: vrana, btrahan, jungejason

Reviewed By: vrana

CC: aran

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

+50 -3
+13 -3
src/storage/lisk/dao/LiskDAO.php
··· 817 817 $mode = 'w'; 818 818 } 819 819 820 - // TODO There is currently no protection on 'r' queries against writing 821 - // or on 'w' queries against reading 820 + // TODO: There is currently no protection on 'r' queries against writing. 822 821 823 - $connection = $this->getEstablishedConnection($mode); 822 + $connection = null; 823 + if ($mode == 'r') { 824 + // If we're requesting a read connection but already have a write 825 + // connection, reuse the write connection so that reads can take place 826 + // inside transactions. 827 + $connection = $this->getEstablishedConnection('w'); 828 + } 829 + 830 + if (!$connection) { 831 + $connection = $this->getEstablishedConnection($mode); 832 + } 833 + 824 834 if (!$connection) { 825 835 $connection = $this->establishLiveConnection($mode); 826 836 if (self::shouldIsolateAllLiskEffectsToTransactions()) {
+36
src/storage/lisk/dao/__tests__/LiskFixtureTestCase.php
··· 66 66 count(id(new PhabricatorUser())->loadAll())); 67 67 } 68 68 69 + public function testReadableTransactions() { 70 + // TODO: When we have semi-durable fixtures, use those instead. This is 71 + // extremely hacky. 72 + 73 + LiskDAO::endIsolateAllLiskEffectsToTransactions(); 74 + try { 75 + 76 + $phid = 'PHID-TEST-'.Filesystem::readRandomCharacters(32); 77 + 78 + $obj = new PhabricatorPHID(); 79 + $obj->openTransaction(); 80 + 81 + $obj->setPHID($phid); 82 + $obj->setPHIDType('TEST'); 83 + $obj->save(); 84 + 85 + $loaded = id(new PhabricatorPHID())->loadOneWhere( 86 + 'phid = %s', 87 + $phid); 88 + 89 + $obj->killTransaction(); 90 + 91 + $this->assertEqual( 92 + true, 93 + ($loaded !== null), 94 + "Reads inside transactions should have transaction visibility."); 95 + 96 + LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 97 + } catch (Exception $ex) { 98 + LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 99 + throw $ex; 100 + } 101 + } 102 + 103 + 104 + 69 105 }
+1
src/storage/lisk/dao/__tests__/__init__.php
··· 11 11 phutil_require_module('phabricator', 'infrastructure/testing/testcase'); 12 12 phutil_require_module('phabricator', 'storage/lisk/dao'); 13 13 14 + phutil_require_module('phutil', 'filesystem'); 14 15 phutil_require_module('phutil', 'utils'); 15 16 16 17