Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ debug: override DEBUG_OPT := -gcflags=all="-N -l"
debug: override CGO_DEBUG_OPT := debug
debug: build

###############################################################################
# disk monitoring tests
###############################################################################
.PHONY: ut-disk-monitor
ut-disk-monitor: config cgo thirdparties
$(info [Disk monitoring unit testing])
@echo "🚀 开始磁盘监控测试..."
@go test -v ./pkg/testutil -run "TestDiskMonitor" -timeout 10m
@echo "✅ 磁盘监控测试完成"

.PHONY: ut-with-disk-monitor
ut-with-disk-monitor: config cgo thirdparties
$(info [Unit testing with disk monitoring])
@echo "🚀 开始带磁盘监控的单元测试..."
@echo "📊 测试前磁盘使用情况:"
@go test -v ./pkg/testutil -run "TestDiskMonitorSuite" -timeout 5m
@echo "📊 运行主要单元测试..."
ifeq ($(UNAME_S),darwin)
@cd optools && ./run_ut.sh UT $(SKIP_TEST)
else
@cd optools && timeout 60m ./run_ut.sh UT $(SKIP_TEST)
endif
@echo "📊 测试后磁盘使用情况:"
@go test -v ./pkg/testutil -run "TestDiskMonitorCleanup" -timeout 2m
@echo "✅ 带磁盘监控的单元测试完成"

###############################################################################
# run unit tests
###############################################################################
Expand Down
11 changes: 0 additions & 11 deletions clients/python/matrixone/cli_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
PROMPT_TOOLKIT_AVAILABLE = True
except ImportError:
PROMPT_TOOLKIT_AVAILABLE = False
# Provide stub classes for documentation generation
class Completer:
"""Stub Completer class when prompt_toolkit is not available"""
pass


# Custom completer for mo-diag commands
Expand Down Expand Up @@ -165,13 +161,6 @@ def _get_databases(self):
except Exception:
return []

else:
# Stub class for documentation generation when prompt_toolkit is not available
class MODiagCompleter:
"""Smart completer for mo-diag commands (stub when prompt_toolkit unavailable)"""
def __init__(self, cli_instance):
self.cli = cli_instance


# ANSI Color codes for terminal output
class Colors:
Expand Down
12 changes: 3 additions & 9 deletions clients/python/tests/online/test_cli_tools_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,14 @@ class TestCLIBasicCommands:
"""Test basic CLI commands"""

def test_show_all_indexes(self, cli_instance):
"""Test show_all_indexes command - validates output when no indexes exist"""
"""Test show_all_indexes command"""
f = io.StringIO()
with redirect_stdout(f):
cli_instance.onecmd("show_all_indexes")

output = f.getvalue()
# Should show index health report or no-indexes message
# Accept various forms of the "no indexes" message
assert (
"Index Health Report" in output
or "No tables with indexes" in output
or "No tables with secondary indexes" in output
or "⚠️" in output # Warning emoji indicates no indexes found
)
# Should show index health report
assert "Index Health Report" in output or "No tables with indexes" in output

def test_sql_command(self, cli_instance):
"""Test SQL command execution"""
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/buger/jsonparser v1.1.1
github.com/bytedance/sonic v1.14.1
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5
github.com/cespare/xxhash v1.1.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/cockroachdb/errors v1.9.1
github.com/colinmarc/hdfs/v2 v2.4.0
Expand Down Expand Up @@ -131,7 +132,6 @@ require (
github.com/bufbuild/protocompile v0.6.0 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cilium/ebpf v0.9.1 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVOVmhWBY=
Expand Down Expand Up @@ -770,6 +771,7 @@ github.com/smartystreets/assertions v1.13.1/go.mod h1:cXr/IwVfSo/RbCSPhoAPv73p3h
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
Expand Down
80 changes: 80 additions & 0 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package backup
import (
"context"
"fmt"
testutil2 "github.com/matrixorigin/matrixone/pkg/testutil"
"os"
"path"
"sync"
"testing"
Expand Down Expand Up @@ -46,6 +48,84 @@ const (
ModuleName = "Backup"
)

// TestDiskMonitorSuite - 磁盘监控测试套件
// 这个测试套件应该在所有其他测试之前运行,用于监控整个测试过程的磁盘使用情况
func TestDiskMonitorSuite(t *testing.T) {
t.Log("🚀 开始磁盘监控测试套件")

// 获取当前工作目录
workDir, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get current working directory: %v", err)
}

// 1. 测试套件开始时的磁盘状态
t.Run("TestSuiteStart", func(t *testing.T) {
t.Log("📊 测试套件开始 - 磁盘使用情况")
testutil2.LogDiskUsage(t, "SUITE-START", workDir)
testutil2.LogSystemInfo(t, "SUITE-START")

// 检查是否有足够的磁盘空间开始测试
if !testutil2.CheckDiskSpace(t, workDir, 2) {
t.Log("⚠️ 警告: 磁盘空间不足,建议清理后再运行测试")
}
})

// 2. 模拟测试运行过程中的磁盘监控
t.Run("TestSuiteMid", func(t *testing.T) {
t.Log("📊 测试套件中期 - 磁盘使用情况")

// 模拟一些文件操作
tempFile, err := os.CreateTemp("", "matrixone_suite_test_*")
if err != nil {
t.Logf("Failed to create temp file: %v", err)
} else {
defer os.Remove(tempFile.Name())

// 写入一些测试数据
data := make([]byte, 5*1024*1024) // 5MB
for i := range data {
data[i] = byte(i % 256)
}

_, err = tempFile.Write(data)
if err != nil {
t.Logf("Failed to write to temp file: %v", err)
}
tempFile.Close()

// 监控写入后的磁盘使用情况
testutil2.LogDiskUsage(t, "SUITE-MID-AFTER-WRITE", workDir)
}

// 监控系统资源使用情况
testutil2.LogSystemInfo(t, "SUITE-MID")
})

// 3. 测试套件结束时的磁盘状态
t.Run("TestSuiteEnd", func(t *testing.T) {
t.Log("📊 测试套件结束 - 磁盘使用情况")
testutil2.LogDiskUsage(t, "SUITE-END", workDir)
testutil2.LogSystemInfo(t, "SUITE-END")

// 检查磁盘使用趋势
usage, err := testutil2.GetDiskUsage(workDir)
if err == nil {
usedPercent := float64(usage.Used) / float64(usage.Total) * 100
if usedPercent > 90 {
t.Log("🔴 磁盘使用率过高 (>90%),建议立即清理")
} else if usedPercent > 80 {
t.Log("🟡 磁盘使用率较高 (>80%),建议考虑清理")
} else if usedPercent > 70 {
t.Log("🟢 磁盘使用率正常 (>70%),继续监控")
} else {
t.Log("🟢 磁盘使用率良好 (<70%)")
}
}
})

t.Log("✅ 磁盘监控测试套件完成")
}
func TestBackupData(t *testing.T) {
defer testutils.AfterTest(t)()
testutils.EnsureNoLeak(t)
Expand Down
48 changes: 0 additions & 48 deletions pkg/common/const.go

This file was deleted.

12 changes: 2 additions & 10 deletions pkg/container/types/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ var packerAllocator = malloc.NewShardedAllocator(
)

func NewPacker() *Packer {
return NewPackerWithSize(4096)
}

func NewPackerWithSize(size uint64) *Packer {
bs, dec, err := packerAllocator.Allocate(size, malloc.NoClear)
bs, dec, err := packerAllocator.Allocate(4096, malloc.NoClear)
if err != nil {
panic(err)
}
Expand All @@ -55,13 +51,9 @@ func NewPackerWithSize(size uint64) *Packer {
}

func NewPackerArray(length int) []*Packer {
return NewPackerArrayWithSize(length, 4096)
}

func NewPackerArrayWithSize(length int, size uint64) []*Packer {
ret := make([]*Packer, 0, length)
for i := 0; i < length; i++ {
ret = append(ret, NewPackerWithSize(size))
ret = append(ret, NewPacker())
}
return ret
}
Expand Down
70 changes: 1 addition & 69 deletions pkg/fileservice/local_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"context"
"errors"
"github.com/matrixorigin/matrixone/pkg/common/malloc"
"io"
"io/fs"
"iter"
Expand All @@ -30,8 +31,6 @@ import (
"sync/atomic"
"time"

"github.com/matrixorigin/matrixone/pkg/common/malloc"

"go.uber.org/zap"

"github.com/matrixorigin/matrixone/pkg/common/moerr"
Expand Down Expand Up @@ -1219,70 +1218,3 @@ func entryIsDir(path string, name string, entry fs.FileInfo) (bool, error) {
}
return false, nil
}

// open for read and write
func (l *LocalFS) OpenFile(ctx context.Context, filePath string) (*os.File, error) {
err := ctx.Err()
if err != nil {
return nil, err
}

path, err := ParsePathAtService(filePath, l.name)
if err != nil {
return nil, err
}
nativePath := l.toNativeFilePath(path.File)
return os.OpenFile(nativePath, os.O_RDWR, 0644)
}

// create or truncate.
func (l *LocalFS) CreateFile(ctx context.Context, filePath string) (*os.File, error) {
err := ctx.Err()
if err != nil {
return nil, err
}

path, err := ParsePathAtService(filePath, l.name)
if err != nil {
return nil, err
}
nativePath := l.toNativeFilePath(path.File)
return os.Create(nativePath)
}

// remove file
func (l *LocalFS) RemoveFile(ctx context.Context, filePath string) error {
err := ctx.Err()
if err != nil {
return err
}

path, err := ParsePathAtService(filePath, l.name)
if err != nil {
return err
}
nativePath := l.toNativeFilePath(path.File)
return os.Remove(nativePath)
}

// open/create then immediately remove. the opend file is good for read/write.
func (l *LocalFS) CreateAndRemoveFile(ctx context.Context, filePath string) (*os.File, error) {
err := ctx.Err()
if err != nil {
return nil, err
}

path, err := ParsePathAtService(filePath, l.name)
if err != nil {
return nil, err
}
nativePath := l.toNativeFilePath(path.File)
f, err := os.Create(nativePath)
if err != nil {
return nil, err
}

// do not check error for this one
os.Remove(nativePath)
return f, nil
}
Loading
Loading