Skip to content

Commit 0bc64fd

Browse files
authored
Merge branch '3.0-dev' into fix_avoid_top_panic
2 parents f873eea + e6d0a67 commit 0bc64fd

85 files changed

Lines changed: 21338 additions & 10759 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea/
2+
.kiro
23
*.o
34
*.a
45
*.exe

pkg/bootstrap/upgrade.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions/v2_1_0"
2727
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions/v2_2_0"
2828
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions/v3_0_0"
29+
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions/v3_0_1"
2930
)
3031

3132
// initUpgrade all versions need create a upgrade handle in pkg/bootstrap/versions
@@ -45,6 +46,7 @@ func (s *service) initUpgrade() {
4546
s.handles = append(s.handles, v2_1_0.Handler)
4647
s.handles = append(s.handles, v2_2_0.Handler)
4748
s.handles = append(s.handles, v3_0_0.Handler)
49+
s.handles = append(s.handles, v3_0_1.Handler)
4850
}
4951

5052
func (s *service) getFinalVersionHandle() VersionHandle {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 Matrix Origin
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+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v3_0_1
16+
17+
import (
18+
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions"
19+
)
20+
21+
// No cluster-level upgrades for v3.0.1
22+
var clusterUpgEntries = []versions.UpgradeEntry{}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 Matrix Origin
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+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v3_0_1
16+
17+
import (
18+
"github.com/matrixorigin/matrixone/pkg/common/log"
19+
"github.com/matrixorigin/matrixone/pkg/common/runtime"
20+
)
21+
22+
func getLogger(sid string) *log.MOLogger {
23+
return runtime.ServiceRuntime(sid).Logger()
24+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2025 Matrix Origin
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+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v3_0_1
16+
17+
import (
18+
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions"
19+
"github.com/matrixorigin/matrixone/pkg/catalog"
20+
"github.com/matrixorigin/matrixone/pkg/frontend"
21+
"github.com/matrixorigin/matrixone/pkg/util/executor"
22+
)
23+
24+
var tenantUpgEntries = []versions.UpgradeEntry{
25+
enableBranchMetadata,
26+
enableRoleRule,
27+
}
28+
29+
var enableBranchMetadata = versions.UpgradeEntry{
30+
Schema: catalog.MO_CATALOG,
31+
TableName: catalog.MO_BRANCH_METADATA,
32+
UpgType: versions.CREATE_NEW_TABLE,
33+
UpgSql: frontend.MoCatalogBranchMetadataDDL,
34+
CheckFunc: func(txn executor.TxnExecutor, accountId uint32) (bool, error) {
35+
return versions.CheckTableDefinition(txn, accountId, catalog.MO_CATALOG, catalog.MO_BRANCH_METADATA)
36+
},
37+
}
38+
39+
var enableRoleRule = versions.UpgradeEntry{
40+
Schema: catalog.MO_CATALOG,
41+
TableName: catalog.MO_ROLE_RULE,
42+
UpgType: versions.CREATE_NEW_TABLE,
43+
UpgSql: frontend.MoCatalogMoRoleRuleDDL,
44+
CheckFunc: func(txn executor.TxnExecutor, accountId uint32) (bool, error) {
45+
return versions.CheckTableDefinition(txn, accountId, catalog.MO_CATALOG, catalog.MO_ROLE_RULE)
46+
},
47+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2025 Matrix Origin
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+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v3_0_1
16+
17+
import (
18+
"context"
19+
"time"
20+
21+
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions"
22+
"github.com/matrixorigin/matrixone/pkg/catalog"
23+
"github.com/matrixorigin/matrixone/pkg/common/moerr"
24+
"github.com/matrixorigin/matrixone/pkg/util/executor"
25+
"go.uber.org/zap"
26+
)
27+
28+
var (
29+
Handler *versionHandle
30+
)
31+
32+
func init() {
33+
Handler = &versionHandle{
34+
metadata: versions.Version{
35+
Version: "3.0.1",
36+
MinUpgradeVersion: "3.0.0",
37+
UpgradeCluster: versions.No,
38+
UpgradeTenant: versions.Yes,
39+
VersionOffset: uint32(len(tenantUpgEntries) + len(clusterUpgEntries)),
40+
},
41+
}
42+
}
43+
44+
type versionHandle struct {
45+
metadata versions.Version
46+
}
47+
48+
func (v *versionHandle) Metadata() versions.Version {
49+
return v.metadata
50+
}
51+
52+
func (v *versionHandle) Prepare(
53+
ctx context.Context,
54+
txn executor.TxnExecutor,
55+
final bool) error {
56+
txn.Use(catalog.MO_CATALOG)
57+
return nil
58+
}
59+
60+
func (v *versionHandle) HandleTenantUpgrade(
61+
ctx context.Context,
62+
tenantID int32,
63+
txn executor.TxnExecutor,
64+
) error {
65+
66+
var (
67+
err error
68+
goon bool
69+
)
70+
71+
for _, upgEntry := range tenantUpgEntries {
72+
goon = false
73+
74+
start := time.Now()
75+
err = upgEntry.Upgrade(txn, uint32(tenantID))
76+
77+
duration := time.Since(start)
78+
79+
if err == nil {
80+
goon = true
81+
getLogger(txn.Txn().TxnOptions().CN).Info("tenant upgrade",
82+
zap.String("cn", txn.Txn().TxnOptions().CN),
83+
zap.String("entry", upgEntry.String()),
84+
zap.Int32("tenantId", tenantID),
85+
zap.String("version", v.metadata.Version),
86+
zap.Duration("duration", duration),
87+
zap.Error(err),
88+
)
89+
} else {
90+
getLogger(txn.Txn().TxnOptions().CN).Error("tenant upgrade",
91+
zap.String("cn", txn.Txn().TxnOptions().CN),
92+
zap.String("entry", upgEntry.String()),
93+
zap.Int32("tenantId", tenantID),
94+
zap.String("version", v.metadata.Version),
95+
zap.Duration("duration", duration),
96+
zap.Error(err),
97+
)
98+
}
99+
100+
if goon {
101+
continue
102+
}
103+
return err
104+
}
105+
106+
return nil
107+
}
108+
109+
func (v *versionHandle) HandleClusterUpgrade(
110+
ctx context.Context,
111+
txn executor.TxnExecutor,
112+
) error {
113+
// No cluster-level upgrades for v3.0.1
114+
return nil
115+
}
116+
117+
func (v *versionHandle) HandleCreateFrameworkDeps(txn executor.TxnExecutor) error {
118+
return moerr.NewInternalErrorNoCtxf("Only v1.2.0 can initialize upgrade framework, current version is:%s", Handler.metadata.Version)
119+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2025 Matrix Origin
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+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v3_0_1
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"github.com/golang/mock/gomock"
22+
"github.com/stretchr/testify/assert"
23+
24+
"github.com/matrixorigin/matrixone/pkg/bootstrap/versions"
25+
"github.com/matrixorigin/matrixone/pkg/common/moerr"
26+
"github.com/matrixorigin/matrixone/pkg/common/runtime"
27+
mock_frontend "github.com/matrixorigin/matrixone/pkg/frontend/test"
28+
"github.com/matrixorigin/matrixone/pkg/pb/txn"
29+
"github.com/matrixorigin/matrixone/pkg/util/executor"
30+
)
31+
32+
func Test_Upgrade(t *testing.T) {
33+
sid := ""
34+
runtime.RunTest(
35+
sid,
36+
func(rt runtime.Runtime) {
37+
txnOperator := mock_frontend.NewMockTxnOperator(gomock.NewController(t))
38+
txnOperator.EXPECT().TxnOptions().Return(txn.TxnOptions{CN: sid}).AnyTimes()
39+
40+
executor := executor.NewMemTxnExecutor(func(sql string) (executor.Result, error) {
41+
return executor.Result{}, nil
42+
}, txnOperator)
43+
44+
metadata := Handler.Metadata()
45+
t.Logf("version metadata:%v", metadata)
46+
47+
if err := Handler.Prepare(context.Background(), executor, true); err != nil {
48+
t.Errorf("Prepare() error = %v", err)
49+
}
50+
51+
if err := Handler.HandleCreateFrameworkDeps(executor); err == nil {
52+
t.Errorf("HandleCreateFrameworkDeps() should report err")
53+
}
54+
55+
if err := Handler.HandleClusterUpgrade(context.Background(), executor); err != nil {
56+
t.Errorf("HandleClusterUpgrade() error = %v", err)
57+
}
58+
59+
if err := Handler.HandleTenantUpgrade(context.Background(), 0, executor); err != nil {
60+
t.Errorf("HandleTenantUpgrade() error = %v", err)
61+
}
62+
},
63+
)
64+
}
65+
66+
func Test_versionHandle_HandleClusterUpgrade(t *testing.T) {
67+
v := &versionHandle{
68+
metadata: versions.Version{
69+
Version: "v3.0.1",
70+
},
71+
}
72+
sid := ""
73+
txnOperator := mock_frontend.NewMockTxnOperator(gomock.NewController(t))
74+
txnOperator.EXPECT().TxnOptions().Return(txn.TxnOptions{CN: sid}).AnyTimes()
75+
executor2 := executor.NewMemTxnExecutor(func(sql string) (executor.Result, error) {
76+
return executor.Result{}, moerr.NewInvalidInputNoCtx("return error")
77+
}, txnOperator)
78+
79+
err := v.HandleClusterUpgrade(context.Background(),
80+
executor2,
81+
)
82+
assert.Nil(t, err)
83+
}

pkg/catalog/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ const (
196196
MO_SQL_STMT_CU = "sql_statement_cu"
197197

198198
// default database name for catalog
199-
MO_CATALOG = "mo_catalog"
200-
MO_DATABASE = "mo_database"
201-
MO_TABLES = "mo_tables"
202-
MO_COLUMNS = "mo_columns"
203-
MO_USER = "mo_user"
199+
MO_CATALOG = "mo_catalog"
200+
MO_DATABASE = "mo_database"
201+
MO_TABLES = "mo_tables"
202+
MO_COLUMNS = "mo_columns"
203+
MO_USER = "mo_user"
204+
MO_ROLE_RULE = "mo_role_rule"
204205

205206
// 'mo_database' table
206207
SystemDBAttr_ID = "dat_id"

pkg/frontend/authenticate.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ var (
975975
catalog.MO_ACCOUNT_LOCK: 0,
976976
catalog.MO_MERGE_SETTINGS: 0,
977977
catalog.MO_BRANCH_METADATA: 0,
978+
catalog.MO_ROLE_RULE: 0,
978979
}
979980
createDbInformationSchemaSql = "create database information_schema;"
980981
createAutoTableSql = MoCatalogMoAutoIncrTableDDL
@@ -1016,6 +1017,7 @@ var (
10161017
MoCatalogMergeSettingsDDL,
10171018
MoCatalogMergeSettingsInitData,
10181019
MoCatalogBranchMetadataDDL,
1020+
MoCatalogMoRoleRuleDDL,
10191021
}
10201022

10211023
//drop tables for the tenant
@@ -1035,6 +1037,7 @@ var (
10351037
`drop view if exists mo_catalog.mo_transactions;`,
10361038
`drop view if exists mo_catalog.mo_cache;`,
10371039
`drop table if exists mo_catalog.mo_snapshots;`,
1040+
`drop table if exists mo_catalog.mo_role_rule;`,
10381041
}
10391042
dropMoMysqlCompatibilityModeSql = `drop table if exists mo_catalog.mo_mysql_compatibility_mode;`
10401043
dropAutoIcrColSql = fmt.Sprintf("drop table if exists mo_catalog.`%s`;", catalog.MOAutoIncrTable)
@@ -5793,10 +5796,13 @@ func determinePrivilegeSetOfStatement(stmt tree.Statement) *privilege {
57935796
*tree.ShowTableValues, *tree.ShowNodeList, *tree.ShowRolesStmt,
57945797
*tree.ShowLocks, *tree.ShowFunctionOrProcedureStatus, *tree.ShowPublications, *tree.ShowSubscriptions,
57955798
*tree.ShowBackendServers, *tree.ShowStages, *tree.ShowConnectors, *tree.DropConnector,
5796-
*tree.PauseDaemonTask, *tree.CancelDaemonTask, *tree.ResumeDaemonTask, *tree.ShowRecoveryWindow:
5799+
*tree.PauseDaemonTask, *tree.CancelDaemonTask, *tree.ResumeDaemonTask, *tree.ShowRecoveryWindow,
5800+
*tree.ShowRules:
57975801
objType = objectTypeNone
57985802
kind = privilegeKindNone
57995803
canExecInRestricted = true
5804+
case *tree.AlterRoleAddRule, *tree.AlterRoleDropRule:
5805+
typs = append(typs, PrivilegeTypeAlterRole, PrivilegeTypeAccountAll)
58005806
case *tree.ShowAccounts:
58015807
objType = objectTypeNone
58025808
kind = privilegeKindSpecial

0 commit comments

Comments
 (0)