Commit graph

29 commits

Author SHA1 Message Date
Aaron Schulz
633eb437a3 rdbms: clean up return values of IDatabase write methods
Also improved the atomicity and affected row count logic for
insert/replace with sqlite.

Also remove unused "fileHandle" code from insert().

Change-Id: If7b9148fd44f3a958899885753c7c86ba66bf193
2018-10-30 03:34:52 +00:00
Aaron Schulz
fe0af6cad5 rdbms: Database::selectDB() update the domain and handle failure better
LoadBalancer uses Database::getDomainId() for deciding which keys to use
in the foreign connection handle arrays. This method should reflect any
changes made to the DB selection.

If the query fails, then do not change domain field. This is the sort of
approach that LoadBalancer is expects in openForeignConnection(). Also,
throw an exception when selectDB() fails.

The db/schema/prefix fields of Database no longer exist in favor of just
using the newer currentDomain field.

Also:
* Add IDatabase::selectDomain() method and made selectDB() wrap it.
* Extract the DB name from sqlite files if not explicitly provided.
* Fix inconsistent open() return values from Database subclasses.
* Make a relationSchemaQualifier() method to handle the concern of
  omitting schema names in queries. The means that getDomainId() can
  still return the right value, rather than confusingly omitt the schema.
* Make RevisionStore::checkDatabaseWikiId() account for the domain schema.
  Unlike d2a4d614fc, this does not incorrectly assume the storage is
  always for the current wiki domain. Also, LBFactorySingle sets the local
  domain so it is defined even in install.php.
* Make RevisionStoreDbTestBase actually set the LoadBalancer local domain.
* Make RevisionTest::testLoadFromTitle() account for the domain schema.

Bug: T193565
Change-Id: I6e51cd54c6da78830b38906b8c46789c79498ab5
2018-10-10 12:03:30 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Brad Jorsch
0618227f7f rdbms: Issue a deprecation warning if errors are ignored
I532bc5201 added code to put the Database into an error state on error,
to prevent callers from catching and ignoring exceptions without rolling
back. But to avoid breaking everything relying on the ability to do so,
it didn't set the error state for certain types of errors.

To allow those broken callers to be cleaned up, log a deprecation
warning when we detect that someone has indeed ignored one of these
errors.

Bug: T189999
Change-Id: Ib7aca59639f30959e106fd4f1a1209e28bad2857
2018-04-10 02:06:44 +00:00
Brad Jorsch
395462b7d5 rdbms: Roll back empty implicit transaction on error
If we're not going to set trxStatus to an error state in this case, we
need to issue a rollback to be sure the database (i.e. PostgreSQL) isn't
still in an error state too.

Bug: T189999
Change-Id: Id6e203b216fff937b6a97d779b36c278e3366409
2018-04-05 14:45:18 -04:00
Aaron Schulz
3975e04cf4 rdbms: make Database query error handling more strict
Handle all errors in query() that might have caused rollback by
putting the Database handle into an error state that can only be
resolved by cancelAtomic() or rollback(). Other queries will be
rejected until then.

This results in more immediate exceptions in some cases where
atomic section mismatch errors would have been thrown, such as a
an error bubbling up from a child atomic section. Most cases were
a try/catch block assumes that only the statement was rolled back
now result in an error and rollback.

Callers using try/catch to handle key conflicts should instead use
SELECT FOR UPDATE to find conflicts beforehand, or use IGNORE, or
the upsert()/replace() methods. The try/catch pattern is unsafe and
no longer allowed, except for some common errors known to just
rollback the statement. Even then, such statements can come from
child atomic sections, so committing would be unsafe. Luckily, in
such cases, there will be a mismatch detected on endAtomic() or a
dangling section detected in close(), resulting in rollback.

Remove caching from DatabaseMyslBase::getServerVariableSettings
in case some SET query changes the values.

Bug: T189999
Change-Id: I532bc5201681a915d0c8aa7a3b1c143b040b142e
2018-04-04 21:26:11 -07:00
addshore
f3df984c79 Introduce IDatabase::buildSubstring
Change-Id: I96f3e0c4920d52f63175cb6767c149f20a8a8cde
2018-03-07 12:32:50 +00:00
Aaron Schulz
ec550d4823 rdbms: remove "m" prefix from Database fields
Done using the PhpStorm refactor->rename tool.

Also move "defaultBigSelects" declaration to DatabaseMysqlBase
as no other classes uses that.

Change-Id: I424a2d9815de3a5d4cca2522f3db23a5efe6b592
2018-02-15 23:29:34 +00:00
Aaron Schulz
6237fd11b6 rdbms: make affectedRows() work more consistently
* Update replace()/upsert() to combine the affected row
  count for the non-native case
* Also make replace() atomic in the non-native case,
  similar to how upsert() already works

Change-Id: I6c9bcba54eca6bcf4a93a9b230aaedf7f36aa877
2018-01-30 20:02:07 -08:00
Umherirrender
f739a8f368 Improve some parameter docs
Add missing @return and @param to function docs and fixed some @param

Change-Id: I810727961057cfdcc274428b239af5975c57468d
2017-09-10 20:32:31 +02:00
Brad Jorsch
a0ad0569bd Add Database::unionConditionPermutations()
Constructs a query for the union of permutations of a set of fields, for
use in situations where the database otherwise makes poor plans due to
inability to use indexes effectively (e.g. T149077 and T168010).

Change-Id: I20980dcada664486c09198b8c45896620bd83e81
2017-06-16 19:39:05 +00:00
Aaron Schulz
38b31bc8db Move DatabaseDomain to Rdbms namespace
Change-Id: Ifb06e792a36b5123ec3596933d0d394711ee5d08
2017-02-07 13:21:40 -08:00
Aaron Schulz
59053a0716 Move ChronologyProtector/TransactionProfiler to Rdbms namespace
Change-Id: I37a655bd8bd267c9bc32028b55925b2dce527d33
2017-01-26 10:30:57 -08:00
Aaron Schulz
5bbac35ed1 Replace DatabaseBase:: with Database:: and update type hints
Change-Id: I3919b04eb2de4fa0bf8a02239fb5bbf17d347511
2016-09-27 04:20:03 +00:00
jenkins-bot
a0fe0eeb5a Merge "Set more fields in fake DB subclasses to avoid errors" 2016-09-21 20:17:28 +00:00
jenkins-bot
7c94ff498b Merge "Set the DatabaseDomain in some tests classes for sanity" 2016-09-21 20:13:28 +00:00
Aaron Schulz
d0e6d92fb0 Check Database::mSessionTempTables in Database::tableExists()
Also make the temp table tracking catch plain "DROP TABLE"
in addition to the stricter "DROP TEMPORARY TABLE" clause.

Bug: T146300
Change-Id: Ia8306ec25e63adcdcf0dcc8f6a700dd01afdc948
2016-09-21 19:02:09 +00:00
Aaron Schulz
dc7338be6f Set more fields in fake DB subclasses to avoid errors
Change-Id: I6b24422e830a8f82ba24383b3425808cb2a28b15
2016-09-21 11:56:28 -07:00
Aaron Schulz
69aa57ed91 Set the DatabaseDomain in some tests classes for sanity
Change-Id: I6531dc6cf89fbe7e5656354bcd4a27369f573752
2016-09-21 10:02:31 +00:00
Aaron Schulz
81e8d7af41 Avoid MWDebug usage in DatabaseBase
This class is in /libs and cannot depend on all of MediaWiki.
Replace the call with a simple debug() call instead.

Also, make the legacy logger route/format errors from the two
new DB log types (DBConnection, DBQuery) to the old wfLogDBError
locations, including MWDebug::debugMsg().

Change-Id: I64895d3f5b9a000d8186ab6a6ffb4b76a7e9ff40
2016-09-17 18:49:30 -07:00
Aaron Schulz
703b0691ca Use ESTIMATE_DB_APPLY for total transaction time estimate
Individual write queries already do this, but the COMMIT step
still used the old accounting.

Change-Id: I416a524d6652f933cbc49033b49745db732c8b92
2016-09-11 16:04:21 -07:00
Aaron Schulz
52d2ebb30a Make insertSelect() do two separate queries in non-CLI mode
This avoids slave lag and makes query time account easier.
It also avoids table-level autoinc locking and slave drift
with statement-based replication in some setups.

Also refactored the use of $wgCommandLine mode in
DatabaseBase slightly, so that it can be injected.

Change-Id: I2dba6024ecf32c9ee24a3080cce3b02568c1458b
2016-08-31 17:21:30 -07:00
Aaron Schulz
46b029e17c database: Clean up profiling code in DatabaseBase
This cuts down on conditionals and ScopedCallback use.

Change-Id: Ie478c613b062e45120cdd626f9fb9de09594c638
2016-08-29 22:13:03 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
withoutaname
b803906e08 Fix calls to DatabaseBase static functions
Previously they were calling Database:: which is a nonexistent class.

Change-Id: I73b2ed4722c9108b6a00c8c0cabbda9564378b4b
2014-08-17 03:23:18 +00:00
Aaron Schulz
ac8c53583c Avoid fatal error if doing a DB query after close()
Change-Id: I606a3ec5a45136abf396f86f5a65db209128d5c9
2014-04-30 17:04:06 -07:00
Aaron Schulz
be7b10166a Made DatabaseBase::getSoftwareLink() dynamic.
* All callers are calling it this way and it breaks
  hhvm when declared statically and called dynamically.

Change-Id: I894e615fd828615384aa8457a16a759c8aa416ef
2013-05-14 21:18:57 -07:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00
umherirrender
302f4b0ce1 Add non DBMS depending SQL tests for DatabaseBase
Created a DatabaseTestHelper class, which extends DatabaseBase and
implements STUBs for the interface methods and abstract methods

Change-Id: I9965b3604e78b2722077a35a7b4ce62a5bcb370e
2013-04-16 09:38:30 +02:00