r108564 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108563‎ | r108564 | r108565 >
Date:23:42, 10 January 2012
Author:raindrift
Status:reverted (Comments)
Tags:
Comment:
Updated to use correct cross-db timestamps and date functions
Added to SQLite updater
Modified paths:
  • /trunk/phase3/includes/ConcurrencyCheck.php (modified) (history)
  • /trunk/phase3/includes/installer/SqliteUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/sqlite/archives/patch-concurrencycheck.sql (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/sqlite/archives/patch-concurrencycheck.sql
@@ -0,0 +1,25 @@
 2+--
 3+-- Store atomic locking information for web resources, to permit
 4+-- UI that warns users when concurrently editing things that aren't
 5+-- concurrently editable.
 6+--
 7+CREATE TABLE /*_*/concurrencycheck (
 8+ -- a string describing the resource or application being checked out.
 9+ cc_resource_type varchar(255) NOT NULL,
 10+
 11+ -- the (numeric) ID of the record that's being checked out.
 12+ cc_record int unsigned NOT NULL,
 13+
 14+ -- the user who has control of the resource
 15+ cc_user int unsigned NOT NULL,
 16+
 17+ -- the date/time on which this record expires
 18+ cc_expiration varbinary(14) not null
 19+
 20+) /*$wgDBTableOptions*/;
 21+-- composite pk.
 22+CREATE UNIQUE INDEX /*i*/cc_resource_record ON /*_*/concurrencycheck (cc_resource_type, cc_record);
 23+-- sometimes there's a delete based on userid.
 24+CREATE INDEX /*i*/cc_user ON /*_*/concurrencycheck (cc_user);
 25+-- sometimes there's a delete based on expiration
 26+CREATE INDEX /*i*/cc_expiration ON /*_*/concurrencycheck (cc_expiration);
Property changes on: trunk/phase3/maintenance/sqlite/archives/patch-concurrencycheck.sql
___________________________________________________________________
Added: svn:eol-style
127 + native
Index: trunk/phase3/includes/installer/SqliteUpdater.php
@@ -71,6 +71,7 @@
7272 array( 'modifyField', 'user', 'ug_group', 'patch-ug_group-length-increase.sql' ),
7373 array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-uploadstash_chunk.sql' ),
7474 array( 'addfield', 'job', 'job_timestamp', 'patch-jobs-add-timestamp.sql' ),
 75+ array( 'addTable', 'concurrencycheck', 'patch-concurrencycheck.sql'),
7576 );
7677 }
7778
Index: trunk/phase3/includes/ConcurrencyCheck.php
@@ -80,7 +80,7 @@
8181 'cc_resource_type' => $this->resourceType,
8282 'cc_record' => $record,
8383 'cc_user' => $userId,
84 - 'cc_expiration' => time() + $this->expirationTime,
 84+ 'cc_expiration' => wfTimestamp( TS_MW, time() + $this->expirationTime ),
8585 ),
8686 __METHOD__,
8787 array( 'IGNORE' )
@@ -108,11 +108,11 @@
109109 );
110110
111111 // not checked out by current user, checkout is unexpired, override is unset
112 - if( ! ( $override || $row->cc_user == $userId || $row->cc_expiration <= time() ) ) {
 112+ if( ! ( $override || $row->cc_user == $userId || wfTimestamp( TS_UNIX, $row->cc_expiration ) <= time() ) ) {
113113 // this was a cache miss. populate the cache with data from the db.
114114 // cache is set to expire at the same time as the checkout, since it'll become invalid then anyway.
115115 // inside this transaction, a row-level lock is established which ensures cache concurrency
116 - $memc->set( $cacheKey, array( 'userId' => $row->cc_user, 'expiration' => $row->cc_expiration ), $row->cc_expiration - time() );
 116+ $memc->set( $cacheKey, array( 'userId' => $row->cc_user, 'expiration' => $row->cc_expiration ), wfTimestamp( TS_UNIX, $row->cc_expiration ) - time() );
117117 $dbw->rollback();
118118 return false;
119119 }
@@ -127,7 +127,7 @@
128128 'cc_resource_type' => $this->resourceType,
129129 'cc_record' => $record,
130130 'cc_user' => $userId,
131 - 'cc_expiration' => $expiration,
 131+ 'cc_expiration' => wfTimestamp( TS_MW, $expiration ),
132132 ),
133133 __METHOD__
134134 );
@@ -187,7 +187,7 @@
188188 'concurrencycheck',
189189 array( '*' ),
190190 array(
191 - 'cc_expiration <= ' . $now,
 191+ 'cc_expiration <= ' . $dbw->addQuotes( wfTimestamp( TS_MW, $now ) ),
192192 ),
193193 __METHOD__,
194194 array()
@@ -203,7 +203,7 @@
204204 $dbw->delete(
205205 'concurrencycheck',
206206 array(
207 - 'cc_expiration <= ' . $now,
 207+ 'cc_expiration <= ' . $dbw->addQuotes( wfTimestamp( TS_MW, $now ) ),
208208 ),
209209 __METHOD__,
210210 array()
@@ -238,7 +238,7 @@
239239 'cc_resource_type' => $this->resourceType,
240240 'cc_record' => $key,
241241 'cc_user' => $cached['userId'],
242 - 'cc_expiration' => $cached['expiration'],
 242+ 'cc_expiration' => wfTimestamp( TS_MW, $cached['expiration'] ),
243243 'cache' => 'cached',
244244 );
245245 } else {
@@ -259,7 +259,7 @@
260260 array(
261261 'cc_resource_type' => $this->resourceType,
262262 'cc_record IN (' . implode( ',', $toSelect ) . ')',
263 - 'cc_expiration > unix_timestamp(now())'
 263+ 'cc_expiration > ' . $dbw->addQuotes( wfTimestamp( TS_MW ) ),
264264 ),
265265 __METHOD__,
266266 array()

Follow-up revisions

RevisionCommit summaryAuthorDate
r108601reverts Concurrency works...hashar09:05, 11 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108559MERGE branches/concurrency 108301:108557 into trunkraindrift23:03, 10 January 2012

Comments

#Comment by Reedy (talk | contribs)   01:27, 11 January 2012

http://integration.mediawiki.org/ci/job/MediaWiki-phpunit/5482/console

     [exec] 1) ConcurrencyCheckTest::testStatus
     [exec] DBQueryError: A database error has occurred.  Did you forget to run maintenance/update.php after upgrading?  See: [https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script]
     [exec] Query: SELECT  *  FROM unittest_concurrencycheck  WHERE cc_resource_type = 'CCUnitTest' AND cc_record IN ('1337','1338','1339','13310')  AND (cc_expiration > '20120111012528')   LOCK IN SHARE MODE
     [exec] Function: ConcurrencyCheck::status
     [exec] Error: 1 near "LOCK": syntax error

Guessing SQLite doesn't use the same locking stuff as MySQL...

Status & tagging log