Allows acquiring ids of records in database table, by inspecting a given read-only replica database to initially find existing records with their ids, and insert non-existing records into a read-write master database and getting those ids as well from the master database after insertion.
More...
|
| __construct (ILBFactory $lbFactory, $table, $idColumn, LoggerInterface $logger=null, $flags=0x0, $waitForReplicationTimeout=2) |
|
| acquireIds (array $neededRecords, $recordsToInsertDecoratorCallback=null) |
| Acquire ids of needed records in the table, inserting non-existing ones into master database. More...
|
|
|
const | FLAG_IGNORE_REPLICA = 0x1 |
| This flag changes this object's behavior so that it always queries master database to find existing items, bypassing replica database completely. More...
|
|
Allows acquiring ids of records in database table, by inspecting a given read-only replica database to initially find existing records with their ids, and insert non-existing records into a read-write master database and getting those ids as well from the master database after insertion.
- See also
- Item & Property Terms
- Copyright
- GPL-2.0-or-later
◆ __construct()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::__construct |
( |
ILBFactory |
$lbFactory, |
|
|
|
$table, |
|
|
|
$idColumn, |
|
|
LoggerInterface |
$logger = null , |
|
|
|
$flags = 0x0 , |
|
|
|
$waitForReplicationTimeout = 2 |
|
) |
| |
- Parameters
-
ILBFactory | $lbFactory | |
string | $table | the name of the table this acquirer is for |
string | $idColumn | the name of the column that contains the desired ids |
LoggerInterface | null | $logger | |
int | $flags | { |
- See also
- self::FLAG_IGNORE_REPLICA}
- Parameters
-
int | $waitForReplicationTimeout | in seconds, the timeout on waiting for replication |
◆ acquireIds()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::acquireIds |
( |
array |
$neededRecords, |
|
|
|
$recordsToInsertDecoratorCallback = null |
|
) |
| |
Acquire ids of needed records in the table, inserting non-existing ones into master database.
Note 1: this function assumes that all records given in $neededRecords specify the same columns. If some records specify less, more or different columns than the first one does, the behavior is not defined. The first element keys will be used as the set of columns to select in database and to provide back in the returned array.
Note 2: this function assumes that all records given in $neededRecords have their values as strings. If some values are of different type (e.g. integer ids) this can cause a false mismatch in identifying records selected in database with their corresponding needed records.
- Parameters
-
array | $neededRecords | array of records to be looked-up or inserted. Each entry in this array should an associative array of column => value pairs. Example: [ [ 'columnA' => 'valueA1', 'columnB' => 'valueB1' ], [ 'columnA' => 'valueA2', 'columnB' => 'valueB2' ], ... ] |
callable | null | $recordsToInsertDecoratorCallback | a callback that will be passed the array of records that are about to be inserted into master database, and should return a new array of records to insert, allowing to enhance and/or supply more default values for other columns that are not supplied as part of $neededRecords array. |
- Returns
- array[] the array of input records along with their ids Example: [ [ 'columnA' => 'valueA1', 'columnB' => 'valueB1', 'idColumn' => '1' ], [ 'columnA' => 'valueA2', 'columnB' => 'valueB2', 'idColumn' => '2' ], ... ]
◆ calcRecordHash()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::calcRecordHash |
( |
array |
$record | ) |
|
|
private |
◆ fetchExistingRecords()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::fetchExistingRecords |
( |
array |
$neededRecords | ) |
|
|
private |
◆ fetchExistingRecordsFromMaster()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::fetchExistingRecordsFromMaster |
( |
array |
$neededRecords, |
|
|
IDatabase |
$dbw = null |
|
) |
| |
|
private |
◆ fetchExistingRecordsFromReplica()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::fetchExistingRecordsFromReplica |
( |
array |
$neededRecords | ) |
|
|
private |
◆ filterNonExistingRecords()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::filterNonExistingRecords |
( |
|
$neededRecords, |
|
|
|
$existingRecords |
|
) |
| |
|
private |
◆ findExistingRecords()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::findExistingRecords |
( |
IDatabase |
$db, |
|
|
array |
$neededRecords |
|
) |
| |
|
private |
- Parameters
-
IDatabase | $db | Caller can choose for this to be the Master or Replica |
array | $neededRecords | |
- Returns
- array
◆ getDbMaster()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::getDbMaster |
( |
| ) |
|
|
private |
◆ getDbReplica()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::getDbReplica |
( |
| ) |
|
|
private |
◆ getLoadBalancer()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::getLoadBalancer |
( |
| ) |
|
|
private |
◆ insertNonExistingRecords()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::insertNonExistingRecords |
( |
array |
$records, |
|
|
|
$recordsToInsertDecoratorCallback = null |
|
) |
| |
|
private |
◆ insertNonExistingRecordsIntoMaster()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::insertNonExistingRecordsIntoMaster |
( |
array |
$neededRecords | ) |
|
|
private |
- Parameters
-
array | $neededRecords | SecurityCheck-SQLInjection |
◆ isIgnoringReplica()
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::isIgnoringReplica |
( |
| ) |
|
|
private |
◆ $flags
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::$flags |
|
private |
◆ $idColumn
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::$idColumn |
|
private |
◆ $lbFactory
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::$lbFactory |
|
private |
◆ $logger
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::$logger |
|
private |
◆ $table
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::$table |
|
private |
◆ $waitForReplicationTimeout
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::$waitForReplicationTimeout |
|
private |
◆ FLAG_IGNORE_REPLICA
const Wikibase\Lib\Store\Sql\Terms\Util\ReplicaMasterAwareRecordIdsAcquirer::FLAG_IGNORE_REPLICA = 0x1 |
This flag changes this object's behavior so that it always queries master database to find existing items, bypassing replica database completely.
The documentation for this class was generated from the following file: