MediaWiki  master
GlobalIdGenerator.php
Go to the documentation of this file.
1 <?php
21 namespace Wikimedia\UUID;
22 
23 use BagOStuff;
24 use EmptyBagOStuff;
25 use InvalidArgumentException;
26 use RuntimeException;
27 use Wikimedia\Assert\Assert;
28 use Wikimedia\AtEase\AtEase;
29 use Wikimedia\Timestamp\ConvertibleTimestamp;
30 
38  protected $srvCache;
40  protected $shellCallback;
41 
43  protected $tmpDir;
45  protected $nodeIdFile;
47  protected $nodeId32;
49  protected $nodeId48;
50 
52  protected $loaded = false;
54  protected $lockFile88;
56  protected $lockFile128;
58  protected $lockFileUUID;
59 
61  protected $fileHandles = []; // cached file handles
62 
63  public const QUICK_VOLATILE = 1; // use an APC like in-memory counter if available
64 
70  public function __construct( $tempDirectory, BagOStuff $srvCache, callable $shellCallback ) {
71  if ( !strlen( $tempDirectory ) ) {
72  throw new InvalidArgumentException( "No temp directory provided" );
73  }
74  $this->tmpDir = $tempDirectory;
75  $this->nodeIdFile = $tempDirectory . '/mw-' . __CLASS__ . '-UID-nodeid';
76  // If different processes run as different users, they may have different temp dirs.
77  // This is dealt with by initializing the clock sequence number and counters randomly.
78  $this->lockFile88 = $tempDirectory . '/mw-' . __CLASS__ . '-UID-88';
79  $this->lockFile128 = $tempDirectory . '/mw-' . __CLASS__ . '-UID-128';
80  $this->lockFileUUID = $tempDirectory . '/mw-' . __CLASS__ . '-UUID-128';
81 
82  $this->srvCache = $srvCache;
83  $this->shellCallback = $shellCallback;
84  }
85 
101  public function newTimestampedUID88( $base = 10 ) {
102  Assert::parameterType( 'integer', $base, '$base' );
103  Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
104  Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
105 
106  $info = $this->getTimeAndDelay( 'lockFile88', 1, 1024, 1024 );
107  $info['offsetCounter'] = $info['offsetCounter'] % 1024;
108 
109  return \Wikimedia\base_convert( $this->getTimestampedID88( $info ), 2, $base );
110  }
111 
118  protected function getTimestampedID88( array $info ) {
119  if ( isset( $info['time'] ) ) {
120  $time = $info['time'];
121  $counter = $info['offsetCounter'];
122  } else {
123  list( $time, $counter ) = $info;
124  }
125  // Take the 46 LSBs of "milliseconds since epoch"
126  $id_bin = $this->millisecondsSinceEpochBinary( $time );
127  // Add a 10 bit counter resulting in 56 bits total
128  $id_bin .= str_pad( decbin( $counter ), 10, '0', STR_PAD_LEFT );
129  // Add the 32 bit node ID resulting in 88 bits total
130  $id_bin .= $this->getNodeId32();
131  // Convert to a 1-27 digit integer string
132  if ( strlen( $id_bin ) !== 88 ) {
133  throw new RuntimeException( "Detected overflow for millisecond timestamp." );
134  }
135 
136  return $id_bin;
137  }
138 
153  public function newTimestampedUID128( $base = 10 ) {
154  Assert::parameterType( 'integer', $base, '$base' );
155  Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
156  Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
157 
158  $info = $this->getTimeAndDelay( 'lockFile128', 16384, 1048576, 1048576 );
159  $info['offsetCounter'] = $info['offsetCounter'] % 1048576;
160 
161  return \Wikimedia\base_convert( $this->getTimestampedID128( $info ), 2, $base );
162  }
163 
170  protected function getTimestampedID128( array $info ) {
171  if ( isset( $info['time'] ) ) {
172  $time = $info['time'];
173  $counter = $info['offsetCounter'];
174  $clkSeq = $info['clkSeq'];
175  } else {
176  list( $time, $counter, $clkSeq ) = $info;
177  }
178  // Take the 46 LSBs of "milliseconds since epoch"
179  $id_bin = $this->millisecondsSinceEpochBinary( $time );
180  // Add a 20 bit counter resulting in 66 bits total
181  $id_bin .= str_pad( decbin( $counter ), 20, '0', STR_PAD_LEFT );
182  // Add a 14 bit clock sequence number resulting in 80 bits total
183  $id_bin .= str_pad( decbin( $clkSeq ), 14, '0', STR_PAD_LEFT );
184  // Add the 48 bit node ID resulting in 128 bits total
185  $id_bin .= $this->getNodeId48();
186  // Convert to a 1-39 digit integer string
187  if ( strlen( $id_bin ) !== 128 ) {
188  throw new RuntimeException( "Detected overflow for millisecond timestamp." );
189  }
190 
191  return $id_bin;
192  }
193 
200  public function newUUIDv1() {
201  // There can be up to 10000 intervals for the same millisecond timestamp.
202  // [0,4999] counter + [0,5000] offset is in [0,9999] for the offset counter.
203  // Add this onto the timestamp to allow making up to 5000 IDs per second.
204  return $this->getUUIDv1( $this->getTimeAndDelay( 'lockFileUUID', 16384, 5000, 5001 ) );
205  }
206 
211  protected function getUUIDv1( array $info ) {
212  $clkSeq_bin = \Wikimedia\base_convert( $info['clkSeq'], 10, 2, 14 );
213  $time_bin = $this->intervalsSinceGregorianBinary( $info['time'], $info['offsetCounter'] );
214  // Take the 32 bits of "time low"
215  $id_bin = substr( $time_bin, 28, 32 );
216  // Add 16 bits of "time mid" resulting in 48 bits total
217  $id_bin .= substr( $time_bin, 12, 16 );
218  // Add 4 bit version resulting in 52 bits total
219  $id_bin .= '0001';
220  // Add 12 bits of "time high" resulting in 64 bits total
221  $id_bin .= substr( $time_bin, 0, 12 );
222  // Add 2 bits of "variant" resulting in 66 bits total
223  $id_bin .= '10';
224  // Add 6 bits of "clock seq high" resulting in 72 bits total
225  $id_bin .= substr( $clkSeq_bin, 0, 6 );
226  // Add 8 bits of "clock seq low" resulting in 80 bits total
227  $id_bin .= substr( $clkSeq_bin, 6, 8 );
228  // Add the 48 bit node ID resulting in 128 bits total
229  $id_bin .= $this->getNodeId48();
230  // Convert to a 32 char hex string with dashes
231  if ( strlen( $id_bin ) !== 128 ) {
232  throw new RuntimeException( "Detected overflow for millisecond timestamp." );
233  }
234  $hex = \Wikimedia\base_convert( $id_bin, 2, 16, 32 );
235  return sprintf( '%s-%s-%s-%s-%s',
236  // "time_low" (32 bits)
237  substr( $hex, 0, 8 ),
238  // "time_mid" (16 bits)
239  substr( $hex, 8, 4 ),
240  // "time_hi_and_version" (16 bits)
241  substr( $hex, 12, 4 ),
242  // "clk_seq_hi_res" (8 bits) and "clk_seq_low" (8 bits)
243  substr( $hex, 16, 4 ),
244  // "node" (48 bits)
245  substr( $hex, 20, 12 )
246  );
247  }
248 
255  public function newRawUUIDv1() {
256  return str_replace( '-', '', $this->newUUIDv1() );
257  }
258 
265  public function newUUIDv4() {
266  $hex = bin2hex( random_bytes( 32 / 2 ) );
267 
268  return sprintf( '%s-%s-%s-%s-%s',
269  // "time_low" (32 bits)
270  substr( $hex, 0, 8 ),
271  // "time_mid" (16 bits)
272  substr( $hex, 8, 4 ),
273  // "time_hi_and_version" (16 bits)
274  '4' . substr( $hex, 12, 3 ),
275  // "clk_seq_hi_res" (8 bits, variant is binary 10x) and "clk_seq_low" (8 bits)
276  dechex( 0x8 | ( hexdec( $hex[15] ) & 0x3 ) ) . $hex[16] . substr( $hex, 17, 2 ),
277  // "node" (48 bits)
278  substr( $hex, 19, 12 )
279  );
280  }
281 
288  public function newRawUUIDv4() {
289  return str_replace( '-', '', $this->newUUIDv4() );
290  }
291 
304  public function newSequentialPerNodeID( $bucket, $bits = 48, $flags = 0 ) {
305  return current( $this->newSequentialPerNodeIDs( $bucket, $bits, 1, $flags ) );
306  }
307 
318  public function newSequentialPerNodeIDs( $bucket, $bits, $count, $flags = 0 ) {
319  return $this->getSequentialPerNodeIDs( $bucket, $bits, $count, $flags );
320  }
321 
329  public function getTimestampFromUUIDv1( string $uuid, int $format = TS_MW ) {
330  $components = [];
331  if ( !preg_match(
332  '/^([0-9a-f]{8})-([0-9a-f]{4})-(1[0-9a-f]{3})-([89ab][0-9a-f]{3})-([0-9a-f]{12})$/',
333  $uuid,
334  $components
335  ) ) {
336  throw new InvalidArgumentException( "Invalid UUIDv1 {$uuid}" );
337  }
338 
339  $timestamp = hexdec( substr( $components[3], 1 ) . $components[2] . $components[1] );
340  // The 60 bit timestamp value is constructed from fields of this UUID.
341  // The timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.
342  $unixTime = ( $timestamp - 0x01b21dd213814000 ) / 1e7;
343 
344  return ConvertibleTimestamp::convert( $format, $unixTime );
345  }
346 
358  protected function getSequentialPerNodeIDs( $bucket, $bits, $count, $flags ) {
359  if ( $count <= 0 ) {
360  return []; // nothing to do
361  }
362  if ( $bits < 16 || $bits > 48 ) {
363  throw new RuntimeException( "Requested bit size ($bits) is out of range." );
364  }
365 
366  $counter = null; // post-increment persistent counter value
367 
368  // Use APC/etc if requested, available, and not in CLI mode;
369  // Counter values would not survive across script instances in CLI mode.
370  if (
371  ( $flags & self::QUICK_VOLATILE ) &&
372  !( $this->srvCache instanceof EmptyBagOStuff )
373  ) {
375  $counter = $cache->incrWithInit( $bucket, $cache::TTL_INDEFINITE, $count, $count );
376  if ( $counter === false ) {
377  throw new RuntimeException( 'Unable to set value to ' . get_class( $cache ) );
378  }
379  }
380 
381  // Note: use of fmod() avoids "division by zero" on 32 bit machines
382  if ( $counter === null ) {
383  $path = $this->tmpDir . '/mw-' . __CLASS__ . '-' . rawurlencode( $bucket ) . '-48';
384  // Get the UID lock file handle
385  if ( isset( $this->fileHandles[$path] ) ) {
386  $handle = $this->fileHandles[$path];
387  } else {
388  $handle = fopen( $path, 'cb+' );
389  $this->fileHandles[$path] = $handle ?: null; // cache
390  }
391  // Acquire the UID lock file
392  if ( $handle === false ) {
393  throw new RuntimeException( "Could not open '{$path}'." );
394  }
395  if ( !flock( $handle, LOCK_EX ) ) {
396  fclose( $handle );
397  throw new RuntimeException( "Could not acquire '{$path}'." );
398  }
399  // Fetch the counter value and increment it...
400  rewind( $handle );
401  $counter = floor( (float)trim( fgets( $handle ) ) ) + $count; // fetch as float
402  // Write back the new counter value
403  ftruncate( $handle, 0 );
404  rewind( $handle );
405  fwrite( $handle, fmod( $counter, 2 ** 48 ) ); // warp-around as needed
406  fflush( $handle );
407  // Release the UID lock file
408  flock( $handle, LOCK_UN );
409  }
410 
411  $ids = [];
412  $divisor = 2 ** $bits;
413  $currentId = floor( $counter - $count ); // pre-increment counter value
414  for ( $i = 0; $i < $count; ++$i ) {
415  $ids[] = fmod( ++$currentId, $divisor );
416  }
417 
418  return $ids;
419  }
420 
438  protected function getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize ) {
439  // Get the UID lock file handle
440  if ( isset( $this->fileHandles[$lockFile] ) ) {
441  $handle = $this->fileHandles[$lockFile];
442  } else {
443  $handle = fopen( $this->$lockFile, 'cb+' );
444  $this->fileHandles[$lockFile] = $handle ?: null; // cache
445  }
446  // Acquire the UID lock file
447  if ( $handle === false ) {
448  throw new RuntimeException( "Could not open '{$this->$lockFile}'." );
449  }
450  if ( !flock( $handle, LOCK_EX ) ) {
451  fclose( $handle );
452  throw new RuntimeException( "Could not acquire '{$this->$lockFile}'." );
453  }
454 
455  // The formatters that use this method expect a timestamp with millisecond
456  // precision and a counter upto a certain size. When more IDs than the counter
457  // size are generated during the same timestamp, an exception is thrown as we
458  // cannot increment further, because the formatted ID would not have enough
459  // bits to fit the counter.
460  //
461  // To orchestrate this between independant PHP processes on the same hosts,
462  // we must have a common sense of time so that we only have to maintain
463  // a single counter in a single lock file.
464  //
465  // Given that:
466  // * The system clock can be observed via time(), without milliseconds.
467  // * Some other clock can be observed via microtime(), which also offers
468  // millisecond precision.
469  // * microtime() drifts in-process further and further away from the system
470  // clock the longer the longer the process runs for.
471  // For example, on 2018-10-03 an HHVM 3.18 JobQueue process at WMF,
472  // that ran for 9 min 55 sec, drifted 7 seconds.
473  // The drift is immediate for processes running while the system clock changes.
474  // time() does not have this problem. See https://bugs.php.net/bug.php?id=42659.
475  //
476  // We have two choices:
477  //
478  // 1. Use microtime() with the following caveats:
479  // - The last stored time may be in the future, or our current time
480  // may be in the past, in which case we'll frequently enter the slow
481  // timeWaitUntil() method to try and "sync" the current process with
482  // the previous process. We mustn't block for long though, max 10ms?
483  // - For any drift above 10ms, we pretend that the clock went backwards,
484  // and treat it the same way as after an NTP sync, by incrementing clock
485  // sequence instead. Given this rolls over automatically and silently
486  // and is meant to be rare, this is essentially sacrifices a reasonable
487  // guarantee of uniqueness.
488  // - For long running processes (e.g. longer than a few seconds) the drift
489  // can easily be more than 2 seconds. Because we only have a single lock
490  // file and don't want to keep too many counters and deal with clearing
491  // those, we fatal the user and refuse to make an ID. (T94522)
492  // 2. Use time() and expand the counter by 1000x and use the first digits
493  // as if they are the millisecond fraction of the timestamp.
494  // Known caveats or perf impact: None.
495  //
496  // We choose the latter.
497  $msecCounterSize = $counterSize * 1000;
498 
499  rewind( $handle );
500  // Format of lock file contents:
501  // "<clk seq> <sec> <msec counter> <rand offset>"
502  $data = explode( ' ', fgets( $handle ) );
503 
504  if ( count( $data ) === 4 ) {
505  // The UID lock file was already initialized
506  $clkSeq = (int)$data[0] % $clockSeqSize;
507  $prevSec = (int)$data[1];
508  // Counter for UIDs with the same timestamp,
509  $msecCounter = 0;
510  $randOffset = (int)$data[3] % $counterSize;
511 
512  // If the system clock moved backwards by an NTP sync,
513  // or if the last writer process had its clock drift ahead,
514  // Try to catch up if the gap is small, so that we can keep a single
515  // monotonic logic file.
516  $sec = $this->timeWaitUntil( $prevSec );
517  if ( $sec === false ) {
518  // Gap is too big. Looks like the clock got moved back significantly.
519  // Start a new clock sequence, and re-randomize the extra offset,
520  // which is useful for UIDs that do not include the clock sequence number.
521  $clkSeq = ( $clkSeq + 1 ) % $clockSeqSize;
522  $sec = time();
523  $randOffset = mt_rand( 0, $offsetSize - 1 );
524  trigger_error( "Clock was set back; sequence number incremented." );
525  } elseif ( $sec === $prevSec ) {
526  // Sanity check, only keep remainder if a previous writer wrote
527  // something here that we don't accept.
528  $msecCounter = (int)$data[2] % $msecCounterSize;
529  // Bump the counter if the time has not changed yet
530  if ( ++$msecCounter >= $msecCounterSize ) {
531  // More IDs generated with the same time than counterSize can accomodate
532  flock( $handle, LOCK_UN );
533  throw new RuntimeException( "Counter overflow for timestamp value." );
534  }
535  }
536  } else {
537  // Initialize UID lock file information
538  $clkSeq = mt_rand( 0, $clockSeqSize - 1 );
539  $sec = time();
540  $msecCounter = 0;
541  $randOffset = mt_rand( 0, $offsetSize - 1 );
542  }
543 
544  // Update and release the UID lock file
545  ftruncate( $handle, 0 );
546  rewind( $handle );
547  fwrite( $handle, "{$clkSeq} {$sec} {$msecCounter} {$randOffset}" );
548  fflush( $handle );
549  flock( $handle, LOCK_UN );
550 
551  // Split msecCounter back into msec and counter
552  $msec = (int)( $msecCounter / 1000 );
553  $counter = $msecCounter % 1000;
554 
555  return [
556  'time' => [ $sec, $msec ],
557  'counter' => $counter,
558  'clkSeq' => $clkSeq,
559  'offset' => $randOffset,
560  'offsetCounter' => $counter + $randOffset,
561  ];
562  }
563 
571  protected function timeWaitUntil( $time ) {
572  $start = microtime( true );
573  do {
574  $ct = time();
575  // https://www.php.net/manual/en/language.operators.comparison.php
576  if ( $ct >= $time ) {
577  // current time is higher than or equal to than $time
578  return $ct;
579  }
580  } while ( ( microtime( true ) - $start ) <= 0.010 ); // up to 10ms
581 
582  return false;
583  }
584 
590  protected function millisecondsSinceEpochBinary( array $time ) {
591  list( $sec, $msec ) = $time;
592  $ts = 1000 * $sec + $msec;
593  if ( $ts > 2 ** 52 ) {
594  throw new RuntimeException( __METHOD__ .
595  ': sorry, this function doesn\'t work after the year 144680' );
596  }
597 
598  return substr( \Wikimedia\base_convert( $ts, 10, 2, 46 ), -46 );
599  }
600 
607  protected function intervalsSinceGregorianBinary( array $time, $delta = 0 ) {
608  list( $sec, $msec ) = $time;
609  $offset = '122192928000000000';
610  if ( PHP_INT_SIZE >= 8 ) { // 64 bit integers
611  $ts = ( 1000 * $sec + $msec ) * 10000 + (int)$offset + $delta;
612  $id_bin = str_pad( decbin( $ts % ( 2 ** 60 ) ), 60, '0', STR_PAD_LEFT );
613  } elseif ( extension_loaded( 'gmp' ) ) {
614  $ts = gmp_add( gmp_mul( (string)$sec, '1000' ), (string)$msec ); // ms
615  $ts = gmp_add( gmp_mul( $ts, '10000' ), $offset ); // 100ns intervals
616  $ts = gmp_add( $ts, (string)$delta );
617  $ts = gmp_mod( $ts, gmp_pow( '2', '60' ) ); // wrap around
618  $id_bin = str_pad( gmp_strval( $ts, 2 ), 60, '0', STR_PAD_LEFT );
619  } elseif ( extension_loaded( 'bcmath' ) ) {
620  $ts = bcadd( bcmul( $sec, 1000 ), $msec ); // ms
621  $ts = bcadd( bcmul( $ts, 10000 ), $offset ); // 100ns intervals
622  $ts = bcadd( $ts, $delta );
623  $ts = bcmod( $ts, bcpow( 2, 60 ) ); // wrap around
624  $id_bin = \Wikimedia\base_convert( $ts, 10, 2, 60 );
625  } else {
626  throw new RuntimeException( 'bcmath or gmp extension required for 32 bit machines.' );
627  }
628  return $id_bin;
629  }
630 
634  private function load() {
635  if ( $this->loaded ) {
636  return; // already called
637  }
638 
639  $this->loaded = true;
640 
641  $nodeId = '';
642  if ( is_file( $this->nodeIdFile ) ) {
643  $nodeId = file_get_contents( $this->nodeIdFile );
644  }
645  // Try to get some ID that uniquely identifies this machine (RFC 4122)...
646  if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
647  AtEase::suppressWarnings();
648  if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
649  // https://technet.microsoft.com/en-us/library/bb490913.aspx
650  $csv = trim( ( $this->shellCallback )( 'getmac /NH /FO CSV' ) );
651  $line = substr( $csv, 0, strcspn( $csv, "\n" ) );
652  $info = str_getcsv( $line );
653  $nodeId = isset( $info[0] ) ? str_replace( '-', '', $info[0] ) : '';
654  } elseif ( is_executable( '/sbin/ifconfig' ) ) { // Linux/BSD/Solaris/OS X
655  // See https://linux.die.net/man/8/ifconfig
656  $m = [];
657  preg_match( '/\s([0-9a-f]{2}(?::[0-9a-f]{2}){5})\s/',
658  ( $this->shellCallback )( '/sbin/ifconfig -a' ), $m );
659  $nodeId = isset( $m[1] ) ? str_replace( ':', '', $m[1] ) : '';
660  }
661  AtEase::restoreWarnings();
662  if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
663  $nodeId = bin2hex( random_bytes( 12 / 2 ) );
664  $nodeId[1] = dechex( hexdec( $nodeId[1] ) | 0x1 ); // set multicast bit
665  }
666  file_put_contents( $this->nodeIdFile, $nodeId ); // cache
667  }
668  $this->nodeId32 = \Wikimedia\base_convert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
669  $this->nodeId48 = \Wikimedia\base_convert( $nodeId, 16, 2, 48 );
670  }
671 
675  private function getNodeId32() {
676  $this->load();
677 
678  return $this->nodeId32;
679  }
680 
684  private function getNodeId48() {
685  $this->load();
686 
687  return $this->nodeId48;
688  }
689 
701  private function deleteCacheFiles() {
702  foreach ( $this->fileHandles as $path => $handle ) {
703  if ( $handle !== null ) {
704  fclose( $handle );
705  }
706  if ( is_file( $path ) ) {
707  unlink( $path );
708  }
709  unset( $this->fileHandles[$path] );
710  }
711  if ( is_file( $this->nodeIdFile ) ) {
712  unlink( $this->nodeIdFile );
713  }
714  }
715 
728  public function unitTestTearDown() {
729  $this->deleteCacheFiles();
730  }
731 
732  public function __destruct() {
733  array_map( 'fclose', array_filter( $this->fileHandles ) );
734  }
735 }
Wikimedia\UUID\GlobalIdGenerator\$fileHandles
array $fileHandles
Cached file handles.
Definition: GlobalIdGenerator.php:61
Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID128
newTimestampedUID128( $base=10)
Get a statistically unique 128-bit unsigned integer ID string.
Definition: GlobalIdGenerator.php:153
Wikimedia\UUID\GlobalIdGenerator\$lockFileUUID
string $lockFileUUID
Local file path.
Definition: GlobalIdGenerator.php:58
Wikimedia\UUID\GlobalIdGenerator
Class for getting statistically unique IDs without a central coordinator.
Definition: GlobalIdGenerator.php:36
Wikimedia\UUID\GlobalIdGenerator\newUUIDv1
newUUIDv1()
Return an RFC4122 compliant v1 UUID.
Definition: GlobalIdGenerator.php:200
EmptyBagOStuff
A BagOStuff object with no objects in it.
Definition: EmptyBagOStuff.php:29
Wikimedia\UUID\GlobalIdGenerator\timeWaitUntil
timeWaitUntil( $time)
Wait till the current timestamp reaches $time and return the current timestamp.
Definition: GlobalIdGenerator.php:571
Wikimedia\UUID\GlobalIdGenerator\getTimeAndDelay
getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize)
Get a (time,counter,clock sequence) where (time,counter) is higher than any previous (time,...
Definition: GlobalIdGenerator.php:438
Wikimedia\UUID\GlobalIdGenerator\__destruct
__destruct()
Definition: GlobalIdGenerator.php:732
Wikimedia\UUID\GlobalIdGenerator\deleteCacheFiles
deleteCacheFiles()
Delete all cache files that have been created (T46850)
Definition: GlobalIdGenerator.php:701
Wikimedia\UUID
Definition: GlobalIdGenerator.php:21
Wikimedia\UUID\GlobalIdGenerator\$lockFile128
string $lockFile128
Local file path.
Definition: GlobalIdGenerator.php:56
Wikimedia\UUID\GlobalIdGenerator\getUUIDv1
getUUIDv1(array $info)
Definition: GlobalIdGenerator.php:211
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:70
Wikimedia\UUID\GlobalIdGenerator\$shellCallback
callable $shellCallback
Callback for running shell commands.
Definition: GlobalIdGenerator.php:40
Wikimedia\UUID\GlobalIdGenerator\getSequentialPerNodeIDs
getSequentialPerNodeIDs( $bucket, $bits, $count, $flags)
Return IDs that are sequential only for this node and bucket.
Definition: GlobalIdGenerator.php:358
Wikimedia\UUID\GlobalIdGenerator\__construct
__construct( $tempDirectory, BagOStuff $srvCache, callable $shellCallback)
Definition: GlobalIdGenerator.php:70
Wikimedia\UUID\GlobalIdGenerator\$lockFile88
string $lockFile88
Local file path.
Definition: GlobalIdGenerator.php:54
$base
$base
Definition: generateLocalAutoload.php:11
Wikimedia\UUID\GlobalIdGenerator\intervalsSinceGregorianBinary
intervalsSinceGregorianBinary(array $time, $delta=0)
Definition: GlobalIdGenerator.php:607
Wikimedia\UUID\GlobalIdGenerator\newUUIDv4
newUUIDv4()
Return an RFC4122 compliant v4 UUID.
Definition: GlobalIdGenerator.php:265
Wikimedia\UUID\GlobalIdGenerator\getTimestampedID88
getTimestampedID88(array $info)
Definition: GlobalIdGenerator.php:118
Wikimedia\UUID\GlobalIdGenerator\$nodeId48
string $nodeId48
Node ID in binary (48 bits)
Definition: GlobalIdGenerator.php:49
Wikimedia\UUID\GlobalIdGenerator\$tmpDir
string $tmpDir
Temporary directory.
Definition: GlobalIdGenerator.php:43
Wikimedia\UUID\GlobalIdGenerator\getNodeId48
getNodeId48()
Definition: GlobalIdGenerator.php:684
Wikimedia\UUID\GlobalIdGenerator\newRawUUIDv4
newRawUUIDv4()
Return an RFC4122 compliant v4 UUID.
Definition: GlobalIdGenerator.php:288
Wikimedia\UUID\GlobalIdGenerator\newSequentialPerNodeID
newSequentialPerNodeID( $bucket, $bits=48, $flags=0)
Return an ID that is sequential only for this node and bucket.
Definition: GlobalIdGenerator.php:304
Wikimedia\UUID\GlobalIdGenerator\newTimestampedUID88
newTimestampedUID88( $base=10)
Get a statistically unique 88-bit unsigned integer ID string.
Definition: GlobalIdGenerator.php:101
Wikimedia\UUID\GlobalIdGenerator\getNodeId32
getNodeId32()
Definition: GlobalIdGenerator.php:675
Wikimedia\UUID\GlobalIdGenerator\getTimestampedID128
getTimestampedID128(array $info)
Definition: GlobalIdGenerator.php:170
$line
$line
Definition: mcc.php:119
Wikimedia\UUID\GlobalIdGenerator\QUICK_VOLATILE
const QUICK_VOLATILE
Definition: GlobalIdGenerator.php:63
Wikimedia\UUID\GlobalIdGenerator\$loaded
bool $loaded
Whether initialization completed.
Definition: GlobalIdGenerator.php:52
Wikimedia\UUID\GlobalIdGenerator\$srvCache
BagOStuff $srvCache
Server-local persistent cache instance.
Definition: GlobalIdGenerator.php:38
Wikimedia\UUID\GlobalIdGenerator\unitTestTearDown
unitTestTearDown()
Cleanup resources when tearing down after a unit test (T46850)
Definition: GlobalIdGenerator.php:728
Wikimedia\UUID\GlobalIdGenerator\load
load()
Load the node ID information.
Definition: GlobalIdGenerator.php:634
$cache
$cache
Definition: mcc.php:33
Wikimedia\UUID\GlobalIdGenerator\$nodeIdFile
string $nodeIdFile
Local file path.
Definition: GlobalIdGenerator.php:45
$path
$path
Definition: NoLocalSettings.php:25
Wikimedia
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Wikimedia\UUID\GlobalIdGenerator\newRawUUIDv1
newRawUUIDv1()
Return an RFC4122 compliant v1 UUID.
Definition: GlobalIdGenerator.php:255
Wikimedia\UUID\GlobalIdGenerator\newSequentialPerNodeIDs
newSequentialPerNodeIDs( $bucket, $bits, $count, $flags=0)
Return IDs that are sequential only for this node and bucket.
Definition: GlobalIdGenerator.php:318
Wikimedia\UUID\GlobalIdGenerator\$nodeId32
string $nodeId32
Node ID in binary (32 bits)
Definition: GlobalIdGenerator.php:47
Wikimedia\UUID\GlobalIdGenerator\millisecondsSinceEpochBinary
millisecondsSinceEpochBinary(array $time)
Definition: GlobalIdGenerator.php:590
Wikimedia\UUID\GlobalIdGenerator\getTimestampFromUUIDv1
getTimestampFromUUIDv1(string $uuid, int $format=TS_MW)
Get timestamp in a specified format from UUIDv1.
Definition: GlobalIdGenerator.php:329