Skip to content

Commit c9e1b4e

Browse files
authored
Add support for different kernel types (Classic and NextGen) by introducing a build tag and including the kernel type in version information. (#1812)
close #1811
1 parent 14bc47c commit c9e1b4e

File tree

9 files changed

+180
-3
lines changed

9 files changed

+180
-3
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ ifeq ("${ENABLE_FIPS}", "1")
6363
GOEXPERIMENT = GOEXPERIMENT=boringcrypto
6464
CGO = 1
6565
endif
66+
ifeq ("${NEXT_GEN}", "1")
67+
ifeq ($(BUILD_FLAG),)
68+
BUILD_FLAG := -tags nextgen
69+
else
70+
BUILD_FLAG := $(BUILD_FLAG),nextgen
71+
endif
72+
endif
6673

6774
RELEASE_VERSION =
6875
ifeq ($(RELEASE_VERSION),)
@@ -134,7 +141,7 @@ build-cdc-with-failpoint: ## Build cdc with failpoint enabled.
134141
$(FAILPOINT_ENABLE)
135142
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc/main.go
136143
$(FAILPOINT_DISABLE)
137-
144+
138145
cdc:
139146
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc
140147

pkg/config/kerneltype/classic.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build !nextgen
15+
16+
package kerneltype
17+
18+
const (
19+
// KernelType is the current kernel type, which is Classic in this case.
20+
KernelType = "Classic"
21+
)
22+
23+
// IsNextGen returns true if the current kernel type is NextGen.
24+
// see doc.go for more info.
25+
func IsNextGen() bool {
26+
return false
27+
}

pkg/config/kerneltype/doc.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// Package kerneltype provides the kernel type of TiDB.
15+
//
16+
// We have 2 types of kernel: Classic and NextGen.
17+
//
18+
// TiDB Classic Kernel refers to the original architecture used during the early
19+
// development stages of TiDB. It utilizes a share-nothing architecture, primarily
20+
// implemented through TiKV, TiDB's distributed transactional key-value storage
21+
// component. In this setup, each TiKV instance independently manages its own
22+
// local storage and computing resources, eliminating dependencies on shared resources.
23+
//
24+
// This architecture provides advantages in terms of horizontal scalability, fault
25+
// tolerance, and simplified management. Each node independently handles data,
26+
// allowing for easy addition or removal of nodes to adapt to workload changes.
27+
// However, unlike the next-generation (cloud native) kernel, it does not leverage
28+
// shared storage solutions like S3 and requires managing local storage directly
29+
// on each node.
30+
//
31+
// The TiDB Next-gen (Cloud Native) Kernel is a new architecture specifically
32+
// designed for cloud-native infrastructure. It adopts a shared-storage architecture
33+
// for the data plane, typically using object storage solutions like Amazon S3 as
34+
// the single source of truth for data storage.
35+
package kerneltype

pkg/config/kerneltype/nextgen.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build nextgen
15+
16+
package kerneltype
17+
18+
const (
19+
// KernelType is the current kernel type, which is Next Generation in this case.
20+
KernelType = "Next Generation"
21+
)
22+
23+
// IsNextGen returns true if the current kernel type is NextGen.
24+
// see doc.go for more info.
25+
func IsNextGen() bool {
26+
return true
27+
}

pkg/config/kerneltype/type.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package kerneltype
15+
16+
// IsClassic returns true if the current kernel type is Classic.
17+
func IsClassic() bool {
18+
return !IsNextGen()
19+
}
20+
21+
// Name returns the kernel type name
22+
func Name() string {
23+
return KernelType
24+
}

pkg/version/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/coreos/go-semver/semver"
2020
"github.com/pingcap/log"
21+
"github.com/pingcap/ticdc/pkg/config/kerneltype"
2122
"go.uber.org/zap"
2223
)
2324

@@ -50,6 +51,7 @@ func LogVersionInfo(app string) {
5051
zap.String("utc-build-time", BuildTS),
5152
zap.String("go-version", GoVersion),
5253
zap.Bool("failpoint-build", false),
54+
zap.String("kernel-type", kerneltype.Name()),
5355
)
5456
}
5557

@@ -62,5 +64,6 @@ func GetRawInfo() string {
6264
info += fmt.Sprintf("UTC Build Time: %s\n", BuildTS)
6365
info += fmt.Sprintf("Go Version: %s\n", GoVersion)
6466
info += fmt.Sprintf("Failpoint Build: %t\n", false)
67+
info += fmt.Sprintf("Kernel Type: %s\n", kerneltype.Name())
6568
return info
6669
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build !nextgen
15+
16+
package version
17+
18+
import (
19+
"testing"
20+
21+
"github.com/stretchr/testify/require"
22+
)
23+
24+
func TestGetRawInfoContainsKernelType(t *testing.T) {
25+
info := GetRawInfo()
26+
require.Contains(t, info, "Kernel Type: Classic\n")
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build nextgen
15+
16+
package version
17+
18+
import (
19+
"testing"
20+
21+
"github.com/stretchr/testify/require"
22+
)
23+
24+
func TestGetRawInfoContainsKernelType(t *testing.T) {
25+
info := GetRawInfo()
26+
require.Contains(t, info, "Kernel Type: Next Generation\n")
27+
}

scripts/check-log-style.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
# limitations under the License.
1313

1414
# zap field name should be camelCase, excepts for idioms and special terms.
15-
grep -RnE "zap.[A-Z][a-zA-Z0-9]+\(\"[0-9A-Za-z]*[-_ ][^\"]*\"(,|\))" api cmd downstreamadapter coordinator eventpb heartbeatpb logservice maintainer pkg server tools utils version tests |
15+
grep -RnE "zap.[A-Z][a-zA-Z0-9]+\(\"[0-9A-Za-z]*[-_ ][^\"]*\"(,|\))" api cmd downstreamadapter coordinator eventpb heartbeatpb logservice maintainer pkg server tools utils tests |
1616
grep -vE "user-agent" |
1717
grep -vE "https_proxy|http_proxy|no_proxy" |
1818
grep -vE "max-message-bytes|max-message-size|replication-factor" |
1919
grep -vE "release-version|git-hash|git-branch|go-version" |
20-
grep -vE "failpoint-build|utc-build-time" |
20+
grep -vE "failpoint-build|utc-build-time|kernel-type" |
2121
awk '{ print } END { if (NR > 0) { exit 1 } }'

0 commit comments

Comments
 (0)