MediaWiki  REL1_22
UIDGenerator Class Reference

Class for getting statistically unique IDs. More...

Collaboration diagram for UIDGenerator:

List of all members.

Public Member Functions

 __destruct ()

Static Public Member Functions

static newRawUUIDv4 ($flags=0)
 Return an RFC4122 compliant v4 UUID.
static newTimestampedUID128 ($base=10)
 Get a statistically unique 128-bit unsigned integer ID string.
static newTimestampedUID88 ($base=10)
 Get a statistically unique 88-bit unsigned integer ID string.
static newUUIDv4 ($flags=0)
 Return an RFC4122 compliant v4 UUID.

Public Attributes

const QUICK_RAND = 1

Protected Member Functions

 __construct ()
 getTimestampAndDelay ($lockFile, $clockSeqSize, $counterSize)
 Get a (time,counter,clock sequence) where (time,counter) is higher than any previous (time,counter) value for the given clock sequence.
 getTimestampedID128 (array $info)
 getTimestampedID88 (array $info)
 millisecondsSinceEpochBinary (array $time)
 timeWaitUntil (array $time)
 Wait till the current timestamp reaches $time and return the current timestamp.

Static Protected Member Functions

static millitime ()
static singleton ()

Protected Attributes

Array $fileHandles = array()
 *
 $lockFile128
 $lockFile88
 $nodeId32
 $nodeId48

Static Protected Attributes

static $instance = null

Detailed Description

Class for getting statistically unique IDs.

Since:
1.21

Definition at line 29 of file UIDGenerator.php.


Constructor & Destructor Documentation

Definition at line 333 of file UIDGenerator.php.


Member Function Documentation

UIDGenerator::getTimestampAndDelay ( lockFile,
clockSeqSize,
counterSize 
) [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.

Parameters:
string$lockFileName of a local lock file
$clockSeqSizeinteger The number of possible clock sequence values
$counterSizeinteger The number of possible counter values
Returns:
Array (result of UIDGenerator::millitime(), counter, clock sequence)
Exceptions:
MWException

Definition at line 222 of file UIDGenerator.php.

UIDGenerator::getTimestampedID128 ( array info) [protected]
Parameters:
array$info(UIDGenerator::millitime(), counter, clock sequence)
Returns:
string 128 bits

Definition at line 157 of file UIDGenerator.php.

UIDGenerator::getTimestampedID88 ( array info) [protected]
Parameters:
array$time(UIDGenerator::millitime(), clock sequence)
Returns:
string 88 bits

Definition at line 115 of file UIDGenerator.php.

Parameters:
array$timeResult of UIDGenerator::millitime()
Returns:
string 46 MSBs of "milliseconds since epoch" in binary (rolls over in 4201)

Definition at line 315 of file UIDGenerator.php.

static UIDGenerator::millitime ( ) [static, protected]
Returns:
Array (current time in seconds, milliseconds since then)

Definition at line 328 of file UIDGenerator.php.

static UIDGenerator::newRawUUIDv4 ( flags = 0) [static]

Return an RFC4122 compliant v4 UUID.

Parameters:
$flagsinteger Bitfield (supports UIDGenerator::QUICK_RAND)
Returns:
string 32 hex characters with no hyphens
Exceptions:
MWException

Definition at line 207 of file UIDGenerator.php.

Referenced by UIDGeneratorTest\testRawUUIDv4(), and UIDGeneratorTest\testRawUUIDv4QuickRand().

static UIDGenerator::newTimestampedUID128 ( base = 10) [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).

Parameters:
$baseinteger Specifies a base other than 10
Returns:
string Number
Exceptions:
MWException

Definition at line 144 of file UIDGenerator.php.

Referenced by ExternalStoreMwstore\store().

static UIDGenerator::newTimestampedUID88 ( base = 10) [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).

Parameters:
$baseinteger Specifies a base other than 10
Returns:
string Number
Exceptions:
MWException

Definition at line 102 of file UIDGenerator.php.

static UIDGenerator::newUUIDv4 ( flags = 0) [static]

Return an RFC4122 compliant v4 UUID.

Parameters:
$flagsinteger Bitfield (supports UIDGenerator::QUICK_RAND)
Returns:
string
Exceptions:
MWException

Definition at line 181 of file UIDGenerator.php.

Referenced by UIDGeneratorTest\testUUIDv4().

static UIDGenerator::singleton ( ) [static, protected]
Returns:
UIDGenerator

Definition at line 80 of file UIDGenerator.php.

UIDGenerator::timeWaitUntil ( array time) [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.

Parameters:
array$timeResult of UIDGenerator::millitime()
Returns:
Array|bool UIDGenerator::millitime() result or false

Definition at line 300 of file UIDGenerator.php.


Member Data Documentation

Array UIDGenerator::$fileHandles = array() [protected]

*

Definition at line 39 of file UIDGenerator.php.

UIDGenerator::$instance = null [static, protected]

Definition at line 31 of file UIDGenerator.php.

UIDGenerator::$lockFile128 [protected]

Definition at line 37 of file UIDGenerator.php.

UIDGenerator::$lockFile88 [protected]

Definition at line 36 of file UIDGenerator.php.

UIDGenerator::$nodeId32 [protected]

Definition at line 33 of file UIDGenerator.php.

UIDGenerator::$nodeId48 [protected]

Definition at line 34 of file UIDGenerator.php.

Definition at line 41 of file UIDGenerator.php.

Referenced by UIDGeneratorTest\testRawUUIDv4QuickRand().


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