Rename canRecoverFromDisconnect() in order to better describe
its function. Make it use the transaction ID and query walltime
as arguments and return an ERR_* class constant instead of a bool.
Avoid retries of slow queries that yield lost connection errors.
Track session state errors caused by the loss of named locks or
temp tables (e.g. during connection loss). Such errors will prevent
further queries except for rollback() and flushSession(), which must
be issued to resolve the error.
Add flushPrimarySessions() methods to LBFactory/LoadBalancer
and use it in places where session state loss is meant to be
safely aknowledged.
Change-Id: I60532f86e629c83b357d4832d1963eca17752944
Using cancelAtomic() is no longer considered a valid way to recover
from a connection loss involving lost writes or lost named locks unless
the entire transaction was started by the relevant atomic section.
DBTransactionError will be thrown for such misuse and rollback() is
required instead.
This will allow for assertQueryIsCurrentlyAllowed() to treat
ROLLBACK queries differently from ROLLBACK TO SAVEPOINT queries.
For some scenarios, like session-level named lock loss, only full
transaction ROLLBACK queries should be allowed.
Change-Id: Ibbcdc79418da052480faecbc027baad2a88157d0
Add TransactionIdentifier class, similar to AtomicSectionIdentifier,
that represents applications-side tokens for transactions. Move the
string ID logic there.
The transaction tokens can be used to determine whether rollback()
alone is sufficient to recover from a connection loss. This will
be done in a follow up patch.
Change-Id: I9c68b0c5a23800001fca49cabd6cc38fce4d5c00
Move the error state setting logic in executeQueryAttempt() up
in order to reduce code duplication.
Move the beginIfImplied() call in executeQueryAttempt() up to the
retry loop in executeQuery(). This narrows the executeQueryAttempt()
concerns to sending a single query and updating tracking fields.
Change-Id: Icdc82108850ea0cd68f259ba20edf239e390a948
Pass the error number as an argument, similar to isConnectionError()
Fix related mysql documentation links
Change-Id: Id32ef2fd27de65376960de3f5138ffdf7654ff71
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together
Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
Fix return values to match documentation
Provide fallback if no null value is allowed
Return from inside of try/finally makes it clear for static analyzer
Change-Id: I8bdfa453fc56dc50749cbd324b3d0d36e8e7065e
Rename canRecoverFromDisconnect() in order to better describe
its function. Make it use the transaction ID and query walltime
as arguments and return an ERR_* class constant instead of a bool.
Avoid retries of slow queries that yield lost connection errors.
Add methods and class constants to track session state errors
caused by the loss of named locks or temp tables. Such errors can
be resolved by a "session flush" method.
Make assertQueryIsCurrentlyAllowed() better distinguish ROLLBACK
queries from ROLLBACK TO SAVEPOINT queries. For some scenarios,
only full tranasction ROLLBACK queries should be allowed.
Add flushSession() method to Database and flushPrimarySessions()
methods to LBFactory/LoadBalancer.
Also:
* Rename wasKnownStatementRollbackError() and make it take the
error number as an argument, similar to wasConnectionError().
Add mysql error codes for query timeouts since they only cause
statement rollbacks.
* Rename wasConnectionError() and mark it as protected. This is an
internal method with no outside callers.
* Rename wasQueryTimeout(), remove some HHVM-specific code, and
simplify the arguments.
* Make executeQuery() use a for loop for the query retry logic
to reduce code duplication.
* Move the error state setting logic in executeQueryAttempt() up
in order to reduce code duplication.
* Move the beginIfImplied() call in executeQueryAttempt() up to the
retry loop in executeQuery(). This narrows the executeQueryAttempt()
concerns to sending a single query and updating tracking fields.
* Make closeConnection() and doHandleSessionLossPreconnect() in
DatabaseSqlite more consistent with the base class by releasing named locks.
* Mark trxStatus() as @internal.
Bug: T281451
Bug: T293859
Change-Id: I200f90e413b8a725828745f81925b54985c72180
- The public method that is being called internally only, is now private.
- The getters are replaced with direct access.
- Make calls to TransactionManager a batch.
Bug: T299698
Change-Id: Id9c5d6a692abd573793c1cab3d07ebf0ee8760f4
Currently it throws an exception when the database type has been changed
to unsupported one in localsettings.php.
The code displays a very confusing error in the browser when triggered,
to solve the error I used database exception and conditional statement.
If db type is not one of built-in supported or don't have custom
implementation DBerror will be thrown.
Bug: T212236
Change-Id: I5fce8b42a5e42e03a34aff5820f7b842393912f1
The pingAll() loop in updateSpecialPages.php tries salvage a
long-running process by waiting for a restarting DB server to come back
up again. The feature was broken because assertHasConnectionHandle()
would throw an exception if a previous reconnection attempt failed.
So, have ping() call replaceLostConnection() if the connection is
already missing.
Change-Id: I24b4cc18a7b586e014dcfd25b50653487fb18893
Fix the fixme in LoadBalancer::getServerConnection() and throw an
exception on connection loss if errors are not silenced. Otherwise a
server shutdown during a maintenance script always leads to an
InvalidArgumentException from DBConnRef::__construct().
Also, improve related log messages.
Change-Id: I8a5af3271264837d7a694382be4c70a735169f8d
This would make Database class smaller and encapsulates the transaction
logic making it easier to understand and change.
Bug: T299698
Change-Id: I409a474209ab4b714c5f62e5e7c0b7a62b9e82c1
Don't count lock waits as write queries in the transaction profiler.
They are not replicated, so it doesn't make sense to count them.
I think 014369874b accidentally inverted the meaning of
QUERY_CHANGE_LOCKS, since previously lock changes used
QUERY_CHANGE_NONE, which forced isWriteQuery() to return false.
Bug: T300194
Change-Id: I29a02c87156a36a5a094e226effb52d513cce76d
* Enforce the ban on is_resource in phpcs
* In OrderedStreamingForkController, the comment was incorrect. I
confirmed using a small test script that if the child closes one end
of a socket pair, the other end will still be open, and is_resource()
will still return true, and fclose() will not fail. The issue was
introduced in c82d30d19c, it was not present in the
CirrusSearch copy of the class.
* Allow is_resource() for debug logging.
* Allow is_resource() for parameter validation where a stream may be
passed to a function, since there is no alternative.
Bug: T260735
Change-Id: I59a752f7bb4b043ddfb2434b52a02f9221bf54db
This would make it actually log /* Class::method */ with the query both
in full and normalized one.
Bug: T298687
Change-Id: Id3cd6bd21ac426cba3ceb3d780f36074a0d25127
This will serve two purposes:
- In future, we would have only one DbLogger injected to classes and
that would dispatch to the correct logger (and the channel) in
itself based on these categories. This would encapsulate the logic of
db logging in rdbms. Simplifies code, handles contexual fields such
as dbname, etc.
There is a PoC of this in Ic20177bd350f9.
- This in logstash would allow us to build graphs for granular types of
errors. For example, deadlocks, sql syntax errors, read-only errors,
and so on.
Bug: T297435
Change-Id: Ibf770c2afb238623bed4d39c1f55831853afc61f
Follows-up 4ba64a1967 (Ic2d6b054b) which added the method with the bug,
and the LinksUpdate refactor (d3b2b8006, I472f4a023) which first
used the method.
Bug: T299095
Change-Id: I9746e69b7b4f79d0afb9b965da43b9ae36c6afe4
Add support for MySQL's per-table syntax for straight joins, which is
a join type analogous to LEFT JOIN.
SelectQueryBuilder::straightJoin() previously enabled the whole-query
straight join option, but it makes more sense for it to work analogously
with leftJoin(). So I renamed the existing method to
straightJoinOption(). No callers found in CodeSearch.
The motivation is to allow us to prevent reordering of the change_tag
join without affecting the rest of the recentchanges query.
Bug: T298225
Change-Id: I2bfcffc2bf9a64f23afdea0dfaccf89938896e62