Commit graph

588 commits

Author SHA1 Message Date
Aaron Schulz
f8d5075656 Upgrade mismatched begin() warnings to exceptions
No WMF logs for these events in the last 7 days.

Change-Id: I79f2f2c8117ffa887a550a793a9e490c2a26f721
2016-05-03 19:17:51 +00:00
Ryan Schmidt
eaa91d7abf Quote column name aliases
Sometimes, a column name alias is chosen that is a reserved word or is
otherwise invalid (such as an alias named "user" on postgres or mssql).
Let's unconditionally quote the alias so that no matter what the user
specifies, it will not cause the query to error out.

Bug: T118973
Change-Id: If3ea7324980355e78afcdb3bf2596d23bb96412d
2016-05-02 21:22:59 +00:00
Brian Wolff
8974d19995 Modify documentation of select() method for Database.
* Add a note in Database.php that docs are in IDatabase.php,
maybe its just me, but I didn't realize that was where the docs
are (even though in retrospect that should have been obvious) and
wasted a lot of time because I didn't realize that.
* Change references to IDatabase::tableName() in doc to
DatabaseBase::tableName(), since tableName is not in the IDatabase
interface.
* Be explicit in docs for select() about which parts are safe for
user input. I think its important to be very explicit about this.

No code changes, just doc changes.

Change-Id: I3a66477afc6a5f54855062482ef04c2966e468f6
2016-04-17 16:20:50 -04:00
Bartosz Dziewoński
c161c46d26 Improve code suffering from PHP 5.3's lack of support for foo()[]
I searched for /\$(\S+) = (.+?\(.*?\);)\n.*?\$\1\[/, ignored
everything involving isset(), unset() or array assigments, then
skimmed through the remaining results and changed things where they
made sense. These changes were not automated, so please review them.

Change-Id: Ib37b4c66fc57648470f151ad412210b3629c2538
2016-02-28 22:49:20 +01:00
Aaron Schulz
38f0c07279 Ignore noop DB transactions errors on connection loss
This avoids some needless exceptions for longer running scripts.

Bug: T127428
Change-Id: I3098141aa77a4c73cb2a0c784b38b15c712f82a9
2016-02-24 00:35:03 +00:00
jenkins-bot
d42754e477 Merge "database: Add extra sanity check to selectFieldValues()" 2016-02-18 14:46:29 +00:00
Aaron Schulz
ff23e83f41 database: Add extra sanity check to selectFieldValues()
Change-Id: Ia2788ea84bd099550655930188365984e5274678
2016-02-18 14:38:44 +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
Aaron Schulz
ef44f4308e Upgrade mismatched commit() warnings to exceptions
I saw no WMF logs for these in the last 7 days.

Change-Id: I725535925ba3fc68cee485767f18937fb8f239bf
2016-02-12 21:32:00 +00:00
Ricordisamoa
1e37987beb Follow-up to 02818c441c
* Remove obsolete @protected tag from docstring
  of DatabaseBase::indexName(), now really protected

* Make DatabaseSqlite::indexName() protected too

Change-Id: I90f894878379d0850dba61cd483af16864c209ea
2016-02-11 00:09:05 +01:00
Ricordisamoa
02818c441c Stop doing $that = $this in includes/db
Closures support $this as of PHP 5.4

Also made DatabaseBase::indexName() protected

Change-Id: Iff31e7d9186832a855a953b923ac182f1c66ffa0
2016-02-10 18:08:17 +01:00
jenkins-bot
c32764db69 Merge "Do not auto-reconnect to DBs if named locks where lost" 2016-01-30 18:07:35 +00:00
Aaron Schulz
79d12a284b Do not auto-reconnect to DBs if named locks where lost
Otherwise, transactions might be committed without cooperative
locks that were supposed to be present. This is similar to the
logic of not auto-reconnecting if a transaction was started to
avoid committing incomplete changes.

Change-Id: Ia7bc6b188bb5ee53a5bf7c5a30718bc7c4dd0ba9
2016-01-30 09:17:17 -08:00
Aaron Schulz
4e62537a8b Make sure getScopedLockAndFlush() commits before unlocking
This is necessary for callers to see changes from prior callers

Change-Id: I5e05215541e641b5b5a4bc55c91d6ec8ef774ca1
2016-01-30 08:52:06 -08:00
Aaron Schulz
60013aa328 Add IDatabase::getScopedLockAndFlush() method
This method is less manual and avoids the usual pitfalls of
not unlocking for a return statement or not flushing out any
prior transaction.

Change-Id: Ib1681244767de860105a68210e181e2f024ee525
2016-01-29 20:32:05 +00:00
Aaron Schulz
b527783de9 Log multi-DB write transactions
Bug: T122387
Change-Id: I03447f8c8465775a70c6a94f24ce196973703ce3
2016-01-15 16:02:02 -07:00
Aaron Schulz
0599bd94eb Remove pointless rollback() warnings with "flush"
This would previously make log noise when rollbackMasterChangesAndLog()
is triggered for explicit transactions.

Change-Id: Ia0009bcf575ef346d3bb7354ce3fb6fb477eb95f
2016-01-13 07:00:45 -08:00
Aaron Schulz
f86bd0a7eb Remove pointless rollback() warnings with "flush"
This would previously make log noise when rollbackMasterChangesAndLog() runs

Change-Id: I36dd955a89b23ed6d1ea693cf5366c7d3ad8d3af
2016-01-13 06:44:08 -08:00
jenkins-bot
afbbc86090 Merge "Dependency inject TransactionProfiler into DatabaseBase" 2016-01-12 20:05:36 +00:00
Aaron Schulz
7c8edbec73 Dependency inject TransactionProfiler into DatabaseBase
Change-Id: Ie5fc8120c3a3a5afe17897084d345f5fdb06843c
2016-01-06 14:58:31 -08:00
Aaron Schulz
75c09d9b31 Remove redundant DatabaseBase doc comments
Change-Id: I7f65d46dd05c6d9f72ec2e11ebba11f0b0854983
2016-01-05 23:56:27 +00:00
jenkins-bot
e53676d3dd Merge "Show user names as subpages of special pages in autocomplete search" 2015-12-30 00:16:20 +00:00
umherirrender
3e0f3cfd43 Show user names as subpages of special pages in autocomplete search
The autocomplete search allows special pages to define the list of
subpages to be excepted. Use user names on the following special pages,
because these special pages can be called with a user name as subpage.

Special:Block
Special:Contributions
Special:DeletedContributions
Special:Emailuser
Special:Listfiles
Special:Unblock
Special:Userrights

This makes it easier to navigate to this special pages with a prefilled
user name field.

Hidden user names are always not shown, because the suggestion is cached
between priviliged user and non-priviliged user.

Change-Id: I7db575bf66caaa5136489ed99f1655673b55adaf
2015-12-29 11:49:58 +01:00
Aaron Schulz
3ab0c7d4d7 Added IDatabase::doAtomicSection() convenience method
This can replace startAtomic/endAtomic pairs.

Bug: T122115
Change-Id: I01c8e4773ec2b42dbe87a5508a10b997be103c11
2015-12-28 23:11:56 +00:00
Aaron Schulz
9c0b55d926 Make getLagFromPtHeartbeat() always use the LB cluster master entry
Before, it just used the immediate master entry, which could be another
slave. In that case, it may not even exists at all.

Bug: T119648
Change-Id: Iea970b81ad2c9855aafcccf0bb0662fc0b3a8d4d
2015-12-09 22:00:19 -08:00
Aaron Schulz
aed92ddf2a Fix edge case in onTransactionIdle()
If a callback set DBO_TRX, make sure it gets unset if that
is not what the DB was set to before the callbacks ran.

Change-Id: I79b649de02e821494d7f88e8979764ec8a9d0c43
2015-12-07 17:26:15 -08:00
Aaron Schulz
cb8842dbab Make getCacheSetOptions() and WAN cache handle broken replication
TTL_LAGGED now triggers if the slave or I/O threads stopped

Change-Id: I5e7bf2d33b8d3a60182ec53a93d65f7e55f02222
2015-12-02 15:38:23 -08:00
Aaron Schulz
36f025f8c9 Improve docs for lag related DB functions
* They can return false if replication is stopped.
* Also remove redundant related doc blocks.

Change-Id: I40a1cb2da2f23815b9da8f79195df45c5e510585
2015-11-18 18:23:08 -08:00
jenkins-bot
e1ebc2de02 Merge "Followup a88df43d: make $wgDebugDumpSql log commented queries again" 2015-11-12 02:46:03 +00:00
Roan Kattouw
0e2b5706ad Followup a88df43d: make $wgDebugDumpSql log commented queries again
Change-Id: I0c10b2119f03fa047dbb2bad1c4c1233403bff59
2015-11-11 18:17:23 -08:00
jenkins-bot
78b6bde01f Merge "Make runOnTransactionIdleCallbacks() handle dangling transactions" 2015-11-10 23:49:30 +00:00
Aaron Schulz
33a3e097cb Improve mismatched atomic section errors
Change-Id: I9b1561b6426ac00f72867452bee396b649ad8bfd
2015-11-05 16:35:22 -08:00
Aaron Schulz
2cbb042dea Make runOnTransactionIdleCallbacks() handle dangling transactions
This avoids "Got COMMIT while atomic sections X are still open"
if the this DB had active transactions when an error occurred.

Change-Id: I1e2eb3a3382537108ecb269c483d2e62a218b656
2015-11-03 13:12:14 -08:00
Aaron Schulz
17c91ad610 Replace newAccelerator() with getLocalServerInstance()
The name is clearer and more consistent, with simpler arguments.

Change-Id: I7205a99ce033e8b086a52cd02c8a721e99c84b1e
2015-11-02 21:39:08 +00:00
jenkins-bot
30135f1dec Merge "Protect WAN cache sets() against uncommitted data" 2015-10-27 10:18:52 +00:00
Kevin Israel
75168d6ae6 Database::__construct(): Don't set $mTrxAtomicLevels to an SplStack
Follows-up db0b9ef264 and 01ef30fcc4.

Change-Id: I06188c746fb885819aa93e0e3caf3dc2bac7ae72
2015-10-25 19:02:15 -04:00
Aaron Schulz
dc646b464c Protect WAN cache sets() against uncommitted data
This generally only effects wikis with no slave DBs,
but also matters if the master has non-zero LB load.
If the master ends up being used for DB_SLAVE, care
should be shown for cache-aside writes

Interesting WAN cache events are now logged.

Change-Id: I2cd8e84138263c13ea23beb9ab3d7562340e1fd3
2015-10-24 17:21:22 -07:00
Aaron Schulz
7662212384 Add IDatabase::isReadOnly() method
Also made getReadOnlyReason() protected as it has no outside
callers and is not part of IDatabase.

Change-Id: If6694a19df038af645a97f701397a536570d1b42
2015-10-20 16:48:18 -07:00
Aaron Schulz
52010e6d21 Make DB handles inherit configured read-only mode
LBFactory inherits $wgReadOnly, the LBs inherit
any LBFactory read only mode, and Database objects
inherit any LB read-only mode.

Add some methods callers can use to check if
a DB/LB handle is read-only before trying writes.

Additionally:
* Fix 5ec1e47475 regression where readOnlyBySection
  read-only mode would not affect wfReadOnly() but only
  lagged-slave read-only mode for LBFactoryMulti.
* Catch errors when getLaggedSlaveMode() is called after
  master connection and object is established.
* Make getLaggedSlaveMode() a no-op if there are no slaves.
* Make string/false logic for read-only consistent everywhere.
* Remove mLaggedSlaveMode "m" prefix.

Change-Id: Ice3224caae564aa5ffb41b424c23d1593229117a
2015-10-20 23:27:14 +00:00
Ori Livneh
563a7f1114 Database::selectRowCount(): support $join_conds
Add a $join_conds parameter for Database::selectRowCount(), to allow the caller
to specify join conditions for the subquery that it generates.

Change-Id: I8c0a93713c121bc5b691ae65d6b6d8f8c08c9e4c
2015-10-19 22:07:34 -07:00
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