UFID - Unique FID Generator UFID generates a unique ID of 128 bits across multiple client instances. Notice: an UFID generator has to associate with one client instance as UFID generator required unique process ID which is extracted from the lowest 29 bits of client instance's process FID. Halon guarantes that the lowest 29 bits of process FID are unique for each client instance.
FID Format:
127 91|90 80|79 49|48 20|19 0 +------------—+----—+------------—+------------—+----------—+ | Motr | Salt | Generation ID | Process ID | Sequence ID | +------------—+----—+------------—+------------—+----------—+ | 37 Bits |11 Bits| 31 Bits | 29 Bits | 20 Bit | +------------—+----—+------------—+------------—+----------—+
Notes: (1) Salt: 11 bits of random number which is set when UFID is initialised. (2) Generation ID: it is taken from timestep (epoch) represented with 31 bits. A new generation ID is set when UFID is initialised or Sequence ID rolls over 20 bits. (3) Process ID: client instance process ID. Each client instance is assigned a cluster-wide unique FID by Halon and the lowest 29 bits of FID is used as process ID. As FID is 128 bit long and process ID uses only 29 bits, Halon must guarantee that all process IDs extracted from 128 bit FIDs are unique. (4) Sequence ID: simple sequence number generated with the client instance.
UFID APIs
UFID provides with the following APIs, see API specifications in helpers/helpers.h for details.
- int m0_ufid_init(struct m0_client *m0c)
- void m0_ufid_fini(struct m0_client *m0c)
- int m0_ufid_new(struct m0_client *m0c, uint32_t nr_seqs, uint32_t nr_skip_seqs, m0_uint128 *id)
- int m0_ufid_next(struct m0_client *m0c, uint32_t nr_seqs, m0_uint128 *id)
UFID Interface usage example
The following sample code shows how UFID generator is initialised and finalised, particularly how it works with client, and 2 examples on how to call m0_ufid_new() and m0_ufid_next(). Example 1 demonstrates using m0_ufid_next() to get the next available FID, while example 2 shows how to get multiple FIDs in one m0_ufid_new() call.
#include <stdio.h>
{
printf(
"m0_ufid_next() returned error: %d",
rc);
}
static void example2()
{
printf(
"m0_ufid_new() returned error: %d",
rc);
}
{
return 0;
}
Enumerator |
---|
M0_UFID_BASE_TS | Epoch value as on 2018-01-01 00:00:00 CAUTION: Don't change this constant, ever.
Changing this constant may lead to conflict FIDs allocated as the generation ID is calculated based on this constant.
|
M0_UFID_RETRY_MAX | Max attempts before general failure.
|
M0_UFID_CLOCK_SKEW_LIMIT | Max allowable clock skew in seconds.
|
Definition at line 130 of file ufid.h.