[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/utils/ -> UIDGenerator.php (summary)

This file deals with UID generation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Author: Aaron Schulz
File Size: 507 lines (19 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class

UIDGenerator:: (18 methods):
  __construct()
  singleton()
  newTimestampedUID88()
  getTimestampedID88()
  newTimestampedUID128()
  getTimestampedID128()
  newUUIDv4()
  newRawUUIDv4()
  newSequentialPerNodeID()
  newSequentialPerNodeIDs()
  getSequentialPerNodeIDs()
  getTimestampAndDelay()
  timeWaitUntil()
  millisecondsSinceEpochBinary()
  millitime()
  deleteCacheFiles()
  unitTestTearDown()
  __destruct()


Class: UIDGenerator  - X-Ref

Class for getting statistically unique IDs

__construct()   X-Ref
No description

singleton()   X-Ref

return: UIDGenerator

newTimestampedUID88( $base = 10 )   X-Ref
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).

param: int $base Specifies a base other than 10
return: string Number

getTimestampedID88( array $info )   X-Ref

param: array $info (UIDGenerator::millitime(), counter, clock sequence)
return: string 88 bits

newTimestampedUID128( $base = 10 )   X-Ref
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).

param: int $base Specifies a base other than 10
return: string Number

getTimestampedID128( array $info )   X-Ref

param: array $info (UIDGenerator::millitime(), counter, clock sequence)
return: string 128 bits

newUUIDv4( $flags = 0 )   X-Ref
Return an RFC4122 compliant v4 UUID

param: int $flags Bitfield (supports UIDGenerator::QUICK_RAND)
return: string

newRawUUIDv4( $flags = 0 )   X-Ref
Return an RFC4122 compliant v4 UUID

param: int $flags Bitfield (supports UIDGenerator::QUICK_RAND)
return: string 32 hex characters with no hyphens

newSequentialPerNodeID( $bucket, $bits = 48, $flags = 0 )   X-Ref
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.

param: string $bucket Arbitrary bucket name (should be ASCII)
param: int $bits Bit size (<=48) of resulting numbers before wrap-around
param: int $flags (supports UIDGenerator::QUICK_VOLATILE)
return: float Integer value as float

newSequentialPerNodeIDs( $bucket, $bits, $count, $flags = 0 )   X-Ref
Return IDs that are sequential *only* for this node and bucket

param: string $bucket Arbitrary bucket name (should be ASCII)
param: int $bits Bit size (16 to 48) of resulting numbers before wrap-around
param: int $count Number of IDs to return (1 to 10000)
param: int $flags (supports UIDGenerator::QUICK_VOLATILE)
return: array Ordered list of float integer values

getSequentialPerNodeIDs( $bucket, $bits, $count, $flags )   X-Ref
Return IDs that are sequential *only* for this node and bucket

param: string $bucket Arbitrary bucket name (should be ASCII)
param: int $bits Bit size (16 to 48) of resulting numbers before wrap-around
param: int $count Number of IDs to return (1 to 10000)
param: int $flags (supports UIDGenerator::QUICK_VOLATILE)
return: array Ordered list of float integer values

getTimestampAndDelay( $lockFile, $clockSeqSize, $counterSize )   X-Ref
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.

param: string $lockFile Name of a local lock file
param: int $clockSeqSize The number of possible clock sequence values
param: int $counterSize The number of possible counter values
return: array (result of UIDGenerator::millitime(), counter, clock sequence)

timeWaitUntil( array $time )   X-Ref
Wait till the current timestamp reaches $time and return the current
timestamp. This returns false if it would have to wait more than 10ms.

param: array $time Result of UIDGenerator::millitime()
return: array|bool UIDGenerator::millitime() result or false

millisecondsSinceEpochBinary( array $time )   X-Ref

param: array $time Result of UIDGenerator::millitime()
return: string 46 MSBs of "milliseconds since epoch" in binary (rolls over in 4201)

millitime()   X-Ref

return: array (current time in seconds, milliseconds since then)

deleteCacheFiles()   X-Ref
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.


unitTestTearDown()   X-Ref
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.


__destruct()   X-Ref
No description



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1