MediaWiki  master
GlobalIdGenerator.php
Go to the documentation of this file.
1 <?php
21 namespace Wikimedia\UUID;
22 
23 use InvalidArgumentException;
24 use RuntimeException;
25 use Wikimedia\Assert\Assert;
26 use Wikimedia\AtEase\AtEase;
27 use Wikimedia\Timestamp\ConvertibleTimestamp;
28 
36  protected $shellCallback;
37 
39  protected $tmpDir;
41  protected $nodeIdFile;
43  protected $nodeId32;
45  protected $nodeId48;
46 
48  protected $loaded = false;
50  protected $lockFile88;
52  protected $lockFile128;
54  protected $lockFileUUID;
55 
57  protected $fileHandles = [];
58 
60  public const QUICK_VOLATILE = 1;
61 
66  private const FILE_PREFIX = 'mw-GlobalIdGenerator';
67 
69  private const CLOCK_TIME = 'time';
71  private const CLOCK_COUNTER = 'counter';
73  private const CLOCK_SEQUENCE = 'clkSeq';
75  private const CLOCK_OFFSET = 'offset';
77  private const CLOCK_OFFSET_COUNTER = 'offsetCounter';
78 
83  public function __construct( $tempDirectory, $shellCallback ) {
84  if ( func_num_args() >= 3 && !is_callable( $shellCallback ) ) {
85  trigger_error(
86  __CLASS__ . ' with a BagOStuff instance was deprecated in MediaWiki 1.37.',
87  E_USER_DEPRECATED
88  );
89  $shellCallback = func_get_arg( 2 );
90  }
91  if ( !strlen( $tempDirectory ) ) {
92  throw new InvalidArgumentException( "No temp directory provided" );
93  }
94  $this->tmpDir = $tempDirectory;
95  $this->nodeIdFile = $tempDirectory . '/' . self::FILE_PREFIX . '-UID-nodeid';
96  // If different processes run as different users, they may have different temp dirs.
97  // This is dealt with by initializing the clock sequence number and counters randomly.
98  $this->lockFile88 = $tempDirectory . '/' . self::FILE_PREFIX . '-UID-88';
99  $this->lockFile128 = $tempDirectory . '/' . self::FILE_PREFIX . '-UID-128';
100  $this->lockFileUUID = $tempDirectory . '/' . self::FILE_PREFIX . '-UUID-128';
101 
102  $this->shellCallback = $shellCallback;
103  }
104 
120  public function newTimestampedUID88( int $base = 10 ) {
121  Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
122  Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
123 
124  $info = $this->getTimeAndDelay( 'lockFile88', 1, 1024, 1024 );
125  $info[self::CLOCK_OFFSET_COUNTER] %= 1024;
126 
127  return \Wikimedia\base_convert( $this->getTimestampedID88( $info ), 2, $base );
128  }
129 
135  protected function getTimestampedID88( array $info ) {
136  $time = $info[self::CLOCK_TIME];
137  $counter = $info[self::CLOCK_OFFSET_COUNTER];
138  // Take the 46 LSBs of "milliseconds since epoch"
139  $id_bin = $this->millisecondsSinceEpochBinary( $time );
140  // Add a 10 bit counter resulting in 56 bits total
141  $id_bin .= str_pad( decbin( $counter ), 10, '0', STR_PAD_LEFT );
142  // Add the 32 bit node ID resulting in 88 bits total
143  $id_bin .= $this->getNodeId32();
144  // Convert to a 1-27 digit integer string
145  if ( strlen( $id_bin ) !== 88 ) {
146  throw new RuntimeException( "Detected overflow for millisecond timestamp." );
147  }
148 
149  return $id_bin;
150  }
151 
166  public function newTimestampedUID128( int $base = 10 ) {
167  Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
168  Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
169 
170  $info = $this->getTimeAndDelay( 'lockFile128', 16384, 1048576, 1048576 );
171  $info[self::CLOCK_OFFSET_COUNTER] %= 1048576;
172 
173  return \Wikimedia\base_convert( $this->getTimestampedID128( $info ), 2, $base );
174  }
175 
181  protected function getTimestampedID128( array $info ) {
182  $time = $info[self::CLOCK_TIME];
183  $counter = $info[self::CLOCK_OFFSET_COUNTER];
184  $clkSeq = $info[self::CLOCK_SEQUENCE];
185  // Take the 46 LSBs of "milliseconds since epoch"
186  $id_bin = $this->millisecondsSinceEpochBinary( $time );
187  // Add a 20 bit counter resulting in 66 bits total
188  $id_bin .= str_pad( decbin( $counter ), 20, '0', STR_PAD_LEFT );
189  // Add a 14 bit clock sequence number resulting in 80 bits total
190  $id_bin .= str_pad( decbin( $clkSeq ), 14, '0', STR_PAD_LEFT );
191  // Add the 48 bit node ID resulting in 128 bits total
192  $id_bin .= $this->getNodeId48();
193  // Convert to a 1-39 digit integer string
194  if ( strlen( $id_bin ) !== 128 ) {
195  throw new RuntimeException( "Detected overflow for millisecond timestamp." );
196  }
197 
198  return $id_bin;
199  }
200 
207  public function newUUIDv1() {
208  // There can be up to 10000 intervals for the same millisecond timestamp.
209  // [0,4999] counter + [0,5000] offset is in [0,9999] for the offset counter.
210  // Add this onto the timestamp to allow making up to 5000 IDs per second.
211  return $this->getUUIDv1( $this->getTimeAndDelay( 'lockFileUUID', 16384, 5000, 5001 ) );
212  }
213 
218  protected function getUUIDv1( array $info ) {
219  $clkSeq_bin = \Wikimedia\base_convert( $info[self::CLOCK_SEQUENCE], 10, 2, 14 );
220  $time_bin = $this->intervalsSinceGregorianBinary(
221  $info[self::CLOCK_TIME],
222  $info[self::CLOCK_OFFSET_COUNTER]
223  );
224  // Take the 32 bits of "time low"
225  $id_bin = substr( $time_bin, 28, 32 );
226  // Add 16 bits of "time mid" resulting in 48 bits total
227  $id_bin .= substr( $time_bin, 12, 16 );
228  // Add 4 bit version resulting in 52 bits total
229  $id_bin .= '0001';
230  // Add 12 bits of "time high" resulting in 64 bits total
231  $id_bin .= substr( $time_bin, 0, 12 );
232  // Add 2 bits of "variant" resulting in 66 bits total
233  $id_bin .= '10';
234  // Add 6 bits of "clock seq high" resulting in 72 bits total
235  $id_bin .= substr( $clkSeq_bin, 0, 6 );
236  // Add 8 bits of "clock seq low" resulting in 80 bits total
237  $id_bin .= substr( $clkSeq_bin, 6, 8 );
238  // Add the 48 bit node ID resulting in 128 bits total
239  $id_bin .= $this->getNodeId48();
240  // Convert to a 32 char hex string with dashes
241  if ( strlen( $id_bin ) !== 128 ) {
242  throw new RuntimeException( "Detected overflow for millisecond timestamp." );
243  }
244  $hex = \Wikimedia\base_convert( $id_bin, 2, 16, 32 );
245  return sprintf( '%s-%s-%s-%s-%s',
246  // "time_low" (32 bits)
247  substr( $hex, 0, 8 ),
248  // "time_mid" (16 bits)
249  substr( $hex, 8, 4 ),
250  // "time_hi_and_version" (16 bits)
251  substr( $hex, 12, 4 ),
252  // "clk_seq_hi_res" (8 bits) and "clk_seq_low" (8 bits)
253  substr( $hex, 16, 4 ),
254  // "node" (48 bits)
255  substr( $hex, 20, 12 )
256  );
257  }
258 
265  public function newRawUUIDv1() {
266  return str_replace( '-', '', $this->newUUIDv1() );
267  }
268 
275  public function newUUIDv4() {
276  $hex = bin2hex( random_bytes( 32 / 2 ) );
277 
278  return sprintf( '%s-%s-%s-%s-%s',
279  // "time_low" (32 bits)
280  substr( $hex, 0, 8 ),
281  // "time_mid" (16 bits)
282  substr( $hex, 8, 4 ),
283  // "time_hi_and_version" (16 bits)
284  '4' . substr( $hex, 12, 3 ),
285  // "clk_seq_hi_res" (8 bits, variant is binary 10x) and "clk_seq_low" (8 bits)
286  dechex( 0x8 | ( hexdec( $hex[15] ) & 0x3 ) ) . $hex[16] . substr( $hex, 17, 2 ),
287  // "node" (48 bits)
288  substr( $hex, 19, 12 )
289  );
290  }
291 
298  public function newRawUUIDv4() {
299  return str_replace( '-', '', $this->newUUIDv4() );
300  }
301 
314  public function newSequentialPerNodeID( $bucket, $bits = 48, $flags = 0 ) {
315  return current( $this->newSequentialPerNodeIDs( $bucket, $bits, 1, $flags ) );
316  }
317 
328  public function newSequentialPerNodeIDs( $bucket, $bits, $count, $flags = 0 ) {
329  return $this->getSequentialPerNodeIDs( $bucket, $bits, $count, $flags );
330  }
331 
339  public function getTimestampFromUUIDv1( string $uuid, int $format = TS_MW ) {
340  $components = [];
341  if ( !preg_match(
342  '/^([0-9a-f]{8})-([0-9a-f]{4})-(1[0-9a-f]{3})-([89ab][0-9a-f]{3})-([0-9a-f]{12})$/',
343  $uuid,
344  $components
345  ) ) {
346  throw new InvalidArgumentException( "Invalid UUIDv1 {$uuid}" );
347  }
348 
349  $timestamp = hexdec( substr( $components[3], 1 ) . $components[2] . $components[1] );
350  // The 60 bit timestamp value is constructed from fields of this UUID.
351  // The timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.
352  $unixTime = ( $timestamp - 0x01b21dd213814000 ) / 1e7;
353 
354  return ConvertibleTimestamp::convert( $format, $unixTime );
355  }
356 
368  protected function getSequentialPerNodeIDs( $bucket, $bits, $count, $flags ) {
369  if ( $count <= 0 ) {
370  return [];
371  }
372  if ( $bits < 16 || $bits > 48 ) {
373  throw new RuntimeException( "Requested bit size ($bits) is out of range." );
374  }
375 
376  $path = $this->tmpDir . '/' . self::FILE_PREFIX . '-' . rawurlencode( $bucket ) . '-48';
377  // Get the UID lock file handle
378  if ( isset( $this->fileHandles[$path] ) ) {
379  $handle = $this->fileHandles[$path];
380  } else {
381  $handle = fopen( $path, 'cb+' );
382  $this->fileHandles[$path] = $handle ?: null;
383  }
384  // Acquire the UID lock file
385  if ( $handle === false ) {
386  throw new RuntimeException( "Could not open '{$path}'." );
387  }
388  if ( !flock( $handle, LOCK_EX ) ) {
389  fclose( $handle );
390  throw new RuntimeException( "Could not acquire '{$path}'." );
391  }
392  // Fetch the counter value and increment it...
393  rewind( $handle );
394 
395  // fetch as float
396  $counter = floor( (float)trim( fgets( $handle ) ) ) + $count;
397 
398  // Write back the new counter value
399  ftruncate( $handle, 0 );
400  rewind( $handle );
401 
402  // Use fmod() to avoid "division by zero" on 32 bit machines
403  // warp-around as needed
404  fwrite( $handle, (string)fmod( $counter, 2 ** 48 ) );
405  fflush( $handle );
406 
407  // Release the UID lock file
408  flock( $handle, LOCK_UN );
409 
410  $ids = [];
411  $divisor = 2 ** $bits;
412 
413  // pre-increment counter value
414  $currentId = floor( $counter - $count );
415  for ( $i = 0; $i < $count; ++$i ) {
416  // Use fmod() to avoid "division by zero" on 32 bit machines
417  $ids[] = fmod( ++$currentId, $divisor );
418  }
419 
420  return $ids;
421  }
422 
440  protected function getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize ) {
441  // Get the UID lock file handle
442  if ( isset( $this->fileHandles[$this->$lockFile] ) ) {
443  $handle = $this->fileHandles[$this->$lockFile];
444  } else {
445  $handle = fopen( $this->$lockFile, 'cb+' );
446  $this->fileHandles[$this->$lockFile] = $handle ?: null;
447  }
448  // Acquire the UID lock file
449  if ( $handle === false ) {
450  throw new RuntimeException( "Could not open '{$this->$lockFile}'." );
451  }
452  if ( !flock( $handle, LOCK_EX ) ) {
453  fclose( $handle );
454  throw new RuntimeException( "Could not acquire '{$this->$lockFile}'." );
455  }
456 
457  // The formatters that use this method expect a timestamp with millisecond
458  // precision and a counter upto a certain size. When more IDs than the counter
459  // size are generated during the same timestamp, an exception is thrown as we
460  // cannot increment further, because the formatted ID would not have enough
461  // bits to fit the counter.
462  //
463  // To orchestrate this between independent PHP processes on the same host,
464  // we must have a common sense of time so that we only have to maintain
465  // a single counter in a single lock file.
466  //
467  // Given that:
468  // * The system clock can be observed via time(), without milliseconds.
469  // * Some other clock can be observed via microtime(), which also offers
470  // millisecond precision.
471  // * microtime() drifts in-process further and further away from the system
472  // clock the longer a process runs for.
473  // For example, on 2018-10-03 an HHVM 3.18 JobQueue process at WMF,
474  // that ran for 9 min 55 sec, microtime drifted by 7 seconds.
475  // time() does not have this problem. See https://bugs.php.net/bug.php?id=42659.
476  //
477  // We have two choices:
478  //
479  // 1. Use microtime() with the following caveats:
480  // - The last stored time may be in the future, or our current time may be in the
481  // past, in which case we'll frequently enter the slow timeWaitUntil() method to
482  // try and "sync" the current process with the previous process.
483  // We mustn't block for long though, max 10ms?
484  // - For any drift above 10ms, we pretend that the clock went backwards, and treat
485  // it the same way as after an NTP sync, by incrementing clock sequence instead.
486  // Given the sequence rolls over automatically, and silently, and is meant to be
487  // rare, this is essentially sacrifices a reasonable guarantee of uniqueness.
488  // - For long running processes (e.g. longer than a few seconds) the drift can
489  // easily be more than 2 seconds. Because we only have a single lock file
490  // and don't want to keep too many counters and deal with clearing those,
491  // we fatal the user and refuse to make an ID. (T94522)
492  // - This offers terrible service availability.
493  // 2. Use time() instead, and expand the counter size by 1000x and use its
494  // digits as if they were the millisecond fraction of our timestamp.
495  // Known caveats or perf impact: None. We still need to read-write our
496  // lock file on each generation, so might as well make the most of it.
497  //
498  // We choose the latter.
499  $msecCounterSize = $counterSize * 1000;
500 
501  rewind( $handle );
502  // Format of lock file contents:
503  // "<clk seq> <sec> <msec counter> <rand offset>"
504  $data = explode( ' ', fgets( $handle ) );
505 
506  if ( count( $data ) === 4 ) {
507  // The UID lock file was already initialized
508  $clkSeq = (int)$data[0] % $clockSeqSize;
509  $prevSec = (int)$data[1];
510  // Counter for UIDs with the same timestamp,
511  $msecCounter = 0;
512  $randOffset = (int)$data[3] % $counterSize;
513 
514  // If the system clock moved backwards by an NTP sync,
515  // or if the last writer process had its clock drift ahead,
516  // Try to catch up if the gap is small, so that we can keep a single
517  // monotonic logic file.
518  $sec = $this->timeWaitUntil( $prevSec );
519  if ( $sec === false ) {
520  // Gap is too big. Looks like the clock got moved back significantly.
521  // Start a new clock sequence, and re-randomize the extra offset,
522  // which is useful for UIDs that do not include the clock sequence number.
523  $clkSeq = ( $clkSeq + 1 ) % $clockSeqSize;
524  $sec = time();
525  $randOffset = mt_rand( 0, $offsetSize - 1 );
526  trigger_error( "Clock was set back; sequence number incremented." );
527  } elseif ( $sec === $prevSec ) {
528  // Double check, only keep remainder if a previous writer wrote
529  // something here that we don't accept.
530  $msecCounter = (int)$data[2] % $msecCounterSize;
531  // Bump the counter if the time has not changed yet
532  if ( ++$msecCounter >= $msecCounterSize ) {
533  // More IDs generated with the same time than counterSize can accommodate
534  flock( $handle, LOCK_UN );
535  throw new RuntimeException( "Counter overflow for timestamp value." );
536  }
537  }
538  } else {
539  // Initialize UID lock file information
540  $clkSeq = mt_rand( 0, $clockSeqSize - 1 );
541  $sec = time();
542  $msecCounter = 0;
543  $randOffset = mt_rand( 0, $offsetSize - 1 );
544  }
545 
546  // Update and release the UID lock file
547  ftruncate( $handle, 0 );
548  rewind( $handle );
549  fwrite( $handle, "{$clkSeq} {$sec} {$msecCounter} {$randOffset}" );
550  fflush( $handle );
551  flock( $handle, LOCK_UN );
552 
553  // Split msecCounter back into msec and counter
554  $msec = (int)( $msecCounter / 1000 );
555  $counter = $msecCounter % 1000;
556 
557  return [
558  self::CLOCK_TIME => [ $sec, $msec ],
559  self::CLOCK_COUNTER => $counter,
560  self::CLOCK_SEQUENCE => $clkSeq,
561  self::CLOCK_OFFSET => $randOffset,
562  self::CLOCK_OFFSET_COUNTER => $counter + $randOffset,
563  ];
564  }
565 
573  protected function timeWaitUntil( $time ) {
574  $start = microtime( true );
575  do {
576  $ct = time();
577  // https://www.php.net/manual/en/language.operators.comparison.php
578  if ( $ct >= $time ) {
579  // current time is higher than or equal to than $time
580  return $ct;
581  }
582  // up to 10ms
583  } while ( ( microtime( true ) - $start ) <= 0.010 );
584 
585  return false;
586  }
587 
593  protected function millisecondsSinceEpochBinary( array $time ) {
594  list( $sec, $msec ) = $time;
595  $ts = 1000 * $sec + $msec;
596  if ( $ts > 2 ** 52 ) {
597  throw new RuntimeException( __METHOD__ .
598  ': sorry, this function doesn\'t work after the year 144680' );
599  }
600 
601  return substr( \Wikimedia\base_convert( (string)$ts, 10, 2, 46 ), -46 );
602  }
603 
610  protected function intervalsSinceGregorianBinary( array $time, $delta = 0 ) {
611  list( $sec, $msec ) = $time;
612  $offset = '122192928000000000';
613 
614  // 64 bit integers
615  if ( PHP_INT_SIZE >= 8 ) {
616  $ts = ( 1000 * $sec + $msec ) * 10000 + (int)$offset + $delta;
617  $id_bin = str_pad( decbin( $ts % ( 2 ** 60 ) ), 60, '0', STR_PAD_LEFT );
618  } elseif ( extension_loaded( 'gmp' ) ) {
619  // ms
620  $ts = gmp_add( gmp_mul( (string)$sec, '1000' ), (string)$msec );
621  // 100ns intervals
622  $ts = gmp_add( gmp_mul( $ts, '10000' ), $offset );
623  $ts = gmp_add( $ts, (string)$delta );
624  // wrap around
625  $ts = gmp_mod( $ts, gmp_pow( '2', 60 ) );
626  $id_bin = str_pad( gmp_strval( $ts, 2 ), 60, '0', STR_PAD_LEFT );
627  } elseif ( extension_loaded( 'bcmath' ) ) {
628  // ms
629  $ts = bcadd( bcmul( $sec, '1000' ), $msec );
630  // 100ns intervals
631  $ts = bcadd( bcmul( $ts, '10000' ), $offset );
632  $ts = bcadd( $ts, (string)$delta );
633  // wrap around
634  $ts = bcmod( $ts, bcpow( '2', '60' ) );
635  $id_bin = \Wikimedia\base_convert( $ts, 10, 2, 60 );
636  } else {
637  throw new RuntimeException( 'bcmath or gmp extension required for 32 bit machines.' );
638  }
639  return $id_bin;
640  }
641 
645  private function load() {
646  if ( $this->loaded ) {
647  return;
648  }
649 
650  $this->loaded = true;
651 
652  $nodeId = '';
653  if ( is_file( $this->nodeIdFile ) ) {
654  $nodeId = file_get_contents( $this->nodeIdFile );
655  }
656  // Try to get some ID that uniquely identifies this machine (RFC 4122)...
657  if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
658  AtEase::suppressWarnings();
659  if ( PHP_OS_FAMILY === 'Windows' ) {
660  // https://technet.microsoft.com/en-us/library/bb490913.aspx
661  $csv = trim( ( $this->shellCallback )( 'getmac /NH /FO CSV' ) );
662  $line = substr( $csv, 0, strcspn( $csv, "\n" ) );
663  $info = str_getcsv( $line );
664  // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal False positive
665  $nodeId = isset( $info[0] ) ? str_replace( '-', '', $info[0] ) : '';
666  } elseif ( is_executable( '/sbin/ifconfig' ) ) {
667  // Linux/BSD/Solaris/OS X
668  // See https://linux.die.net/man/8/ifconfig
669  $m = [];
670  preg_match( '/\s([0-9a-f]{2}(?::[0-9a-f]{2}){5})\s/',
671  ( $this->shellCallback )( '/sbin/ifconfig -a' ), $m );
672  $nodeId = isset( $m[1] ) ? str_replace( ':', '', $m[1] ) : '';
673  }
674  AtEase::restoreWarnings();
675  if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
676  $nodeId = bin2hex( random_bytes( 12 / 2 ) );
677  // set multicast bit
678  $nodeId[1] = dechex( hexdec( $nodeId[1] ) | 0x1 );
679  }
680  file_put_contents( $this->nodeIdFile, $nodeId );
681  }
682  $this->nodeId32 = \Wikimedia\base_convert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
683  $this->nodeId48 = \Wikimedia\base_convert( $nodeId, 16, 2, 48 );
684  }
685 
689  private function getNodeId32() {
690  $this->load();
691 
692  return $this->nodeId32;
693  }
694 
698  private function getNodeId48() {
699  $this->load();
700 
701  return $this->nodeId48;
702  }
703 
715  private function deleteCacheFiles() {
716  foreach ( $this->fileHandles as $path => $handle ) {
717  if ( $handle !== null ) {
718  fclose( $handle );
719  }
720  if ( is_file( $path ) ) {
721  unlink( $path );
722  }
723  unset( $this->fileHandles[$path] );
724  }
725  if ( is_file( $this->nodeIdFile ) ) {
726  unlink( $this->nodeIdFile );
727  }
728  }
729 
742  public function unitTestTearDown() {
743  $this->deleteCacheFiles();
744  }
745 
746  public function __destruct() {
747  // @phan-suppress-next-line PhanPluginUseReturnValueInternalKnown
748  array_map( 'fclose', array_filter( $this->fileHandles ) );
749  }
750 }
Class for getting statistically unique IDs without a central coordinator.
newRawUUIDv1()
Return an RFC4122 compliant v1 UUID.
const CLOCK_OFFSET
Key used in the serialized clock state map that is stored on disk.
newTimestampedUID88(int $base=10)
Get a statistically unique 88-bit unsigned integer ID string.
newSequentialPerNodeID( $bucket, $bits=48, $flags=0)
Return an ID that is sequential only for this node and bucket.
newTimestampedUID128(int $base=10)
Get a statistically unique 128-bit unsigned integer ID string.
newUUIDv4()
Return an RFC4122 compliant v4 UUID.
getSequentialPerNodeIDs( $bucket, $bits, $count, $flags)
Return IDs that are sequential only for this node and bucket.
newRawUUIDv4()
Return an RFC4122 compliant v4 UUID.
const FILE_PREFIX
Avoid using CLASS so namespace separators aren't interpreted as path components on Windows (T259693)
const CLOCK_OFFSET_COUNTER
Key used in the serialized clock state map that is stored on disk.
unitTestTearDown()
Cleanup resources when tearing down after a unit test (T46850)
string $tmpDir
Temporary directory.
string $nodeId32
Node ID in binary (32 bits)
string $nodeId48
Node ID in binary (48 bits)
const CLOCK_COUNTER
Key used in the serialized clock state map that is stored on disk.
__construct( $tempDirectory, $shellCallback)
timeWaitUntil( $time)
Wait till the current timestamp reaches $time and return the current timestamp.
bool $loaded
Whether initialization completed.
newUUIDv1()
Return an RFC4122 compliant v1 UUID.
string $lockFile128
Local file path.
array $fileHandles
Cached file handles.
getTimestampFromUUIDv1(string $uuid, int $format=TS_MW)
Get timestamp in a specified format from UUIDv1.
callable $shellCallback
Callback for running shell commands.
getTimeAndDelay( $lockFile, $clockSeqSize, $counterSize, $offsetSize)
Get a (time,counter,clock sequence) where (time,counter) is higher than any previous (time,...
string $lockFileUUID
Local file path.
string $nodeIdFile
Local file path.
load()
Load the node ID information.
newSequentialPerNodeIDs( $bucket, $bits, $count, $flags=0)
Return IDs that are sequential only for this node and bucket.
const CLOCK_TIME
Key used in the serialized clock state map that is stored on disk.
const CLOCK_SEQUENCE
Key used in the serialized clock state map that is stored on disk.
intervalsSinceGregorianBinary(array $time, $delta=0)
deleteCacheFiles()
Delete all cache files that have been created (T46850)
string $lockFile88
Local file path.
$line
Definition: mcc.php:119