Record more details about where a write is taking place while holding a cluster lock
Summary: Ref T4292. This will let the UI and future `bin/repository` tools give administrators more tools to understand problems when reporting or resolving them. Test Plan: - Pushed fully clean repository. - Pushed previously-pushed repository. - Forced write to abort, inspected useful information in the database. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4292 Differential Revision: https://secure.phabricator.com/D15748
This commit is contained in:
		
							
								
								
									
										2
									
								
								resources/sql/autopatches/20160418.repoversion.1.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								resources/sql/autopatches/20160418.repoversion.1.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | ALTER TABLE {$NAMESPACE}_repository.repository_workingcopyversion | ||||||
|  |   ADD writeProperties LONGTEXT COLLATE {$COLLATE_TEXT}; | ||||||
| @@ -26,7 +26,8 @@ final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow { | |||||||
|       $command = csprintf('git-receive-pack %s', $repository->getLocalPath()); |       $command = csprintf('git-receive-pack %s', $repository->getLocalPath()); | ||||||
|  |  | ||||||
|       $did_synchronize = true; |       $did_synchronize = true; | ||||||
|       $repository->synchronizeWorkingCopyBeforeWrite(); |       $viewer = $this->getUser(); | ||||||
|  |       $repository->synchronizeWorkingCopyBeforeWrite($viewer); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $caught = null; |     $caught = null; | ||||||
|   | |||||||
| @@ -2482,7 +2482,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO | |||||||
|   /** |   /** | ||||||
|    * @task sync |    * @task sync | ||||||
|    */ |    */ | ||||||
|   public function synchronizeWorkingCopyBeforeWrite() { |   public function synchronizeWorkingCopyBeforeWrite( | ||||||
|  |     PhabricatorUser $actor) { | ||||||
|     if (!$this->shouldEnableSynchronization()) { |     if (!$this->shouldEnableSynchronization()) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| @@ -2516,7 +2517,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO | |||||||
|  |  | ||||||
|     PhabricatorRepositoryWorkingCopyVersion::willWrite( |     PhabricatorRepositoryWorkingCopyVersion::willWrite( | ||||||
|       $repository_phid, |       $repository_phid, | ||||||
|       $device_phid); |       $device_phid, | ||||||
|  |       array( | ||||||
|  |         'userPHID' => $actor->getPHID(), | ||||||
|  |         'epoch' => PhabricatorTime::getNow(), | ||||||
|  |         'devicePHID' => $device_phid, | ||||||
|  |       )); | ||||||
|  |  | ||||||
|     $this->clusterWriteVersion = $max_version; |     $this->clusterWriteVersion = $max_version; | ||||||
|     $this->clusterWriteLock = $write_lock; |     $this->clusterWriteLock = $write_lock; | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ final class PhabricatorRepositoryWorkingCopyVersion | |||||||
|   protected $devicePHID; |   protected $devicePHID; | ||||||
|   protected $repositoryVersion; |   protected $repositoryVersion; | ||||||
|   protected $isWriting; |   protected $isWriting; | ||||||
|  |   protected $writeProperties; | ||||||
|  |  | ||||||
|   protected function getConfiguration() { |   protected function getConfiguration() { | ||||||
|     return array( |     return array( | ||||||
| @@ -14,6 +15,7 @@ final class PhabricatorRepositoryWorkingCopyVersion | |||||||
|       self::CONFIG_COLUMN_SCHEMA => array( |       self::CONFIG_COLUMN_SCHEMA => array( | ||||||
|         'repositoryVersion' => 'uint32', |         'repositoryVersion' => 'uint32', | ||||||
|         'isWriting' => 'bool', |         'isWriting' => 'bool', | ||||||
|  |         'writeProperties' => 'text?', | ||||||
|       ), |       ), | ||||||
|       self::CONFIG_KEY_SCHEMA => array( |       self::CONFIG_KEY_SCHEMA => array( | ||||||
|         'key_workingcopy' => array( |         'key_workingcopy' => array( | ||||||
| @@ -66,7 +68,10 @@ final class PhabricatorRepositoryWorkingCopyVersion | |||||||
|    * 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($repository_phid, $device_phid) { |   public static function willWrite( | ||||||
|  |     $repository_phid, | ||||||
|  |     $device_phid, | ||||||
|  |     array $write_properties) { | ||||||
|     $version = new self(); |     $version = new self(); | ||||||
|     $conn_w = $version->establishConnection('w'); |     $conn_w = $version->establishConnection('w'); | ||||||
|     $table = $version->getTableName(); |     $table = $version->getTableName(); | ||||||
| @@ -74,16 +79,19 @@ final class PhabricatorRepositoryWorkingCopyVersion | |||||||
|     queryfx( |     queryfx( | ||||||
|       $conn_w, |       $conn_w, | ||||||
|       'INSERT INTO %T |       'INSERT INTO %T | ||||||
|         (repositoryPHID, devicePHID, repositoryVersion, isWriting) |         (repositoryPHID, devicePHID, repositoryVersion, isWriting, | ||||||
|  |           writeProperties) | ||||||
|         VALUES |         VALUES | ||||||
|         (%s, %s, %d, %d) |         (%s, %s, %d, %d, %s) | ||||||
|         ON DUPLICATE KEY UPDATE |         ON DUPLICATE KEY UPDATE | ||||||
|           isWriting = VALUES(isWriting)', |           isWriting = VALUES(isWriting), | ||||||
|  |           writeProperties = VALUES(writeProperties)', | ||||||
|       $table, |       $table, | ||||||
|       $repository_phid, |       $repository_phid, | ||||||
|       $device_phid, |       $device_phid, | ||||||
|       0, |       0, | ||||||
|       1); |       1, | ||||||
|  |       phutil_json_encode($write_properties)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -101,7 +109,10 @@ final class PhabricatorRepositoryWorkingCopyVersion | |||||||
|  |  | ||||||
|     queryfx( |     queryfx( | ||||||
|       $conn_w, |       $conn_w, | ||||||
|       'UPDATE %T SET repositoryVersion = %d, isWriting = 0 |       'UPDATE %T SET | ||||||
|  |           repositoryVersion = %d, | ||||||
|  |           isWriting = 0, | ||||||
|  |           writeProperties = null | ||||||
|         WHERE |         WHERE | ||||||
|           repositoryPHID = %s AND |           repositoryPHID = %s AND | ||||||
|           devicePHID = %s AND |           devicePHID = %s AND | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley