forked from matrixorigin/matrixone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize workspace dump (matrixorigin#20759)
1. 优化workspace刷盘策略,减少小表刷盘频率 2. 细分workspace threshold为 commit threshold和write threshold,write threshold用于statement之间的刷盘 3. 支持动态调整workspace threshold ``` sql select mo_ctl('cn','workspaceThreshold','commit:write'); ``` commit和write为uint64,单位是MB,分别对应commit 和 write threshold。 Approved by: @reusee, @zhangxu19830126, @triump2020, @XuPeng-SH, @daviszhen, @sukki37, @m-schen
- Loading branch information
1 parent
703e47e
commit 5dcbe05
Showing
14 changed files
with
1,042 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2024 Matrix Origin | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ctl | ||
|
||
import ( | ||
"context" | ||
"github.com/matrixorigin/matrixone/pkg/clusterservice" | ||
"github.com/matrixorigin/matrixone/pkg/common/moerr" | ||
"github.com/matrixorigin/matrixone/pkg/pb/metadata" | ||
"github.com/matrixorigin/matrixone/pkg/pb/query" | ||
"github.com/matrixorigin/matrixone/pkg/vm/process" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type Res struct { | ||
PodID string `json:"pod_id,omitempty"` | ||
CommitThreshold uint64 `json:"commit_threshold,omitempty"` | ||
WriteThreshold uint64 `json:"write_threshold,omitempty"` | ||
ErrorStr string `json:"error,omitempty"` | ||
} | ||
|
||
func handleWorkspaceThreshold( | ||
proc *process.Process, | ||
service serviceType, | ||
parameter string, | ||
sender requestSender, | ||
) (Result, error) { | ||
if service != cn { | ||
return Result{}, moerr.NewWrongServiceNoCtx("expected CN", string(service)) | ||
} | ||
|
||
thresholds := strings.Split(parameter, ":") | ||
if len(thresholds) != 2 { | ||
return Result{}, moerr.NewInvalidInput(proc.Ctx, "invalid parameter") | ||
} | ||
commit, err := strconv.ParseUint(thresholds[0], 10, 64) | ||
if err != nil { | ||
return Result{}, moerr.NewInvalidInput(proc.Ctx, "invalid commit threshold") | ||
} | ||
write, err := strconv.ParseUint(thresholds[1], 10, 64) | ||
if err != nil { | ||
return Result{}, moerr.NewInvalidInput(proc.Ctx, "invalid write threshold") | ||
} | ||
|
||
request := proc.GetQueryClient().NewRequest(query.CmdMethod_WorkspaceThreshold) | ||
request.WorkspaceThresholdRequest = &query.WorkspaceThresholdRequest{ | ||
CommitThreshold: commit, | ||
WriteThreshold: write, | ||
} | ||
|
||
results := make([]Res, 0) | ||
|
||
clusterservice.GetMOCluster( | ||
proc.GetService()).GetCNService(clusterservice.Selector{}, func(cn metadata.CNService) bool { | ||
ctx, cancel := context.WithTimeoutCause(context.Background(), time.Second, moerr.CauseTransferRequest2OtherCNs) | ||
defer cancel() | ||
|
||
resp, err := proc.GetQueryClient().SendMessage(ctx, cn.QueryAddress, request) | ||
err = moerr.AttachCause(ctx, err) | ||
|
||
res := Res{ | ||
PodID: cn.ServiceID, | ||
} | ||
|
||
if err != nil { | ||
res.ErrorStr = err.Error() | ||
} else { | ||
res.CommitThreshold = resp.WorkspaceThresholdResponse.CommitThreshold | ||
res.WriteThreshold = resp.WorkspaceThresholdResponse.WriteThreshold | ||
} | ||
results = append(results, res) | ||
return true | ||
}) | ||
|
||
return Result{ | ||
Method: WorkspaceThreshold, | ||
Data: results, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 Matrix Origin | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ctl | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/matrixorigin/matrixone/pkg/common/moerr" | ||
"github.com/matrixorigin/matrixone/pkg/common/morpc" | ||
"github.com/matrixorigin/matrixone/pkg/common/runtime" | ||
"github.com/matrixorigin/matrixone/pkg/queryservice/client" | ||
"github.com/matrixorigin/matrixone/pkg/vm/process" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestHandleWorkspaceThreshold(t *testing.T) { | ||
id := uuid.New().String() | ||
addr := "127.0.0.1:7755" | ||
initRuntime([]string{id}, []string{addr}) | ||
|
||
runtime.SetupServiceBasedRuntime(id, runtime.ServiceRuntime("")) | ||
|
||
cli, err := client.NewQueryClient(id, morpc.Config{}) | ||
require.Nil(t, err) | ||
|
||
proc := new(process.Process) | ||
proc.Base = &process.BaseProcess{} | ||
proc.Base.QueryClient = cli | ||
|
||
result, err := handleWorkspaceThreshold(proc, tn, "xxx", nil) | ||
require.Equal(t, Result{}, result) | ||
require.True(t, moerr.IsMoErrCode(err, moerr.ErrWrongService)) | ||
|
||
runtime.ServiceRuntime("").SetGlobalVariables(runtime.ClusterService, new(mockCluster)) | ||
|
||
result, err = handleWorkspaceThreshold(proc, cn, "2:3", nil) | ||
require.NoError(t, err) | ||
require.Equal(t, result, Result{ | ||
Method: WorkspaceThreshold, | ||
Data: []Res{ | ||
{ | ||
PodID: "not exist", | ||
ErrorStr: "internal error: invalid CN query address ", | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.