MediaWiki
1.32.5
|
Class for getting statistically unique IDs. More...
Public Member Functions | |
__destruct () | |
Static Public Member Functions | |
static | newRawUUIDv1 () |
Return an RFC4122 compliant v1 UUID. More... | |
static | newRawUUIDv4 ( $flags=0) |
Return an RFC4122 compliant v4 UUID. More... | |
static | newSequentialPerNodeID ( $bucket, $bits=48, $flags=0) |
Return an ID that is sequential only for this node and bucket. More... | |
static | newSequentialPerNodeIDs ( $bucket, $bits, $count, $flags=0) |
Return IDs that are sequential only for this node and bucket. More... | |
static | newTimestampedUID128 ( $base=10) |
Get a statistically unique 128-bit unsigned integer ID string. More... | |
static | newTimestampedUID88 ( $base=10) |
Get a statistically unique 88-bit unsigned integer ID string. More... | |
static | newUUIDv1 () |
Return an RFC4122 compliant v1 UUID. More... | |
static | newUUIDv4 ( $flags=0) |
Return an RFC4122 compliant v4 UUID. More... | |
static | unitTestTearDown () |
Cleanup resources when tearing down after a unit test. More... | |
Public Attributes | |
const | QUICK_RAND = 1 |
const | QUICK_VOLATILE = 2 |
Protected Member Functions | |
__construct () | |
getSequentialPerNodeIDs ( $bucket, $bits, $count, $flags) | |
Return IDs that are sequential only for this node and bucket. More... | |
getTimeAndDelay ( $lockFile, $clockSeqSize, $counterSize, $offsetSize) | |
Get a (time,counter,clock sequence) where (time,counter) is higher than any previous (time,counter) value for the given clock sequence. More... | |
getTimestampedID128 (array $info) | |
getTimestampedID88 (array $info) | |
getUUIDv1 (array $info) | |
intervalsSinceGregorianBinary (array $time, $delta=0) | |
millisecondsSinceEpochBinary (array $time) | |
timeWaitUntil ( $time) | |
Wait till the current timestamp reaches $time and return the current timestamp. More... | |
Static Protected Member Functions | |
static | singleton () |
Protected Attributes | |
array | $fileHandles = [] |
Cached file handles. More... | |
string | $lockFile128 |
Local file path. More... | |
string | $lockFile88 |
Local file path. More... | |
string | $lockFileUUID |
Local file path. More... | |
string | $nodeId32 |
Node ID in binary (32 bits) More... | |
string | $nodeId48 |
Node ID in binary (48 bits) More... | |
string | $nodeIdFile |
Local file path. More... | |
Static Protected Attributes | |
static UIDGenerator | $instance = null |
Private Member Functions | |
deleteCacheFiles () | |
Delete all cache files that have been created. More... | |
Class for getting statistically unique IDs.
Definition at line 30 of file UIDGenerator.php.
|
protected |
Definition at line 53 of file UIDGenerator.php.
References $line, MWCryptRand\generateHex(), wfIsWindows(), wfShellExec(), and wfTempDir().
UIDGenerator::__destruct | ( | ) |
Definition at line 683 of file UIDGenerator.php.
|
private |
Delete all cache files that have been created.
This is a cleanup method primarily meant to be used from unit tests to avoid poluting the local filesystem. If used outside of a unit test environment it should be used with caution as it may destroy state saved in the files.
Definition at line 648 of file UIDGenerator.php.
|
protected |
Return IDs that are sequential only for this node and bucket.
string | $bucket | Arbitrary bucket name (should be ASCII) |
int | $bits | Bit size (16 to 48) of resulting numbers before wrap-around |
int | $count | Number of IDs to return |
int | $flags | (supports UIDGenerator::QUICK_VOLATILE) |
RuntimeException |
Definition at line 363 of file UIDGenerator.php.
References $cache, $path, wfIsCLI(), and wfTempDir().
|
protected |
Get a (time,counter,clock sequence) where (time,counter) is higher than any previous (time,counter) value for the given clock sequence.
This is useful for making UIDs sequential on a per-node bases.
string | $lockFile | Name of a local lock file |
int | $clockSeqSize | The number of possible clock sequence values |
int | $counterSize | The number of possible counter values |
int | $offsetSize | The number of possible offset values |
RuntimeException |
Definition at line 443 of file UIDGenerator.php.
References captcha-old\count, and timeWaitUntil().
|
protected |
array | $info | The result of UIDGenerator::getTimeAndDelay(), for sub classes, a seqencial array like (time, offsetCounter, clkSeq). |
RuntimeException |
Definition at line 189 of file UIDGenerator.php.
References $nodeId48, $time, and millisecondsSinceEpochBinary().
|
protected |
array | $info | result of UIDGenerator::getTimeAndDelay(), or for sub classes, a seqencial array like (time, offsetCounter). |
RuntimeException |
Definition at line 135 of file UIDGenerator.php.
References $nodeId32, $time, and millisecondsSinceEpochBinary().
|
protected |
array | $info | Result of UIDGenerator::getTimeAndDelay() |
Definition at line 245 of file UIDGenerator.php.
References $nodeId48, and intervalsSinceGregorianBinary().
|
protected |
array | $time | Array of second and millisecond integers |
int | $delta | Number of intervals to add on to the timestamp |
RuntimeException |
Definition at line 612 of file UIDGenerator.php.
Referenced by getUUIDv1().
|
protected |
array | $time | Array of second and millisecond integers |
RuntimeException |
Definition at line 595 of file UIDGenerator.php.
Referenced by getTimestampedID128(), and getTimestampedID88().
|
static |
Return an RFC4122 compliant v1 UUID.
RuntimeException |
Definition at line 237 of file UIDGenerator.php.
Referenced by UIDGeneratorTest\testUUIDv1().
|
static |
Return an RFC4122 compliant v4 UUID.
int | $flags | Bitfield (supports UIDGenerator::QUICK_RAND) |
RuntimeException |
Definition at line 316 of file UIDGenerator.php.
Referenced by JobQueueRedis\getNewJobFields(), UIDGeneratorTest\testRawUUIDv4(), and UIDGeneratorTest\testRawUUIDv4QuickRand().
|
static |
Return an ID that is sequential only for this node and bucket.
These IDs are suitable for per-host sequence numbers, e.g. for some packet protocols. If UIDGenerator::QUICK_VOLATILE is used the counter might reset on server restart.
string | $bucket | Arbitrary bucket name (should be ASCII) |
int | $bits | Bit size (<=48) of resulting numbers before wrap-around |
int | $flags | (supports UIDGenerator::QUICK_VOLATILE) |
Definition at line 332 of file UIDGenerator.php.
Referenced by UIDGeneratorTest\testNewSequentialID().
|
static |
Return IDs that are sequential only for this node and bucket.
string | $bucket | Arbitrary bucket name (should be ASCII) |
int | $bits | Bit size (16 to 48) of resulting numbers before wrap-around |
int | $count | Number of IDs to return |
int | $flags | (supports UIDGenerator::QUICK_VOLATILE) |
Definition at line 347 of file UIDGenerator.php.
References singleton().
Referenced by CdnCacheUpdate\HTCPPurge(), and UIDGeneratorTest\testNewSequentialIDs().
|
static |
Get a statistically unique 128-bit unsigned integer ID string.
The bits of the UID are prefixed with the time (down to the millisecond).
These IDs are suitable as globally unique IDs, without any enforced uniqueness. New rows almost always have higher UIDs, which makes B-TREE updates on INSERT fast. They can also be stored as "DECIMAL(39) UNSIGNED" or BINARY(16) in MySQL.
UID generation is serialized on each server (as the node ID is for the whole machine).
int | $base | Specifies a base other than 10 |
RuntimeException |
Definition at line 171 of file UIDGenerator.php.
References $base, and singleton().
Referenced by ExternalStoreMwstore\store().
|
static |
Get a statistically unique 88-bit unsigned integer ID string.
The bits of the UID are prefixed with the time (down to the millisecond).
These IDs are suitable as values for the shard key of distributed data. If a column uses these as values, it should be declared UNIQUE to handle collisions. New rows almost always have higher UIDs, which makes B-TREE updates on INSERT fast. They can also be stored "DECIMAL(27) UNSIGNED" or BINARY(11) in MySQL.
UID generation is serialized on each server (as the node ID is for the whole machine).
int | $base | Specifies a base other than 10 |
RuntimeException |
Definition at line 118 of file UIDGenerator.php.
References $base, and singleton().
|
static |
Return an RFC4122 compliant v1 UUID.
RuntimeException |
Definition at line 222 of file UIDGenerator.php.
References singleton().
Referenced by UIDGeneratorTest\testUUIDv1().
|
static |
Return an RFC4122 compliant v4 UUID.
int | $flags | Bitfield (supports UIDGenerator::QUICK_RAND) |
RuntimeException |
Definition at line 290 of file UIDGenerator.php.
References MWCryptRand\generateHex(), QUICK_RAND, and wfRandomString().
Referenced by UIDGeneratorTest\testUUIDv4().
|
staticprotected |
Definition at line 95 of file UIDGenerator.php.
References $instance.
Referenced by newSequentialPerNodeIDs(), newTimestampedUID128(), newTimestampedUID88(), newUUIDv1(), and unitTestTearDown().
|
protected |
Wait till the current timestamp reaches $time and return the current timestamp.
This returns false if it would have to wait more than 10ms.
int | $time | Result of time() |
Definition at line 576 of file UIDGenerator.php.
References $time.
Referenced by getTimeAndDelay().
|
static |
Cleanup resources when tearing down after a unit test.
This is a cleanup method primarily meant to be used from unit tests to avoid poluting the local filesystem. If used outside of a unit test environment it should be used with caution as it may destroy state saved in the files.
Definition at line 677 of file UIDGenerator.php.
References singleton().
Referenced by UIDGeneratorTest\tearDown().
|
protected |
Cached file handles.
Definition at line 48 of file UIDGenerator.php.
|
staticprotected |
Definition at line 32 of file UIDGenerator.php.
Referenced by singleton().
|
protected |
Local file path.
Definition at line 43 of file UIDGenerator.php.
|
protected |
Local file path.
Definition at line 41 of file UIDGenerator.php.
|
protected |
Local file path.
Definition at line 45 of file UIDGenerator.php.
|
protected |
Node ID in binary (32 bits)
Definition at line 36 of file UIDGenerator.php.
Referenced by getTimestampedID88().
|
protected |
Node ID in binary (48 bits)
Definition at line 38 of file UIDGenerator.php.
Referenced by getTimestampedID128(), and getUUIDv1().
|
protected |
Local file path.
Definition at line 34 of file UIDGenerator.php.
const UIDGenerator::QUICK_RAND = 1 |
Definition at line 50 of file UIDGenerator.php.
Referenced by JobQueueRedis\getNewJobFields(), newUUIDv4(), and UIDGeneratorTest\testRawUUIDv4QuickRand().
const UIDGenerator::QUICK_VOLATILE = 2 |
Definition at line 51 of file UIDGenerator.php.
Referenced by CdnCacheUpdate\HTCPPurge().