aboutsummaryrefslogtreecommitdiffstats
path: root/includes/libs/rdbms/lbfactory/LBFactorySimple.php
Commit message (Collapse)AuthorAgeFilesLines
* libs: Use type declaration on undocumented private functionsUmherirrender2025-03-311-1/+1
| | | | Change-Id: I9a74c316b87ae35597ce846a830a55542d9aa14c
* rdbms: clean up LBFactorySingle construction and documentationAaron Schulz2024-09-201-1/+1
| | | | | | | | | | | | | | | Remove the "lb" option from __construct(). Instead, just automatically make an instance of LoadBalancerDisabled if "connection" is null. Update newDisabled(), the only caller using "lb", to pass a null connection. Explicitly specify the extra LoadBalancer parameters in __construct(). Rename "lb" field to "mainLB" for consistency with other subclasses. Tweak documentation for LBFactory subclasses to use more consistent language about LoadBalancer and clusters. Change-Id: Ia81f1a9eb00e682e9a223770573d21f92857a698
* Replace array_keys in foreach to use $_ as value insteadUmherirrender2023-07-101-1/+1
| | | | | | | | When the value of the associated array is not used, there is no need to use array_keys and create internal a copy of the array, just omit the value with $_ to tell static analyzer that the var is unused. Change-Id: I5c6d667e98c0167c0573c683f0d617bc1d4ca619
* rdbms: Drop hard-deprecated and unused ILBFactory::forEachLB()Amir Sarabadani2023-01-111-10/+0
| | | | | Bug: T326274 Change-Id: I7ad07ee3385c1a862ecc0188d07b2252a7f518aa
* Make use of ??= in more placesDannyS7122022-12-171-3/+1
| | | | | | New feature from PHP 7.4 Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
* rdbms: improve documentation about sections/clusters in LBFactory classesAaron Schulz2022-09-171-1/+8
| | | | | Bug: T316299 Change-Id: Ia87b8ec274db462e527a9a05cdf189922ec3ad94
* rdbms: Clean up file doc commentsTimo Tijhof2022-08-091-5/+3
| | | | | | | | | | | | | | | | | | | | | | | * Document what the LBFactory/LoadBalancer (sub)classes do. * Move useful descriptions from file doc to class doc so that we don't pointlessly maintain it in two places, and to allow for the file block to be consistently visually ignored instead of sometimes containing useful information. This patch removes various non-applicable or unrelated descriptions from the file block that were blindly copy-pasted, thus proving my point. It also removes two duplicate/clashing definition of the 'Database' defgroup. Keeping only the primary one in IDatabase.php. * Move ingroup tag to class block, as indexing the source file in Doxygen creates noise in the navigation sidebar and does not add add any benefit. * Fix dead-end reference to a sqlite/README. I'll rework this in a later patch. Change-Id: Iad0e67d766f4a7d5b97e7a471b49f2d8e60c506b
* Replace LoadBalancer/LBFactory callback iteration with generatorsTim Starling2022-04-291-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Callback style iteration made sense before generators existed, but generators make for simpler code. The "call method" variants made sense before closures existed but defeat static analysis. So, in LBFactory: * Add ILBFactory::getAllLBs() * Deprecate ILBFactory::forEachLB() * Remove LBFactory::forEachLBCallMethod(), was protected. * Add LBFactory::getLBsForOwner(), which is protected and has the internal interface in @return. Adding a new abstract method breaks Wikibase tests despite LBFactory not being stable to extend. * Migrate callers. Generators allow you to return/break from the middle of the loop, which implies a little rearrangement for some callers. In LoadBalancer, connections supposedly of type IDatabase were routinely type-hinted as Database in closure parameters so that methods could be called that were not in the interface. So it's convenient to get rid of public iteration methods entirely in favour of private methods returning Database[]. * Hard-deprecate ILoadBalancerForOwner::forEachOpenConnection() and replace it with a private generator method since nothing called it externally except for core tests. * Hard-deprecate ILoadBalancerForOwner::forEachOpenPrimaryConnection() and replace it with a private generator. DeferredUpdates needed it for iterating over IDatabase::explicitTrxActive(), so add ILoadBalancer::explicitTrxActive() as a replacement. * Replace private method LoadBalancer::forEachOpenReplicaConnection() with a generator. Depends-On: If0b382231e27d6d1197fb7b6aef6ab50335df4e5 Change-Id: I64514e77b9bfe737be5b12e1d3c9c49976bb522f
* rdbms: Remove instance ownership conceptTim Starling2022-04-261-13/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instance ownership is supposed to protect LoadBalancer and Database against unauthorized calls to internal methods other than by the owning LoadBalancer/LBFactory. This seems like unnecessary complexity. It was introduced for T231443 and T217819, but the link was speculative and in the end it didn't help to fix or isolate those bugs. Since then it has caused a production error (T303885) and an intermittent CI failure (T292239). Instead, split the ILoadBalancer interface, introducing ILoadBalancerForOwner, which contains the methods which are only safe to call by LBFactory or by the caller of LBFactory::newMainLB(). This allows phan to statically detect inappropriate calls to internal methods. Ownership was used for convenience for two things unrelated to its original purpose: * Suppressing calls to ScopedCallback::newScopedIgnoreUserAbort() when the caller has already called it. But nested calls are apparently harmless, so I just called it unconditionally. * Suppressing exceptions from Database::close(). I extended the behaviour for owned instances to apply to all instances, so even unowned instances will no longer throw on close. CodeSearch suggests nothing in extensions is calling these methods with an owner parameter. One extension (Wikibase) overrides a method with an owner parameter in a test mock class and so needs to be simultaneously updated. Depends-On: Ib03aba9d8f5f05b875a321d00b14483633a636a8 Change-Id: I27ba4973d24d759c88b3868c95e7db875801ca0c
* docs: Change wording master to primary in comments and log textUmherirrender2021-09-011-1/+1
| | | | | Bug: T254646 Change-Id: I5379dc79be60c99f0a30f74e5d624f81fe6f921b
* Add typehints to several methodsDaimona Eaytoy2021-08-311-6/+6
| | | | | | | | | | | | | These not only make the code more robust, but also help a lot when writing unit tests: if a method is return-typehinted and its class is mocked, the mock method will automatically return a mock of its declared return type. Otherwise it will return null, and developers are forced to manually mock the method if the return value is used by the SUT in a way that doesn't accept null. Depends-On: I628fcb1807133390c7b9b47984f512f5b1ae58d0 Depends-On: I7080bc505f5838b2f51a368da562104e206063b0 Change-Id: I59068cfed10aabf6c6002f9e9312a6ef6e7e9441
* Remove unused default values from class propertiesThiemo Kreuz2021-05-121-1/+1
| | | | | | | | In all these cases the property is unconditionally set in the constructor. The extra initialisation is effectively dead code and an extra source of errors and confusion. Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
* rdbms: add LoadBalancer::getClusterName() methodAaron Schulz2021-03-011-4/+16
| | | | | | | | | | Also: * Add LBFactoryMulti sanity check to avoid section/cluster collisions. Since sections are just a type of cluster, using the same name can cause confusion. WMF config already treats them as overall unique. * Rename 'externalLoads' field in LoadBalancer for clarity. Change-Id: I748db691b4918b797b82d75cfd8722453ccd9d7f
* rdbms: add "loadMonitor" parameter to LBFactoryMulti/LBFactorySimpleAaron Schulz2020-03-271-5/+13
| | | | | | | | | | This allows full configuration of the LoadMonitor, not just setting the class name like loadMonitorClass allows. Deprecate the later. Also fix obsolete LoadBalancer constructor documentation and standardize the style of LBFactoryMulti::__construct() comments. Change-Id: Icfdc0d6bbf227dce56e65ad679b93ce3f604e9f7
* rdbms: various cleanups to LoadBalancer::reallyOpenConnection()Aaron Schulz2019-10-111-9/+0
| | | | | | | | | | | | | | | | | | Move the DBO_TRX init logic out of Database::__construct() and into LoadBalancer since the later already handles setting and clearing this flag based on transaction rounds starting and ending. Add 'lazyMasterHandle', 'topologyRole', and 'topologicalMaster' parameters to Database::factory() and inject them via LoadBalancer all at once in order to avoid worrying about call order. Move some type casting code to Database::__construct(). Add IDatabase::getTopologyRole()/getTopologicalMaster(). Use constants for getLBInfo()/setLBInfo() for better usage tracking and typo resistance. Change-Id: I437ce434326601e6ba36d9aedc55db396dfe4452
* rdbms: expand on LoadBalancer ownership conceptAaron Schulz2019-09-051-8/+8
| | | | | | | | | | | | | | | | | | | | Enforce this pattern for the remaining LoadBalancer methods. Carry this over into Database::close() to decide how loud the error handling should be. In LBFactory, clean up ownership of newMainLB()/newExternalLB(). The should have a null owner if called from outside the class since the LBFactory does not track nor care about them anymore in that case. Disable newMainLB() for LBFactorySingle as it makes no sense and was broken. Also remove some redundant abstract LBFactory methods that just duplciate ILBFactory. Bug: T231443 Bug: T217819 Depends-On: I7ed5c799320430c196a9a8e81af901999e2de7d0 Change-Id: I90b30a79754cfcc290277d302052e60df4fbc649
* rdbms: assorted LBFactoryMulti/LBFactorySimple cleanupsAaron Schulz2019-09-041-25/+30
| | | | | | | | | | | | | Ignore "groupLoads" in "serverTemplate" for consistency with "load". These server config map values should come from "groupLoadsBySection" and "sectionLoads" only. Simplify LBFactoryMulti::makeServerArray() to not bother setting values that LoadBalancer already sets ('flags', 'master', 'replica'). Move down private methods and clean up a various code comments. Change-Id: I0fe7f913a37236380127bef8d02768a9d1209596
* Revert "rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRX"Urbanecm2019-08-251-0/+8
| | | | | | | | | This reverts commit 45831e619c5e667ae1201bcdacfb8d4dcce10b41. Reason for revert: Caused beta not work at all. Bug: T231162 Change-Id: Icc5c1fa0dc01082a622641ad96c22c939cd56d48
* rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRXAaron Schulz2019-08-241-8/+0
| | | | | | | | | | | | | | Make LoadBalancer::reallyOpenConnection() handle initializing DBO_TRX instead of Database::__construct(). Also: * Avoid having the "catch" block appear like it returns a half-constructed Database. * Use the variable name $conn instead of $db to be consistent throughout the class. Only send Database::__construct() parameters that it recognizes instead of mixing in setLBInfo() data. Change-Id: Iffc3d1d0713051a164adb51a4c4ee12e4ac887c3
* rdbms: clean up LBFactory domain splitting code and remove redundant commentsAaron Schulz2019-06-281-17/+1
| | | | Change-Id: I43812537e52b7a815e918512e2585e4858c06888
* rdbms: move "maxLag" parameter up to LBFactory and add commentsAaron Schulz2019-02-051-7/+0
| | | | | | Also make the default value constant be define in only one place Change-Id: I1abd2b4569910031853b25f92d7cb69a1614d05b
* Get rid of call_user_func(_array)(), part 3Max Semenik2018-06-101-2/+2
| | | | | | Also cleaned up nearby code in a couple places. Change-Id: Ibf44ee7c0ceb739d7e79406e4ff39303c316e285
* Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenientBartosz DziewoƄski2018-05-301-8/+4
| | | | | | | | | | | | | | 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
* Add "maxLag" parameter to LBFactory sub-classes and LoadBalancerAaron Schulz2017-11-221-0/+7
| | | | Change-Id: I2559e81a4a67036a899fec10582ac1ccb3818cf1
* Defer calling ChronologyProtector::initLB() until connectingAaron Schulz2017-03-281-2/+0
| | | | | Bug: T160678 Change-Id: Id51c2854f38d9e4697e52776168b16996e9152e4
* Move remaining LoadBalancer classes to RdbmsAaron Schulz2017-02-231-1/+0
| | | | | | The old names are left as aliases. Change-Id: I52a327f2463a2ba7437324047b5b00d28cd1d758
* Move LBFactory to Rdbms namespaceAaron Schulz2017-02-031-0/+5
| | | | Change-Id: I5ae10783228d0252284807c9562bc8e328d4becb
* Improve getLagTimes.php output and add statsD flagAaron Schulz2016-11-041-0/+13
| | | | | | | | | | | | * The script now lists all DBs in the LBFactory, not just those of the current wiki cluster. * Add a --report option to send the metrics to statsD so that the MediaWiki view of lag can be measured, rather than just the DB-level view. This avoids some noise with depooled servers. Bug: T149210 Change-Id: I6eae25e29aecf21251ad0eec53c56a86f35007f5
* Cleanup unused LBFactory $domain argumentsAaron Schulz2016-10-241-14/+3
| | | | Change-Id: I17b409a71e263ff5e0175f6a35fb9c5288f00c11
* Implement scaleLoads() in LoadMonitorMySQLAaron Schulz2016-10-031-2/+2
| | | | | | | | | | | * Recently pooled servers will get more traffic as their internal caches warm up by getting queries * Also let LoadMonitor support options for flexibility The "loadMonitor" config field now takes in array in LoadBalancer. * Make LoadMonitor the default instead of LoadMonitorNull. Change-Id: I53b89b0c25bdcc30deec3f8b502fb14479c53ae8
* Make newExternalLB() public to match newMainLB()Aaron Schulz2016-09-221-1/+1
| | | | Change-Id: I7e46c947882c5de6e4d25a7110c2a2558df7ad76
* Fix @return of LBFactorySimple::getExternalLB()Kunal Mehta2016-09-211-1/+1
| | | | Change-Id: If5353af7c4ec3781597159c12481444159c463f3
* Database class parameter and documentation cleanupsAaron Schulz2016-09-191-0/+12
| | | | | | | | | | * Document various parameter arrays. * Fix $user = false loophole in Database::__construct(). * Set the Postgres port *before* calling super, as it is needed by open(). * Remove 'chronProt' parameter as it is lazy-loaded. Change-Id: Icc1037efa1eee7ae6fdd2919f60001e6e29ae55c
* Fix "externalCluster" LBFactorySimple setting in LBFactoryMWAaron Schulz2016-09-191-1/+1
| | | | | | Fixes regression from d175b391ae2a Change-Id: I4bbc875e2fcd021e342959a37475ec356cb58cce
* Move LBFactorySimple to /libs/rdbmsAaron Schulz2016-09-171-0/+139
* Refactored LBFactory a bit to make this possible. * Move newChronologyProtector() up to LBFactory and make a lazy-loading method instead. * Move appendPreShutdownTimeAsQuery() up to LBFactory. * Inject the web request values for LBFactory from Setup.php. * Remove unused laggedSlaveUsed() method. Change-Id: Ie8a38a6f4d6359680eb6a5be24a34e30b9816479