Differential D15792 Diff 38039 src/applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php
| <?php | <?php | ||||
| final class PhabricatorRepositoryWorkingCopyVersion | final class PhabricatorRepositoryWorkingCopyVersion | ||||
| extends PhabricatorRepositoryDAO { | extends PhabricatorRepositoryDAO { | ||||
| protected $repositoryPHID; | protected $repositoryPHID; | ||||
| protected $devicePHID; | protected $devicePHID; | ||||
| protected $repositoryVersion; | protected $repositoryVersion; | ||||
| protected $isWriting; | protected $isWriting; | ||||
| protected $lockOwner; | |||||
| protected $writeProperties; | protected $writeProperties; | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_TIMESTAMPS => false, | self::CONFIG_TIMESTAMPS => false, | ||||
| self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
| 'repositoryVersion' => 'uint32', | 'repositoryVersion' => 'uint32', | ||||
| 'isWriting' => 'bool', | 'isWriting' => 'bool', | ||||
| 'writeProperties' => 'text?', | 'writeProperties' => 'text?', | ||||
| 'lockOwner' => 'text255?', | |||||
| ), | ), | ||||
| self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
| 'key_workingcopy' => array( | 'key_workingcopy' => array( | ||||
| 'columns' => array('repositoryPHID', 'devicePHID'), | 'columns' => array('repositoryPHID', 'devicePHID'), | ||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| ), | ), | ||||
| ) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
| Show All 37 Lines | final class PhabricatorRepositoryWorkingCopyVersion | ||||
| * may have committed and acknowledged a write on a node that lost the lock | * may have committed and acknowledged a write on a node that lost the lock | ||||
| * partway through the write and is no longer reachable. | * partway through the write and is no longer reachable. | ||||
| * | * | ||||
| * In particular, if a node loses its connection to the datbase the global | * In particular, if a node loses its connection to the datbase the global | ||||
| * lock is released by default. This is a durable lock which stays locked | * lock is released by default. This is a durable lock which stays locked | ||||
| * by default. | * by default. | ||||
| */ | */ | ||||
| public static function willWrite( | public static function willWrite( | ||||
| AphrontDatabaseConnection $locked_connection, | |||||
| $repository_phid, | $repository_phid, | ||||
| $device_phid, | $device_phid, | ||||
| array $write_properties) { | array $write_properties, | ||||
| $lock_owner) { | |||||
| $version = new self(); | $version = new self(); | ||||
| $conn_w = $version->establishConnection('w'); | |||||
| $table = $version->getTableName(); | $table = $version->getTableName(); | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $locked_connection, | ||||
| 'INSERT INTO %T | 'INSERT INTO %T | ||||
| (repositoryPHID, devicePHID, repositoryVersion, isWriting, | (repositoryPHID, devicePHID, repositoryVersion, isWriting, | ||||
| writeProperties) | writeProperties, lockOwner) | ||||
| VALUES | VALUES | ||||
| (%s, %s, %d, %d, %s) | (%s, %s, %d, %d, %s, %s) | ||||
| ON DUPLICATE KEY UPDATE | ON DUPLICATE KEY UPDATE | ||||
| isWriting = VALUES(isWriting), | isWriting = VALUES(isWriting), | ||||
| writeProperties = VALUES(writeProperties)', | writeProperties = VALUES(writeProperties), | ||||
| lockOwner = VALUES(lockOwner)', | |||||
| $table, | $table, | ||||
| $repository_phid, | $repository_phid, | ||||
| $device_phid, | $device_phid, | ||||
| 0, | 0, | ||||
| 1, | 1, | ||||
| phutil_json_encode($write_properties)); | phutil_json_encode($write_properties), | ||||
| $lock_owner); | |||||
| } | } | ||||
| /** | /** | ||||
| * After a write, update the version and release the "isWriting" lock. | * After a write, update the version and release the "isWriting" lock. | ||||
| */ | */ | ||||
| public static function didWrite( | public static function didWrite( | ||||
| $repository_phid, | $repository_phid, | ||||
| $device_phid, | $device_phid, | ||||
| $old_version, | $old_version, | ||||
| $new_version) { | $new_version, | ||||
| $lock_owner) { | |||||
| $version = new self(); | $version = new self(); | ||||
| $conn_w = $version->establishConnection('w'); | $conn_w = $version->establishConnection('w'); | ||||
| $table = $version->getTableName(); | $table = $version->getTableName(); | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET | 'UPDATE %T SET | ||||
| repositoryVersion = %d, | repositoryVersion = %d, | ||||
| isWriting = 0 | isWriting = 0, | ||||
| lockOwner = NULL | |||||
| WHERE | WHERE | ||||
| repositoryPHID = %s AND | repositoryPHID = %s AND | ||||
| devicePHID = %s AND | devicePHID = %s AND | ||||
| repositoryVersion = %d AND | repositoryVersion = %d AND | ||||
| isWriting = 1', | isWriting = 1 AND | ||||
| lockOwner = %s', | |||||
| $table, | $table, | ||||
| $new_version, | $new_version, | ||||
| $repository_phid, | $repository_phid, | ||||
| $device_phid, | $device_phid, | ||||
| $old_version); | $old_version, | ||||
| $lock_owner); | |||||
| } | } | ||||
| /** | /** | ||||
| * After a fetch, set the local version to the fetched version. | * After a fetch, set the local version to the fetched version. | ||||
| */ | */ | ||||
| public static function updateVersion( | public static function updateVersion( | ||||
| $repository_phid, | $repository_phid, | ||||
| ▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines | |||||