Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer Class Reference

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 primary database and getting those ids as well from the primary database after insertion. More...

+ Collaboration diagram for Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer:

Public Member Functions

 __construct (RepoDomainDb $repoDb, string $table, string $idColumn, int $flags=0x0, int $waitForReplicationTimeout=2)
 
 acquireIds (array $neededRecords, ?callable $recordsToInsertDecoratorCallback=null)
 Acquire ids of needed records in the table, inserting non-existing ones into primary database.
 

Public Attributes

const FLAG_IGNORE_REPLICA = 0x1
 This flag changes this object's behavior so that it always queries primary database to find existing items, bypassing replica database completely.
 

Private Member Functions

 fetchExistingRecords (array $neededRecords)
 
 insertNonExistingRecords (array $records, ?callable $recordsToInsertDecoratorCallback=null)
 
 fetchExistingRecordsFromPrimary (array $neededRecords, IDatabase $dbw=null)
 
 fetchExistingRecordsFromReplica (array $neededRecords)
 
 getDbReplica ()
 
 getDbPrimary ()
 
 findExistingRecords (IReadableDatabase $db, array $neededRecords)
 
 insertNonExistingRecordsIntoPrimary (array $neededRecords)
 
 filterNonExistingRecords (array $neededRecords, array $existingRecords)
 
 calcRecordHash (array $record)
 
 isIgnoringReplica ()
 

Private Attributes

RepoDomainDb $repoDb
 
string $table
 
string $idColumn
 
int $flags
 
int $waitForReplicationTimeout
 

Detailed Description

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 primary database and getting those ids as well from the primary database after insertion.

See also
Item & Property Terms

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::__construct ( RepoDomainDb $repoDb,
string $table,
string $idColumn,
int $flags = 0x0,
int $waitForReplicationTimeout = 2 )
Parameters
RepoDomainDb$repoDb
string$tablethe name of the table this acquirer is for
string$idColumnthe name of the column that contains the desired ids
int$flags{
See also
self::FLAG_IGNORE_REPLICA}
Parameters
int$waitForReplicationTimeoutin seconds, the timeout on waiting for replication

Member Function Documentation

◆ acquireIds()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::acquireIds ( array $neededRecords,
?callable $recordsToInsertDecoratorCallback = null )

Acquire ids of needed records in the table, inserting non-existing ones into primary 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$neededRecordsarray 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$recordsToInsertDecoratorCallbacka callback that will be passed the array of records that are about to be inserted into primary 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\ReplicaPrimaryAwareRecordIdsAcquirer::calcRecordHash ( array $record)
private

◆ fetchExistingRecords()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::fetchExistingRecords ( array $neededRecords)
private

◆ fetchExistingRecordsFromPrimary()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::fetchExistingRecordsFromPrimary ( array $neededRecords,
IDatabase $dbw = null )
private

◆ fetchExistingRecordsFromReplica()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::fetchExistingRecordsFromReplica ( array $neededRecords)
private

◆ filterNonExistingRecords()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::filterNonExistingRecords ( array $neededRecords,
array $existingRecords )
private

◆ findExistingRecords()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::findExistingRecords ( IReadableDatabase $db,
array $neededRecords )
private
Parameters
IReadableDatabase$dbCaller can choose for this to be the Primary or Replica, but only “read” methods are called in either case
array$neededRecords
Returns
array

◆ getDbPrimary()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::getDbPrimary ( )
private

◆ getDbReplica()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::getDbReplica ( )
private

◆ insertNonExistingRecords()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::insertNonExistingRecords ( array $records,
?callable $recordsToInsertDecoratorCallback = null )
private

◆ insertNonExistingRecordsIntoPrimary()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::insertNonExistingRecordsIntoPrimary ( array $neededRecords)
private
Parameters
array$neededRecords

◆ isIgnoringReplica()

Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::isIgnoringReplica ( )
private

Member Data Documentation

◆ $flags

int Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::$flags
private

◆ $idColumn

string Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::$idColumn
private

◆ $repoDb

RepoDomainDb Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::$repoDb
private

◆ $table

string Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::$table
private

◆ $waitForReplicationTimeout

int Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::$waitForReplicationTimeout
private

◆ FLAG_IGNORE_REPLICA

const Wikibase\Lib\Store\Sql\Terms\Util\ReplicaPrimaryAwareRecordIdsAcquirer::FLAG_IGNORE_REPLICA = 0x1

This flag changes this object's behavior so that it always queries primary database to find existing items, bypassing replica database completely.


The documentation for this class was generated from the following file: