Index: branches/FileBackend/phase3/maintenance/locking/file_locks.sql |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | -- Table to handle resource locking (EX) with row-level locking |
3 | 3 | CREATE TABLE /*_*/filelocks_exclusive ( |
4 | | - fle_key binary(40) NOT NULL PRIMARY KEY |
| 4 | + fle_key binary(31) NOT NULL PRIMARY KEY |
5 | 5 | ) ENGINE=InnoDB, CHECKSUM=0; |
6 | 6 | |
7 | 7 | -- Table to handle resource locking (SH) with row-level locking |
8 | 8 | CREATE TABLE /*_*/filelocks_shared ( |
9 | | - fls_key binary(40) NOT NULL, |
| 9 | + fls_key binary(31) NOT NULL, |
10 | 10 | fls_session integer unsigned NOT NULL, |
11 | 11 | PRIMARY KEY (fls_key,fls_session) |
12 | 12 | ) ENGINE=InnoDB, CHECKSUM=0; |
Index: branches/FileBackend/phase3/maintenance/locking/LockServerDaemon.php |
— | — | @@ -228,7 +228,7 @@ |
229 | 229 | list( $session, $key, $command, $type, $values ) = $m; |
230 | 230 | if ( sha1( $session . $command . $type . $values . $this->authKey ) !== $key ) { |
231 | 231 | return 'BAD_KEY'; |
232 | | - } elseif ( strlen( $session ) !== 40 ) { |
| 232 | + } elseif ( strlen( $session ) !== 31 ) { |
233 | 233 | return 'BAD_SESSION'; |
234 | 234 | } |
235 | 235 | $values = explode( '|', $values ); |
— | — | @@ -248,7 +248,7 @@ |
249 | 249 | return 'BAD_TYPE'; |
250 | 250 | } |
251 | 251 | foreach ( $values as $value ) { |
252 | | - if ( strlen( $value ) !== 40 ) { |
| 252 | + if ( strlen( $value ) !== 31 ) { |
253 | 253 | return 'BAD_FORMAT'; |
254 | 254 | } |
255 | 255 | } |
Index: branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/DBLockManager.php |
— | — | @@ -358,7 +358,7 @@ |
359 | 359 | * Get the bucket for lock key. |
360 | 360 | * This should avoid throwing any exceptions. |
361 | 361 | * |
362 | | - * @param $key string (40 char hex key) |
| 362 | + * @param $key string (31 char hex key) |
363 | 363 | * @return integer |
364 | 364 | */ |
365 | 365 | protected function getBucketFromKey( $key ) { |
Index: branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | for ( $i = 0; $i < 5; $i++ ) { |
65 | 65 | $this->session .= mt_rand( 0, 2147483647 ); |
66 | 66 | } |
67 | | - $this->session = sha1( $this->session ); |
| 67 | + $this->session = wfBaseConvert( sha1( $this->session ), 16, 36, 31 ); |
68 | 68 | } |
69 | 69 | |
70 | 70 | protected function doLock( array $keys, $type ) { |
— | — | @@ -267,7 +267,7 @@ |
268 | 268 | /** |
269 | 269 | * Get the bucket for lock key |
270 | 270 | * |
271 | | - * @param $key string (40 char hex key) |
| 271 | + * @param $key string (31 char hex key) |
272 | 272 | * @return integer |
273 | 273 | */ |
274 | 274 | protected function getBucketFromKey( $key ) { |
Index: branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/LockManager.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | * @return Status |
49 | 49 | */ |
50 | 50 | final public function lock( array $paths, $type = self::LOCK_EX ) { |
51 | | - $keys = array_unique( array_map( 'sha1', $paths ) ); |
| 51 | + $keys = array_unique( array_map( 'LockManager::sha1Base36', $paths ) ); |
52 | 52 | return $this->doLock( $keys, $this->lockTypeMap[$type] ); |
53 | 53 | } |
54 | 54 | |
— | — | @@ -59,11 +59,21 @@ |
60 | 60 | * @return Status |
61 | 61 | */ |
62 | 62 | final public function unlock( array $paths, $type = self::LOCK_EX ) { |
63 | | - $keys = array_unique( array_map( 'sha1', $paths ) ); |
| 63 | + $keys = array_unique( array_map( 'LockManager::sha1Base36', $paths ) ); |
64 | 64 | return $this->doUnlock( $keys, $this->lockTypeMap[$type] ); |
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
| 68 | + * Get the base 36 SHA-1 of a string, padded to 31 digits |
| 69 | + * |
| 70 | + * @param $path string |
| 71 | + * @return string |
| 72 | + */ |
| 73 | + final protected static function sha1Base36( $path ) { |
| 74 | + return wfBaseConvert( sha1( $path ), 16, 36, 31 ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
68 | 78 | * Lock resources with the given keys and lock type |
69 | 79 | * |
70 | 80 | * @param $key Array List of keys to lock (40 char hex hashes) |