moderator-toolbox-nxg-for-reddit / util/wiki/schemas/usernotes/sharding
util/wiki/schemas/usernotes/sharding¶
Functions¶
hashUsername()¶
hashUsername(
name):number
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:79
Hashes a username to its uint32 shard key with 32-bit FNV-1a over the
lowercased name. Lowercased because storage may key one user under both a
lowercase and a canonical-cased name (merged by getUser) - both casings
must land in the same shard. The function is part of the storage format:
changing it strands existing users in the wrong shards.
Parameters¶
name¶
string
Returns¶
number
initialManifest()¶
initialManifest(
types):UsernotesManifest
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:133
Builds the manifest for a freshly sharded subreddit: one shard covering the whole hash space.
Parameters¶
types¶
Returns¶
isUsernotesManifest()¶
isUsernotesManifest(
value):value is UsernotesManifest
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:94
Structurally validates a parsed NXG usernotes page as a manifest, including the shard range invariants (sorted, first range starts at 0, no duplicate starts or pages).
Parameters¶
value¶
unknown
Returns¶
value is UsernotesManifest
mergeShardData()¶
mergeShardData(
shards,types):UserNotesData
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:214
Merges decoded shard datasets into one in-memory dataset. Users colliding
across shards should be impossible (ranges are disjoint); if it happens
anyway the last shard wins and the result is flagged corrupted.
Parameters¶
types¶
The manifest’s type definitions, attached to the result.
Returns¶
partitionUsers()¶
partitionUsers(
users,manifest):Map<string,Record<string,UsernotesUser>>
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:161
Partitions a user map into per-shard user maps by username hash. Every shard in the manifest gets an entry, even when empty - an emptied shard is rewritten as a valid empty envelope rather than removed (ranges never merge).
Parameters¶
users¶
Record<string, UsernotesUser>
manifest¶
Returns¶
Map<string, Record<string, UsernotesUser>>
pickSplitBoundary()¶
pickSplitBoundary(
users,rangeStart):number|null
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:185
Picks the hash boundary to split an overflowing shard’s range at: the median user’s hash, nudged forward past duplicates so the boundary is strictly inside the range and both halves are non-empty.
Parameters¶
users¶
The users currently in the shard.
rangeStart¶
number
The shard’s inclusive lower hash bound.
Returns¶
number | null
The new boundary (start of the upper half), or null when the
shard cannot split (fewer than two distinct hashes above rangeStart).
Interfaces¶
UsernotesManifest¶
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:52
The JSON manifest stored at the NXG usernotes page.
Properties¶
format¶
format:
"tbun-manifest"
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:53
gen¶
gen:
number
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:56
Monotonic generation counter, bumped whenever the shard list changes. Makes split page names unique.
retired?¶
optionalretired?:string[]
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:69
Pages retired by a split whose best-effort tombstone write failed; retried on later manifest writes and dropped once tombstoned.
shards¶
shards:
UsernotesShardRef[]
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:64
Shard ranges, sorted by start; shards[0].start is always 0.
types¶
types:
UserNoteColor[]
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:62
Usernote type definitions, making the sharded layout self-contained
(v6 envelopes only carry type keys). Seeded from the subreddit config’s
usernoteColors on write.
ver¶
ver:
7
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:54
UsernotesShardRef¶
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:41
One shard’s entry in the manifest.
Properties¶
page¶
page:
string
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:48
Page-name suffix under the NXG usernotes prefix, e.g. s3-80000000.
start¶
start:
number
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:46
Inclusive uint32 lower bound of the shard’s hash range. Shard i covers
[start_i, start_{i+1}); the last shard covers through 2^32 - 1.
Variables¶
USERNOTES_MANIFEST_FORMAT¶
constUSERNOTES_MANIFEST_FORMAT:"tbun-manifest"='tbun-manifest'
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:18
Manifest format marker; identifies the page as a shard manifest.
USERNOTES_MANIFEST_VER¶
constUSERNOTES_MANIFEST_VER:7=7
Defined in: extension/data/util/wiki/schemas/usernotes/sharding.ts:24
Current manifest schema version. Continues the legacy usernotes numbering: v6 is the single-page zlib format, v7 the sharded manifest layout.