IF Commons GitHub

merge/id

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0008-anyfs-merge-logical FR-003

The hybrid clock that makes version ids. A replica makes each id from the later of its wall time and the last id it made or took, with the 12-bit counter of the UUID (rand_a) to order the ids of one millisecond, seeded at random in each new millisecond, so that every id it makes is after every id it has seen and ids of one replica never go backwards, even where its wall clock does. An id from the far future is refused when a delta is taken, because one would put every later write of the store behind it.

import { nextTime } from "./id.ts";
nextTime(undefined, 1000); // { ms: 1000, counter: 0 }

Source: commons/anyfs/src/merge/id.ts

2 of 3 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DEFAULT_MAX_DRIFTconstno test imports it
const DEFAULT_MAX_DRIFT: 300000

How far ahead of its own wall clock a replica takes an id: five minutes, in milliseconds.

nextTimefunction
function nextTime(last: IdTime | undefined, wall: number, seed?: number): IdTime

The time of an id made now: after the last time and after the wall time. In the millisecond of the last id the counter is one more than the last; in a new millisecond it starts at seed (0 to MAX_COUNTER_SEED, random where a replica makes ids: RFC 9562 section 6.2, method 1), whose top bit left clear guards against a rollover; where the counter is full the clock goes to the next millisecond and does not wait.

Imported by 19 tests of the run (19 passed, 0 failed): the library's results

seeTimefunction
function seeTime(last: IdTime | undefined, remote: IdTime): IdTime

The last time after a time is taken from another replica: the later of the two, so that the next id made is after it.

Imported by 19 tests of the run (19 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.