feat(job-array-one-based-index): array ID allocation numbered from 1 (task 1.3)

idgen_array() allocates the next whole 32768 block and returns its
first element (array tag, index 1), refusing n outside 1..32767 and a
block past the 20-bit sequence (-EOVERFLOW, context unchanged). The
reset-on-new-second step is shared with idgen() via idgen_tick_locked();
idgen() itself is unchanged until task 9.1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-01 09:24:00 +00:00
parent d027410304
commit ef728435d4
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
4 changed files with 212 additions and 10 deletions

View file

@ -20,4 +20,12 @@ extern int idgen_ctx_init(idgen_ctx_t*);
extern int idgen(idgen_ctx_t*, size_t, size_t, size_t, uint64_t*);
extern void idgen_ctx_fini(idgen_ctx_t*);
/* First element ID of a new n-element array, numbered from 1.
* 1 <= n <= MAX_ARRAY_IDX (32767). On success *first = MAKE_JOBID(c, a, ts,
* TAG_JOB_ARRAY, (block << 15) | 1), the context is advanced past the whole
* block and n is returned. -EINVAL for bad args or n; -EOVERFLOW if the next
* block would leave the sequence field (the context is left unchanged). */
extern int idgen_array(idgen_ctx_t* ctx, size_t clusterId, size_t apiserverId,
size_t n, uint64_t* first);
#endif