From 56b8c1c913c934775d9fe304652b4cfe4cbb20c3 Mon Sep 17 00:00:00 2001 From: Andy Yang Date: Wed, 2 Aug 2023 12:16:21 -0400 Subject: [PATCH] builtinconstants: define constants for unique int bit segments This patch defines constants for the sizes and bitmasks for each bit segment in a unique int generated for row IDs. Release note: None --- pkg/sql/row/row_converter.go | 2 +- .../builtins/builtinconstants/constants.go | 28 +++++++++++++++++-- pkg/sql/sem/builtins/builtins.go | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/sql/row/row_converter.go b/pkg/sql/row/row_converter.go index 2b7a3a35b413..ea5757d199c9 100644 --- a/pkg/sql/row/row_converter.go +++ b/pkg/sql/row/row_converter.go @@ -489,7 +489,7 @@ func NewDatumRowConverter( return c, nil } -const rowIDBits = 64 - builtinconstants.NodeIDBits +const rowIDBits = 64 - builtinconstants.UniqueIntNodeIDBits // Row inserts kv operations into the current kv batch, and triggers a SendBatch // if necessary. diff --git a/pkg/sql/sem/builtins/builtinconstants/constants.go b/pkg/sql/sem/builtins/builtinconstants/constants.go index 13eb43f35465..6e0964fd8e09 100644 --- a/pkg/sql/sem/builtins/builtinconstants/constants.go +++ b/pkg/sql/sem/builtins/builtinconstants/constants.go @@ -76,6 +76,28 @@ const ( CreateSchemaTelemetryJobBuiltinName = "crdb_internal.create_sql_schema_telemetry_job" ) -// NodeIDBits is the number of bits stored in the lower portion of -// GenerateUniqueInt. -const NodeIDBits = 15 +// A unique int generated by GenerateUniqueInt is a 64-bit integer with +// the following format: +// +// [1 leading zero bit][48 bits for timestamp][15 bits for nodeID] +const ( + // UniqueIntLeadingZeroBits is the number of leading zero bits in a unique + // int generated by GenerateUniqueInt. + UniqueIntLeadingZeroBits = 1 + + // UniqueIntTimestampBits is the number of bits in the timestamp segment + // in a unique int generated by GenerateUniqueInt. + UniqueIntTimestampBits = 48 + + // UniqueIntNodeIDBits is the number of bits in the node ID segment + // in a unique int generated by GenerateUniqueInt. + UniqueIntNodeIDBits = 15 + + // UniqueIntNodeIDMask is a bitmask for the node ID in a unique int + // generated by GenerateUniqueInt. + UniqueIntNodeIDMask = 1<