Commit graph

532 commits

Author SHA1 Message Date
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
Aaron Schulz
7df76bae3b Made TransactionProfiler log regardless of Profiler
* Also avoid the use of slow closures for profiling

Change-Id: Id437e39038fd9ba80b899329a61e9f14229481f2
2015-02-20 02:11:11 +00:00
Aaron Schulz
fc22415ba9 Pass the right variable to recordQueryCompletion()
Change-Id: I0d75ed7dd55e40b63bd823ec43b8d3a8f5bed53b
2015-02-15 09:31:00 +00:00
Tim Starling
88982d4ccf Fix spammy "Writes done" debug message
Was broken by I1a8830eaf, which accidentally caused the log message to
be output for every write query, instead of only the first write query.

Change-Id: I4a53914bcb28804ff4c31b4e0418591793d411b6
2015-02-13 15:59:37 +11:00
jenkins-bot
c3d802cc30 Merge "Added query/connection expectation support to TransactionProfiler" 2015-02-12 21:38:58 +00:00
Aaron Schulz
505394a5a9 Added query/connection expectation support to TransactionProfiler
* Master connections and writes on read requests will now be logged to
  get visibility into code that reduces performance and site availability.

bug: T88445
bug: T86862
Change-Id: Ic2ae95c33facbb54e062aef2ce67d6182caa044a
2015-02-11 18:57:03 +00:00
jenkins-bot
23650785ef Merge "Moved RecentChange::purgeExpiredChanges to a job" 2015-02-10 21:32:55 +00:00
Kevin Israel
5f3957498b Database: Cast to int in estimateRowCount(), selectRowCount()
Doc comments state that these methods return ints. In order to ensure
that, values must be cast to int before they are returned.

With respect to selectRowCount(), follows-up 65f81d2843.

Change-Id: I108221ce4ad1b5b103b015fe875de54e04781741
2015-02-06 05:03:45 -05:00
Aaron Schulz
52a5954068 Moved "large write query" code to TransactionProfiler
Change-Id: Ic05e832eb21545a4e639b52aca7b3a5811a890ce
2015-02-05 01:42:25 +00:00
Erik Bernhardson
7fd481c770 Always decode Blob objects from Database::addQuotes
The current API for Database::encodeBlob/Database::addQuotes requires
the code that is outputting binary data to have a database handle, so
that it may call Database::encodeBlob to get either a plain string or
a Blob object back. All database implementations other than MySQL
return a Blob object from Database::encodeBlob.

This is a rather inconvenient API, it tightly couples the creation of
binary data with the Database object unnecessarily.  If all database
objects accept a Blob via Database::addQuotes then code can simply
wrap its arguments in Blob and know that any database it ends up at
will be properly handled.

This patch changes the default implementation of Database::addQuotes
to recognize a Blob object was passed in, and use Blob::fetch to turn
it back into a string.  Database implementations other than MySQL all
handle this Blob object already.  The postgresql implementation had
to be adjusted slightly. Now when it sees a Blob object that it did
not create it will encode that appropriately.

Bug: 72367
Change-Id: I12fb4bd339be19137fffba2e47a70741382f6a8c
2015-02-02 17:43:12 +00:00
Aaron Schulz
99e6b43ab8 Moved RecentChange::purgeExpiredChanges to a job
* Also added a selectFieldValues helper method to the DB classes
  since this use case keeps coming up.

Change-Id: I62cdbb497dc2c8fe4758e756d13688b85165e869
2015-01-16 17:39:31 -08:00
Aaron Schulz
6921770414 Updated some try-catch statements: MWException -> Exception
Change-Id: I76601a86e30f4984e3b1a8c8ec5ef5a0f652433a
2015-01-09 17:20:22 -08:00
Sumit Asthana
26235c7337 Database::makeList() : Handle NULL when building 'IN' clause
Amends to Database::makeList() to check if 'NULL' is present in array while
building IN clause. Presently a NULL in array intended to build IN clause, is
treated as a usual value. This creates
problem:https://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in
Therefore null is appended at the end of the IN clause as " $field IS NULL"
rather than within the IN clause.
DatabaseSQLTest.php: Some test cases added for the modified behaviour.

Bug: T50853
Change-Id: Ic255c37e9702fd44d8173027ab8036ddc48f9d2e
2015-01-03 22:20:35 +05:30
Aaron Schulz
61e23c0578 Cleanup DatabaseBase::query implicit transaction code
* Add DatabaseBase::isTransactableQuery() for checking whether a query could
  benefit from being executed in a transaction.

Change-Id: Ie5b116bc726b47c68459e6525a1bb43b96bd9f30
2014-12-25 22:43:57 +00:00
Reedy
4d9143c7f5 Add lots of @throws
Change-Id: I09d0c13070f966fcf23d2638d8fc1328279a5995
2014-12-24 13:49:20 +00:00
Aaron Schulz
8029513503 Use generalizeSQL for DBPerformance log entries
Change-Id: I6612e01ba6382bcdc1642848009f6b8e13bd79f2
2014-12-18 15:00:57 -08:00
Aaron Schulz
9c246d1019 Log to DBPerformance when queries affect many rows
Change-Id: If82b596187b638888760f800bba2fea20fc7ae8a
2014-12-12 19:35:57 +00:00