MediaWiki
master
|
Class for getting statistically unique IDs without a central coordinator. More...
Public Member Functions | |
__construct ( $tempDirectory, $shellCallback) | |
__destruct () | |
getTimestampFromUUIDv1 (string $uuid, int $format=TS_MW) | |
Get timestamp in a specified format from UUIDv1. More... | |
newRawUUIDv1 () | |
Return an RFC4122 compliant v1 UUID. More... | |
newRawUUIDv4 () | |
Return an RFC4122 compliant v4 UUID. More... | |
newSequentialPerNodeID ( $bucket, $bits=48, $flags=0) | |
Return an ID that is sequential only for this node and bucket. More... | |
newSequentialPerNodeIDs ( $bucket, $bits, $count, $flags=0) | |
Return IDs that are sequential only for this node and bucket. More... | |
newTimestampedUID128 (int $base=10) | |
Get a statistically unique 128-bit unsigned integer ID string. More... | |
newTimestampedUID88 (int $base=10) | |
Get a statistically unique 88-bit unsigned integer ID string. More... | |
newUUIDv1 () | |
Return an RFC4122 compliant v1 UUID. More... | |
newUUIDv4 () | |
Return an RFC4122 compliant v4 UUID. More... | |
unitTestTearDown () | |
Cleanup resources when tearing down after a unit test (T46850) More... | |
Protected Member Functions | |
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... | |
Protected Attributes | |
array | $fileHandles = [] |
Cached file handles. More... | |
bool | $loaded = false |
Whether initialization completed. 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... | |
callable | $shellCallback |
Callback for running shell commands. More... | |
string | $tmpDir |
Temporary directory. More... | |
Private Member Functions | |
deleteCacheFiles () | |
Delete all cache files that have been created (T46850) More... | |
getNodeId32 () | |
getNodeId48 () | |
load () | |
Load the node ID information. More... | |
Private Attributes | |
const | CLOCK_COUNTER = 'counter' |
Key used in the serialized clock state map that is stored on disk. More... | |
const | CLOCK_OFFSET = 'offset' |
Key used in the serialized clock state map that is stored on disk. More... | |
const | CLOCK_OFFSET_COUNTER = 'offsetCounter' |
Key used in the serialized clock state map that is stored on disk. More... | |
const | CLOCK_SEQUENCE = 'clkSeq' |
Key used in the serialized clock state map that is stored on disk. More... | |
const | CLOCK_TIME = 'time' |
Key used in the serialized clock state map that is stored on disk. More... | |
const | FILE_PREFIX = 'mw-GlobalIdGenerator' |
Avoid using CLASS so namespace separators aren't interpreted as path components on Windows (T259693) More... | |
Class for getting statistically unique IDs without a central coordinator.
Definition at line 34 of file GlobalIdGenerator.php.
Wikimedia\UUID\GlobalIdGenerator::__construct | ( | $tempDirectory, | |
$shellCallback | |||
) |
string | bool | $tempDirectory | A writable temporary directory |
callback | $shellCallback | A callback that takes a shell command and returns the output |
Definition at line 83 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\$shellCallback.
Wikimedia\UUID\GlobalIdGenerator::__destruct | ( | ) |
Definition at line 746 of file GlobalIdGenerator.php.
|
private |
Delete all cache files that have been created (T46850)
This is a cleanup method primarily meant to be used from unit tests to avoid polluting 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 715 of file GlobalIdGenerator.php.
References $path.
Referenced by Wikimedia\UUID\GlobalIdGenerator\unitTestTearDown().
|
private |
Definition at line 689 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\$nodeId32, and Wikimedia\UUID\GlobalIdGenerator\load().
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimestampedID88().
|
private |
Definition at line 698 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\$nodeId48, and Wikimedia\UUID\GlobalIdGenerator\load().
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128(), and Wikimedia\UUID\GlobalIdGenerator\getUUIDv1().
|
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 GlobalIdGenerator::QUICK_VOLATILE) |
RuntimeException |
Definition at line 368 of file GlobalIdGenerator.php.
References $path.
Referenced by Wikimedia\UUID\GlobalIdGenerator\newSequentialPerNodeIDs().
|
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 440 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\timeWaitUntil().
Referenced by Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID128(), Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID88(), and Wikimedia\UUID\GlobalIdGenerator\newUUIDv1().
|
protected |
array | $info | The result of GlobalIdGenerator::getTimeAndDelay() |
RuntimeException |
Definition at line 181 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\CLOCK_OFFSET_COUNTER, Wikimedia\UUID\GlobalIdGenerator\CLOCK_SEQUENCE, Wikimedia\UUID\GlobalIdGenerator\CLOCK_TIME, Wikimedia\UUID\GlobalIdGenerator\getNodeId48(), and Wikimedia\UUID\GlobalIdGenerator\millisecondsSinceEpochBinary().
Referenced by Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID128().
|
protected |
array | $info | result of GlobalIdGenerator::getTimeAndDelay() |
RuntimeException |
Definition at line 135 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\CLOCK_OFFSET_COUNTER, Wikimedia\UUID\GlobalIdGenerator\CLOCK_TIME, Wikimedia\UUID\GlobalIdGenerator\getNodeId32(), and Wikimedia\UUID\GlobalIdGenerator\millisecondsSinceEpochBinary().
Referenced by Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID88().
Wikimedia\UUID\GlobalIdGenerator::getTimestampFromUUIDv1 | ( | string | $uuid, |
int | $format = TS_MW |
||
) |
Get timestamp in a specified format from UUIDv1.
string | $uuid | the UUID to get the timestamp from |
int | $format | the format to convert the timestamp to. Default: TS_MW |
Definition at line 339 of file GlobalIdGenerator.php.
|
protected |
array | $info | Result of GlobalIdGenerator::getTimeAndDelay() |
Definition at line 218 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\getNodeId48(), and Wikimedia\UUID\GlobalIdGenerator\intervalsSinceGregorianBinary().
Referenced by Wikimedia\UUID\GlobalIdGenerator\newUUIDv1().
|
protected |
array | $time | Array of second and millisecond integers |
int | $delta | Number of intervals to add on to the timestamp |
RuntimeException |
Definition at line 610 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getUUIDv1().
|
private |
Load the node ID information.
Definition at line 645 of file GlobalIdGenerator.php.
References $line.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getNodeId32(), and Wikimedia\UUID\GlobalIdGenerator\getNodeId48().
|
protected |
array | $time | Array of second and millisecond integers |
RuntimeException |
Definition at line 593 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128(), and Wikimedia\UUID\GlobalIdGenerator\getTimestampedID88().
Wikimedia\UUID\GlobalIdGenerator::newRawUUIDv1 | ( | ) |
Return an RFC4122 compliant v1 UUID.
RuntimeException |
Definition at line 265 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\newUUIDv1().
Wikimedia\UUID\GlobalIdGenerator::newRawUUIDv4 | ( | ) |
Return an RFC4122 compliant v4 UUID.
RuntimeException |
Definition at line 298 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\newUUIDv4().
Wikimedia\UUID\GlobalIdGenerator::newSequentialPerNodeID | ( | $bucket, | |
$bits = 48 , |
|||
$flags = 0 |
|||
) |
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 GlobalIdGenerator::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 GlobalIdGenerator::QUICK_VOLATILE) |
Definition at line 314 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\newSequentialPerNodeIDs().
Wikimedia\UUID\GlobalIdGenerator::newSequentialPerNodeIDs | ( | $bucket, | |
$bits, | |||
$count, | |||
$flags = 0 |
|||
) |
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 GlobalIdGenerator::QUICK_VOLATILE) |
Definition at line 328 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\getSequentialPerNodeIDs().
Referenced by Wikimedia\UUID\GlobalIdGenerator\newSequentialPerNodeID().
Wikimedia\UUID\GlobalIdGenerator::newTimestampedUID128 | ( | int | $base = 10 | ) |
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 166 of file GlobalIdGenerator.php.
References $base, Wikimedia\UUID\GlobalIdGenerator\CLOCK_OFFSET_COUNTER, Wikimedia\UUID\GlobalIdGenerator\getTimeAndDelay(), and Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128().
Wikimedia\UUID\GlobalIdGenerator::newTimestampedUID88 | ( | int | $base = 10 | ) |
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 120 of file GlobalIdGenerator.php.
References $base, Wikimedia\UUID\GlobalIdGenerator\CLOCK_OFFSET_COUNTER, Wikimedia\UUID\GlobalIdGenerator\getTimeAndDelay(), and Wikimedia\UUID\GlobalIdGenerator\getTimestampedID88().
Wikimedia\UUID\GlobalIdGenerator::newUUIDv1 | ( | ) |
Return an RFC4122 compliant v1 UUID.
RuntimeException |
Definition at line 207 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\getTimeAndDelay(), and Wikimedia\UUID\GlobalIdGenerator\getUUIDv1().
Referenced by Wikimedia\UUID\GlobalIdGenerator\newRawUUIDv1().
Wikimedia\UUID\GlobalIdGenerator::newUUIDv4 | ( | ) |
Return an RFC4122 compliant v4 UUID.
RuntimeException |
Definition at line 275 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\newRawUUIDv4().
|
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 573 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimeAndDelay().
Wikimedia\UUID\GlobalIdGenerator::unitTestTearDown | ( | ) |
Cleanup resources when tearing down after a unit test (T46850)
This is a cleanup method primarily meant to be used from unit tests to avoid polluting 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 742 of file GlobalIdGenerator.php.
References Wikimedia\UUID\GlobalIdGenerator\deleteCacheFiles().
|
protected |
Cached file handles.
Definition at line 57 of file GlobalIdGenerator.php.
|
protected |
Whether initialization completed.
Definition at line 48 of file GlobalIdGenerator.php.
|
protected |
Local file path.
Definition at line 52 of file GlobalIdGenerator.php.
|
protected |
Local file path.
Definition at line 50 of file GlobalIdGenerator.php.
|
protected |
Local file path.
Definition at line 54 of file GlobalIdGenerator.php.
|
protected |
Node ID in binary (32 bits)
Definition at line 43 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getNodeId32().
|
protected |
Node ID in binary (48 bits)
Definition at line 45 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getNodeId48().
|
protected |
Local file path.
Definition at line 41 of file GlobalIdGenerator.php.
|
protected |
Callback for running shell commands.
Definition at line 36 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\__construct().
|
protected |
Temporary directory.
Definition at line 39 of file GlobalIdGenerator.php.
|
private |
Key used in the serialized clock state map that is stored on disk.
Definition at line 71 of file GlobalIdGenerator.php.
|
private |
Key used in the serialized clock state map that is stored on disk.
Definition at line 75 of file GlobalIdGenerator.php.
|
private |
Key used in the serialized clock state map that is stored on disk.
Definition at line 77 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128(), Wikimedia\UUID\GlobalIdGenerator\getTimestampedID88(), Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID128(), and Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID88().
|
private |
Key used in the serialized clock state map that is stored on disk.
Definition at line 73 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128().
|
private |
Key used in the serialized clock state map that is stored on disk.
Definition at line 69 of file GlobalIdGenerator.php.
Referenced by Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128(), and Wikimedia\UUID\GlobalIdGenerator\getTimestampedID88().
|
private |
Avoid using CLASS so namespace separators aren't interpreted as path components on Windows (T259693)
Definition at line 66 of file GlobalIdGenerator.php.