Motr  M0
ufid.h File Reference
#include "motr/client.h"
Include dependency graph for ufid.h:

Go to the source code of this file.

Data Structures

struct  m0_ufid
 
struct  m0_ufid_generator
 

Macros

#define __MOTR_HELPERS_UFID_H__
 
#define UFID_MASK(N)   ((1UL << N) - 1UL)
 
#define M0_UFID_GENID_MASK   UFID_MASK(M0_UFID_GENID_BITS)
 
#define M0_UFID_GENID_HI_MASK   UFID_MASK(M0_UFID_GENID_HI_BITS)
 
#define M0_UFID_GENID_LO_MASK   UFID_MASK(M0_UFID_GENID_LO_BITS)
 
#define M0_UFID_SALT_MASK   UFID_MASK(M0_UFID_SALT_BITS)
 
#define M0_UFID_SEQID_MASK   UFID_MASK(M0_UFID_SEQID_BITS)
 
#define M0_UFID_PROCID_MASK   UFID_MASK(M0_UFID_PROCID_BITS)
 
#define M0_UFID_RESERVED_MASK   UFID_MASK(M0_UFID_RESERVED_BITS)
 
#define M0_UFID_HI_RESERVED   (UINT64_MAX << (64UL - M0_UFID_RESERVED_BITS))
 
#define M0_UFID_SEQID_MAX   (1UL << M0_UFID_SEQID_BITS)
 
#define M0_UFID_PROCID_MAX   (1UL << M0_UFID_PROCID_BITS)
 

Enumerations

enum  { M0_UFID_BASE_TS = 1514764800L, M0_UFID_RETRY_MAX = 1000L, M0_UFID_CLOCK_SKEW_LIMIT = 300 }
 
enum  m0_ufid_format {
  M0_UFID_SEQID_BITS = 20UL, M0_UFID_PROCID_BITS = 29UL, M0_UFID_GENID_BITS = 31UL, M0_UFID_SALT_BITS = 11UL,
  M0_UFID_RESERVED_BITS = 37UL, M0_UFID_MAX_BITS = 91UL
}
 
enum  m0_ufid_gen_id_format { M0_UFID_GENID_HI_BITS = 16UL, M0_UFID_GENID_LO_BITS = 15UL }
 
enum  m0_ufid_procid_format { M0_UFID_PROCID_WARN_BITS = 1UL, M0_UFID_PROCID_SAFE_BITS = 28UL }
 

Macro Definition Documentation

◆ __MOTR_HELPERS_UFID_H__

#define __MOTR_HELPERS_UFID_H__

Definition at line 25 of file ufid.h.

◆ M0_UFID_GENID_HI_MASK

#define M0_UFID_GENID_HI_MASK   UFID_MASK(M0_UFID_GENID_HI_BITS)

Definition at line 172 of file ufid.h.

◆ M0_UFID_GENID_LO_MASK

#define M0_UFID_GENID_LO_MASK   UFID_MASK(M0_UFID_GENID_LO_BITS)

Definition at line 173 of file ufid.h.

◆ M0_UFID_GENID_MASK

#define M0_UFID_GENID_MASK   UFID_MASK(M0_UFID_GENID_BITS)

Definition at line 171 of file ufid.h.

◆ M0_UFID_HI_RESERVED

#define M0_UFID_HI_RESERVED   (UINT64_MAX << (64UL - M0_UFID_RESERVED_BITS))

Definition at line 179 of file ufid.h.

◆ M0_UFID_PROCID_MASK

#define M0_UFID_PROCID_MASK   UFID_MASK(M0_UFID_PROCID_BITS)

Definition at line 176 of file ufid.h.

◆ M0_UFID_PROCID_MAX

#define M0_UFID_PROCID_MAX   (1UL << M0_UFID_PROCID_BITS)

Definition at line 182 of file ufid.h.

◆ M0_UFID_RESERVED_MASK

#define M0_UFID_RESERVED_MASK   UFID_MASK(M0_UFID_RESERVED_BITS)

Definition at line 177 of file ufid.h.

◆ M0_UFID_SALT_MASK

#define M0_UFID_SALT_MASK   UFID_MASK(M0_UFID_SALT_BITS)

Definition at line 174 of file ufid.h.

◆ M0_UFID_SEQID_MASK

#define M0_UFID_SEQID_MASK   UFID_MASK(M0_UFID_SEQID_BITS)

Definition at line 175 of file ufid.h.

◆ M0_UFID_SEQID_MAX

#define M0_UFID_SEQID_MAX   (1UL << M0_UFID_SEQID_BITS)

Definition at line 181 of file ufid.h.

◆ UFID_MASK

#define UFID_MASK (   N)    ((1UL << N) - 1UL)

Definition at line 170 of file ufid.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

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>
static struct m0_client *m0c;
static struct m0_config m0c_conf;
static struct m0_ufid_generator ufid_gr;
static void example1(struct m0_client *m0c)
{
int rc;
struct m0_uint128 id128 = M0_UINT128(0, 0);
rc = m0_ufid_next(&ufid_gr, 1, &id128);
if (rc < 0)
printf("m0_ufid_next() returned error: %d", rc);
}
static void example2()
{
int rc;
struct m0_uint128 id128 = M0_UINT128(0, 0);
rc = m0_ufid_new(&ufid_gr, 100, 100, &id128);
if (rc < 0)
printf("m0_ufid_new() returned error: %d", rc);
}
int main()
{
int rc;
rc = m0_client_init(&m0c, &m0c_conf, true)?:
m0_ufid_init(m0c, &ufid_gr);
if (rc != 0)
return rc;
example1(m0c);
example2(m0c);
m0_ufid_fini(ufid_gr);
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.

◆ m0_ufid_format

Enumerator
M0_UFID_SEQID_BITS 
M0_UFID_PROCID_BITS 
M0_UFID_GENID_BITS 
M0_UFID_SALT_BITS 
M0_UFID_RESERVED_BITS 
M0_UFID_MAX_BITS 

Definition at line 147 of file ufid.h.

◆ m0_ufid_gen_id_format

Enumerator
M0_UFID_GENID_HI_BITS 
M0_UFID_GENID_LO_BITS 

Definition at line 156 of file ufid.h.

◆ m0_ufid_procid_format

M0_UFID_PROCID_SAFE_BITS == M0_UFID_PROCID_BITS - M0_UFID_PROCID_WARN_BITS

Enumerator
M0_UFID_PROCID_WARN_BITS 
M0_UFID_PROCID_SAFE_BITS 

Definition at line 165 of file ufid.h.