Commit graph

548 commits

Author SHA1 Message Date
Aaron Schulz
d01d35184d Made Database atomic section errors mention the sections
Change-Id: Ia6243dd655ef09f3bfbc66ac6d0757ec7bb4bd10
2015-10-07 12:31:04 -07:00
jenkins-bot
12ce3c8e8d Merge "Enforce lagged-slave read-only mode on the DB layer" 2015-10-07 01:40:34 +00:00
Aaron Schulz
2db0dd9ccd Added @since to Database
Change-Id: Ia4396317bb3c78ab6b60ecbf0e1825e44ed08589
2015-10-05 22:41:05 -07:00
jenkins-bot
4f7d15021d Merge "Make WANObjectCache sets account for slave lag" 2015-10-06 00:11:22 +00:00
jenkins-bot
c5ac11e2eb Merge "Start rename of DatabaseBase => Database" 2015-10-05 23:45:36 +00:00
Aaron Schulz
db0b9ef264 Make WANObjectCache sets account for slave lag
* This gets lag information that is useful when
  the calling code is about to run queries that
  will have their results cached.
* This is now used in place of trxTimestamp() for
  WANObjectCache set() and getWithSetCallback().
* The WAN cache will use a low TTL if the lag is
  too high to avoid caching stale data for weeks.
* Bumped MAX_COMMIT_DELAY as nothing enforces it.

Bug: T113204
Change-Id: I2a95b4088cff42d6e980351555f81a4b13519e24
2015-10-05 16:45:13 -07:00
jenkins-bot
b8ec980120 Merge "Database debug log cleanup (remove wgDebugDumpSqlLength/wgDebugDBTransactions)" 2015-10-05 19:57:45 +00:00
jenkins-bot
87531f2b37 Merge "Make generalizeSQL() protected" 2015-10-05 19:53:03 +00:00
Aaron Schulz
a88df43d3f Database debug log cleanup (remove wgDebugDumpSqlLength/wgDebugDBTransactions)
* Simplify the debug log call and use queries group
* Remove $wgDebugDumpSqlLength, as profiler output
  already has shortened query strings (one can use
  profiling without DBO_DEBUG)
* Removed $wgDebugDBTransactions as BEGIN/COMMIT already show
* Removed PostgresTransactionState as it was only used for
  $wgDebugDBTransactions handling
* This cuts down on lots of global variable usage

Change-Id: I185adb1694441d074dea965960429b4910727620
2015-10-05 12:47:09 -07:00
Aaron Schulz
db170ebe78 Enforce lagged-slave read-only mode on the DB layer
* Most callers gracefully check wfReadOnly(),
  but fail in case they dont. This also catches
  foreign DBs which might slip through the cracks.
* Also remove useless wfDebug() call around
  mDoneWrites check as write queries show in
  the logs anyway.

Change-Id: I560ebd19c4eb2b3a040d4331702346440617cfaa
2015-10-05 05:41:19 +00:00
Aaron Schulz
1b67a929ab Start rename of DatabaseBase => Database
This gives static method callers the option
to use methods like Database::factory() instead
of having to use the uglier DatabaseBase::factory().

Change-Id: I61800626b71ad2803a897df060059dbaf8778679
2015-10-04 12:36:56 -07:00
Aaron Schulz
f169cc63af Make generalizeSQL() protected
Change-Id: Ib1317576b82993adf5ae454f9ecd8bd148a58cc9
2015-10-04 02:48:55 -07:00
Aaron Schulz
01ef30fcc4 Converted DatabaseBase::mTrxAtomicLevels to an array
* This simplifies the code and cleans up __construct()
  a bit while also making it less likely to cause
  trouble with unit testing mocks.
* Also add a sanity mTrxLevel check around usage
  of mTrxAtomicLevels in the one place it was missing

Change-Id: Ia0a7f22f5c27b3d4d8b51e04629f42a1ed9c3993
2015-10-04 01:25:11 +00:00
Aaron Schulz
48906dde12 Fixed remaning IDEA errors in DatabaseBase
Change-Id: Ife8d7ecd4f224f1e2ef6f729765c303ec69a3f5f
2015-09-30 19:42:26 -07:00
Aaron Schulz
c3740286ac Removed old fake slave hacks used for debug log testing
* Any modern automatic tests would use mocking methods

Change-Id: I5fbd8ebe7090f75bdcccc7a2848ae88f34a64512
2015-09-29 00:44:48 -07:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Kevin Israel
617d59fcb3 Database: Remove resultObject() from the public interface
It has not been necessary to call this method outside the Database classes
since 1.11 (r23756 / 9382bc7a85).

This is a breaking change and should not be merged before the following
changes to extensions:

* Disambiguator: Ibef942fd
* Maps: Ic90bd0ad
* OAI: Idbbe08d6
* Oversight: I63071e65
* Video: Id71914cd

Change-Id: Idfe7cd6f516f0aca850878282c47e7914accc6d8
2015-09-26 11:13:23 -07:00
Kevin Israel
a0f6af5521 DatabaseBase::deadlockLoop(): Remove unused variables
Follows-up 419221e4a7.

Change-Id: Ia0d50e40600ca2cd7b90441b66340d3c290be85f
2015-09-19 02:07:13 -04:00
Kevin Israel
5a4c5985ae Database: Remove unused errorCount() method
Also removed the protected $mErrorCount property used by this method.

Also removed DatabaseOracle::reportQueryError(). After removing its use
of $mErrorCount and applying relevant changes from 419221e4a7 ("Fixed
bug where catching DB errors left ignoreErrors() on"), the only effect
would be that, like for the other DB types, query errors would be
logged using wfLogDBError().

Change-Id: Ie26a5f5ef7dc5619d9db38d3eb6b7af3e6592aff
2015-09-18 04:35:13 -04:00
addshore
2c3773be2a Add @throws tag to Database::insert
This was already documented but not with @throws

Change-Id: Ib55c2efb9993c5d939fab1ed5d6ade3fc277902f
2015-08-27 09:55:53 +02:00
jenkins-bot
abb724688c Merge "Avoid update.php suggestion on DB connection errors" 2015-08-10 18:31:02 +00:00
Aaron Schulz
51be75ba00 Avoid update.php suggestion on DB connection errors
Bug: T98788
Change-Id: I21974d6b775f13c33055f76c30142e937eb0e965
2015-08-07 00:31:46 -07:00
Aaron Schulz
e7a7fb4238 Fixed deadlockLoop() IDE errors
Change-Id: I76bb9250bc8017756af4f2552cd48ab595a26297
2015-08-06 12:45:30 -07:00
Aaron Schulz
c2e45cdde1 Made DB ignoreErrors() method protected
* This should *only* ever be used internal for error suppression,
  such as in the exception reporting methods. Having it public
  means callers have to worry (in theory) about whether the
  DB handles errors one way or a totally different way even
  though there is really only meant to be one.

Change-Id: I5916830d1bd53ee948308f394e55c17dd515ad33
2015-07-21 14:18:04 -07:00
Aaron Schulz
4de0ff162d Removed redundant signatures from DatabaseBase
Change-Id: I35816c752cd1b782796989a2d5ac4fe5eff78e55
2015-07-19 13:50:32 -07:00
Aaron Schulz
d807a9dc4a Added FIXME to default Database replace() implementation
Change-Id: I3ec0ec066248ee733b41f9c70d40382d96898613
2015-07-17 15:22:54 -07:00
umherirrender
d2d679dde7 Pass function name in Database::selectRowCount
This allow to see the correct function name in the debug logs

Change-Id: I84c94edce60efb8f15a7eb178065ee03e85fc282
2015-07-10 22:44:03 +02:00
Aaron Schulz
6e283d394f Formally defined IDatabase and made a few Database methods protected
* IDEs can now make sense of IDatabase, which is useful for
  lazy connections. The interface might also help lower coupling.
* This also updates DBConnRef, which implements IDatabase
* Some discouraged methods are left out of IDatabase.
  These methods either encourage manual query building,
  are only needed by the updater, are obscure/unused,
  or either wise encourage bad practice. DBConnRef still
  supports these if called to avoid breakage though.

Change-Id: Ia83530820f185415725c1d5f54b5172121b4938f
2015-07-02 12:26:30 -07:00
jenkins-bot
0bcd8347e5 Merge "database: Small DB class cleanups" 2015-06-28 00:26:07 +00:00
Aaron Schulz
359b1b7cbe database: Small DB class cleanups
* Moved some duplicated logic to assertOpen() method
* Override doc type for mConn for the mysqli subclass
* Fixed a few code comments

Change-Id: I78d595554ed51f64ca7cf7bd7ce369a492a59145
2015-06-28 00:15:54 +00:00
addshore
c5a65358ca Add more return types to Database class
We expect these to be implemented and where
implemented we expect them to return these types.

This means when typehinting against Database
(Which is done throughout the code as we dont know
what DB we will eb using) warnings about void return
types will no longer be shown by static analysis stuff

Change-Id: I03d85560d9eb92d6df11dba8bc90339bf41cee8c
2015-06-26 16:47:58 +02:00
Timo Tijhof
bb61a0486e database: Don't treat $defaultSchemas as containing all types/drivers
The Database::factory() method treats $dbType as of one of
predefined "canonicalDBTypes", and defaults to using it as driver.
Which is then used for the name of the Database subclass.

This allows extensions and wiki farms to have custom subclasses
to override certain methods, or even provide new drivers.

The $defaultSchemas array added in f7174057a4 was given all canonical
keys (with null values) to allow unconditionally access. This
doesn't scale very well and is error-prone. Reduce it to the
override only and fallback make the fallback to null explicitly.

See T102285 for where this would help prevent a PHP Notice.

Change-Id: I3f1e1f59c300d34de30f6480ff4e54f159d51b16
2015-06-15 18:16:32 +01:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Aaron Schulz
7936b94341 Log transaction that spend too much time in write queries
Change-Id: I9ba184601cfb1667291f7a29677cc5205344d5ad
2015-05-07 17:13:20 -07:00
Aaron Schulz
a129edcc5e Made DatabaseSqlite::__construct always caller super
* Also fixed misuse of private mTrxAtomicLevels var

Change-Id: I711508cb3906a5192be1a244a7e511b1720141ca
2015-04-28 08:37:21 -07:00
jenkins-bot
661f171575 Merge "Added $wgJobSerialCommitThreshold setting" 2015-04-27 08:29:46 +00:00
Aaron Schulz
7c821caef5 Added $wgJobSerialCommitThreshold setting
* This is used to avoid lag by certain jobs

Bug: T95501
Change-Id: Id707c9a840fa23d56407e03aaae4e25149a1f906
2015-04-24 11:38:16 -07:00
Aaron Schulz
fe72859716 Allow setting MySQL session variables via config
Change-Id: I39c7e0f5ffe53a3fb15da489f4dddc36af99a4b3
2015-04-24 11:07:02 -07:00
Aaron Schulz
4dd8b5cf45 Added a simple pendingWriteQueryDuration() DB method
Change-Id: I924cf78d8bb96d526a7ba7444f0532d7eb223bf2
2015-04-23 03:13:40 +00:00
jenkins-bot
dd7df34a22 Merge "Clean up handling of 'infinity'" 2015-04-14 18:57:16 +00:00
Aaron Schulz
b6ef721900 Reduce begin/commit activity in startAtomic with DBO_TRX
Change-Id: I6c1334967aeff54fb18091c23749fcb0b49624b9
2015-04-09 15:49:15 -07:00
Aaron Schulz
419221e4a7 Fixed bug where catching DB errors left ignoreErrors() on
* Also fixed an actual rollback loop possible in postgres

Change-Id: I41508127f74e1bbee4c020546fed85ab53318ab7
2015-04-07 18:12:06 +00:00
Aaron Schulz
4d58457784 Added slave/master fallback logic in Revision
* This is a more specific form of the logic removed in 3c2bc32ae1.
  It does not suffer the problem of causing constant master DB
  queries due to a bad template reference or such.
* It will use the master if writes from the current thread
  are pending or were recently committed. This deals with the
  common problem of code that needs to read things it just wrote,
  such as diffs on rollback or edit hooks.
* This commit reverts 8624e261f by making the hack obsolete.

Bug: T93866
Bug: T94407
Change-Id: Ib9ecb75e1236e767bdc86d124d5e22a03ae0fb5f
2015-03-31 23:39:28 +00:00
Brad Jorsch
ac6f81d9ad Clean up handling of 'infinity'
There's a bunch of stuff that probably only works because the database
representation of infinity is actually 'infinity' on all databases
besides Oracle, and Oracle in general isn't maintained.

Generally, we should probably use 'infinity' everywhere except where
directly dealing with the database.

* Many extension callers of Language::formatExpiry() with $format !==
  true are assuming it'll return 'infinity', none are checking for
  $db->getInfinity().
* And Language::formatExpiry() would choke if passed 'infinity', despite
  callers doing this.
* And Language::formatExpiry() could be more useful for the API if we
  can override the string returned for infinity.
* As for core, Title is using Language::formatExpiry() with TS_MW which
  is going to be changing anyway. Extension callers mostly don't exist.
* Block already normalizes its mExpiry field (and ->getExpiry()),
  but some stuff is comparing it with $db->getInfinity() anyway. A few
  external users set mExpiry to $db->getInfinity(), but this is mostly
  because SpecialBlock::parseExpiryInput() returns $db->getInfinity()
  while most callers (including all extensions) are assuming 'infinity'.
* And for that matter, Block should use $db->decodeExpiry() instead of
  manually doing it, once we make that safe to call with 'infinity' for
  all the extensions passing $db->getInfinity() to Block's contructor.
* WikiPage::doUpdateRestrictions() and some of its callers are using
  $db->getInfinity(), when all the inserts using that value are using
  $db->encodeExpiry() which will convert 'infinity'.

This also cleans up a slave-lag issue I noticed in ApiBlock while
testing.

Bug: T92550
Change-Id: I5eb68c1fb6029da8289276ecf7c81330575029ef
2015-03-13 11:19:53 -04:00
Aaron Schulz
c39a4530b0 Made master connection expectations actually work
Bug: –T86862
Change-Id: If918904c6c02ea83473dfaf34dfc2787ab610c6f
2015-03-03 13:18:18 -08:00
Aaron Schulz
61df5e785f Made SqlBagOStuff avoid tripping TransactionProfiler
* Set a custom profiler with no expectations to avoid tripping
  the "0 write" expection. This avoids useless log entries.

Change-Id: Iac849a729eb36b1a8affb0dbc8b8c195fab4b03a
2015-02-27 17:45:48 +00:00
jenkins-bot
bd5fd843d6 Merge "Always decode Blob objects from Database::addQuotes" 2015-02-25 21:17:06 +00:00
jenkins-bot
19d6957824 Merge "DatabaseBase constructor cleanups" 2015-02-23 21:18:23 +00:00
Aaron Schulz
2cfcb390c6 DatabaseBase constructor cleanups
* The array based format is now required
* Pass any additional parameters through factory() to __construct() even
  if the base clase does not recognize them. This makes DB specific
  options simpler.
* Also added missing bits to Sqlite constructors

Bug: T90288
Change-Id: I29b79a3c1bb2b5e51c1c8f5e04cd08c71e0662a3
2015-02-23 13:02:28 -08:00
Kevin Israel
3c16633c4f DatabaseBase: Document behavior of nulls in array conditions
Follows-up 26235c7337.

Change-Id: Id008557e53a8c27f49e87cb2120298ce6478b6df
2015-02-21 23:47:43 -05:00