feat(job-array-one-based-index): apiserver backend ID helpers and array ID wrapper (task 5.1)
GenerateArrayJobID wraps libxce idgen_array (first element, index 1; one-element arrays included) with a non-cgo stub; pure helpers ParseHumanJobIDStrict (written identity with exact field-width checks, uint64 overflow reported as a width error), IsArrayCapableKey and MakeElementID (bit-identical to libxce jobsel_element_id). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
47b9938120
commit
b88e352616
7 changed files with 260 additions and 3 deletions
|
|
@ -346,6 +346,25 @@ func GenerateJobID(clusterID, apiserverID int, arraySize int) (uint64, error) {
|
|||
return uint64(jobID), nil
|
||||
}
|
||||
|
||||
// GenerateArrayJobID calls the C idgen_array() to allocate a new array of n
|
||||
// elements (1 <= n <= 32767, numbered from 1) and returns the first element's
|
||||
// ID (tag TAG_JOB_ARRAY, index 1); ExtractArrayBaseID of it is the array ID.
|
||||
// n == 1 is a one-element array, not an ordinary job (job-array-one-based-index
|
||||
// 1.1, 1.2). Errors on a bad n or when the sequence block would overflow.
|
||||
func GenerateArrayJobID(clusterID, apiserverID int, n int) (uint64, error) {
|
||||
if n < 1 {
|
||||
return 0, fmt.Errorf("idgen_array: invalid array size %d", n)
|
||||
}
|
||||
idCtxOnce.Do(initIDGen)
|
||||
var first C.uint64_t
|
||||
rc := C.idgen_array(&gIDCtx, C.size_t(clusterID), C.size_t(apiserverID),
|
||||
C.size_t(n), &first)
|
||||
if rc < 0 {
|
||||
return 0, fmt.Errorf("idgen_array failed: %d", int(rc))
|
||||
}
|
||||
return uint64(first), nil
|
||||
}
|
||||
|
||||
// Cleanup releases C resources. Call at process shutdown.
|
||||
func Cleanup() {
|
||||
C.idgen_ctx_fini(&gIDCtx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue