Skip to content

Commit

Permalink
Merge pull request #103798 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1-103148

release-23.1: server: server identity returns nodeID for system tenant
  • Loading branch information
dhartunian committed Jun 2, 2023
2 parents 2747de2 + 3053977 commit 305392c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ func (s *idProvider) ServerIdentityString(key serverident.ServerIdentificationKe
case serverident.IdentifyKVNodeID:
// If tenantID is set, this is a SQL-only server and it has no
// node ID.
if s.tenantID.IsSet() {
if s.tenantID.IsSet() && !s.tenantID.IsSystem() {
return ""
}
return s.maybeMemoizeServerID()
Expand Down
72 changes: 72 additions & 0 deletions pkg/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import (
"net"
"os"
"reflect"
"sync/atomic"
"testing"
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/base/serverident"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
Expand All @@ -27,6 +30,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/netutil"
"github.com/cockroachdb/cockroach/pkg/util/netutil/addr"
"github.com/kr/pretty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -268,3 +272,71 @@ func TestParseBootstrapResolvers(t *testing.T) {
}
})
}

func TestIdProviderServerIdentityString(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

type fields struct {
clusterID *base.ClusterIDContainer
clusterStr atomic.Value
tenantID roachpb.TenantID
tenantStr atomic.Value
serverID *base.NodeIDContainer
serverStr atomic.Value
}
type args struct {
key serverident.ServerIdentificationKey
}

nodeID := &base.NodeIDContainer{}
nodeID.Set(context.Background(), roachpb.NodeID(123))

tenID, err := roachpb.MakeTenantID(2)
require.NoError(t, err)

tests := []struct {
name string
fields fields
args args
want string
}{
{
"system tenant shows nodeID",
fields{tenantID: roachpb.SystemTenantID, serverID: nodeID},
args{key: serverident.IdentifyKVNodeID},
"123",
},
{
"system tenant shows tenID",
fields{tenantID: roachpb.SystemTenantID, serverID: nodeID},
args{key: serverident.IdentifyTenantID},
"1",
},
{
"application tenant hides nodeID",
fields{tenantID: tenID, serverID: nodeID},
args{key: serverident.IdentifyKVNodeID},
"",
},
{
"application tenant shows tenID",
fields{tenantID: tenID, serverID: nodeID},
args{key: serverident.IdentifyTenantID},
"2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &idProvider{
clusterID: tt.fields.clusterID,
clusterStr: tt.fields.clusterStr,
tenantID: tt.fields.tenantID,
tenantStr: tt.fields.tenantStr,
serverID: tt.fields.serverID,
serverStr: tt.fields.serverStr,
}
assert.Equalf(t, tt.want, s.ServerIdentityString(tt.args.key), "ServerIdentityString(%v)", tt.args.key)
})
}
}

0 comments on commit 305392c

Please sign in to comment.