rdbms: make Database::query() more readable and consistent
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 14 Mar 2019 01:56:26 +0000 (18:56 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 14 Mar 2019 23:11:27 +0000 (23:11 +0000)
commit03908112635f9da82e4e1141cb4ed4838c56a84d
tree60b44e93aa110cf9b5632a664b24316122efdd13
parentfa0fe8d2940b71950f82f2303acd3a3717b51389
rdbms: make Database::query() more readable and consistent

Mainly:
* Stash trxLevel as the variable $priorTransaction since
  Database::replaceLostConnection might make it 0 when called.
* Factor out Database::beginIfImplied method and call it on
  each query attempt of query(), not just the first one.
* Do not bother setting STATUS_TRX_ERROR if a query fails due to
  connection issues and was recoverable since requiring ROLLBACK
  in order to continue has no real advantage.
* Do not bother setting trxDoneWrites/lastWriteTime for temporary
  table operations.
* Make Database::handleTransactionLoss() keep TransactionProfiler
  cleaner by calling Database::transactionWritingOut().

Also:
* Make sure Database::wasKnownStatementRollbackError() calls are
  right after the corresponding queries so it is easy to follow.
  Having connection attempts in between seems fragile.
* Rename Database::doProfiledQuery => Database::attemptQuery and
  move more logic to that method.
* Factor out Database::assertNeitherReplicaNorReadOnly method.
* Rename Database::assertOpen => Database::assertHasConnectionHandle.
* Fix wording of Database::wasKnownStatementRollbackError comments.
* Use $isEffectiveWrite variable name instead of $isNonTempWrite
  and $isWrite in some places.

Bug: T218226
Change-Id: I2063e4080b41d5fc504f9207a56312ce92130ed7
includes/libs/rdbms/database/Database.php
tests/phpunit/includes/db/DatabaseTestHelper.php