-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
227 lines (198 loc) · 9.14 KB
/
Makefile
File metadata and controls
227 lines (198 loc) · 9.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# MetaStore Makefile
# Build configuration for MetaStore with unified storage engine support
# Storage engines: Memory (in-memory + WAL) and Pebble (pure Go persistent KV)
# Binary name
BINARY_NAME=metaStore
CMD_PATH=./cmd/metastore
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Build flags
LDFLAGS=-ldflags="-s -w"
# Colors for output
NO_COLOR=\033[0m
GREEN=\033[0;32m
YELLOW=\033[0;33m
CYAN=\033[0;36m
RED=\033[0;31m
.PHONY: all build clean test help deps tidy run-memory run-pebble cluster-memory cluster-pebble install test-perf test-perf-memory test-perf-pebble benchmark
## all: Default target - build the binary
all: build
## build: Build MetaStore binary (pure Go, no CGO required)
build:
@echo "$(CYAN)Building MetaStore...$(NO_COLOR)"
@# Ensure go.sum exists by downloading dependencies if needed
@if [ ! -f "go.sum" ] || [ -z "$$(cat go.sum 2>/dev/null)" ]; then \
echo "$(YELLOW)Downloading Go dependencies...$(NO_COLOR)"; \
export GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct; \
go mod download && go mod tidy; \
fi
@# Build with pure Go (no CGO needed - Pebble is pure Go)
@export GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct; \
if CGO_ENABLED=0 GOEXPERIMENT=greenteagc $(GOBUILD) --help >/dev/null 2>&1; then \
echo "$(YELLOW)Building with GreenTea GC experiment...$(NO_COLOR)"; \
CGO_ENABLED=0 GOEXPERIMENT=greenteagc $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(CMD_PATH); \
else \
echo "$(YELLOW)Building with standard GC...$(NO_COLOR)"; \
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(CMD_PATH); \
fi
@echo "$(GREEN)Build complete: $(BINARY_NAME)$(NO_COLOR)"
@ls -lh $(BINARY_NAME)
## clean: Remove binary and clean build cache
clean:
@echo "$(YELLOW)Cleaning...$(NO_COLOR)"
@if command -v go >/dev/null 2>&1; then $(GOCLEAN); fi
@rm -f $(BINARY_NAME)
@rm -rf data/
@rm -rf test/data/
@rm -rf /tmp/metastore-test-*
@rm -f /tmp/test_*.log
@echo "$(GREEN)Clean complete$(NO_COLOR)"
## test: Run all tests (excluding performance/benchmark tests)
test:
@echo "$(CYAN)Running all tests (excluding performance/benchmark tests)...$(NO_COLOR)"
@echo "$(YELLOW)Cleaning test data directories...$(NO_COLOR)"
@rm -rf data/
@rm -rf test/data/
@rm -rf /tmp/metastore-test-*
@echo "$(YELLOW)Testing pkg packages (excluding concurrency)...$(NO_COLOR)"
@$(GOTEST) -v -short -timeout=5m ./pkg/config/... ./pkg/health/... ./pkg/pool/...
@echo "$(YELLOW)Testing pkg/concurrency package...$(NO_COLOR)"
@$(GOTEST) -v -short -timeout=5m ./pkg/concurrency/...
@echo "$(YELLOW)Testing internal packages...$(NO_COLOR)"
@$(GOTEST) -v -timeout=30m ./internal/...
@echo "$(YELLOW)Testing integration and system tests...$(NO_COLOR)"
@$(GOTEST) -v -short -timeout=45m -skip "Performance|Benchmark" ./test/
@echo "$(GREEN)All tests passed!$(NO_COLOR)"
## test-unit: Run only unit tests (no integration tests)
test-unit:
@echo "$(CYAN)Running unit tests...$(NO_COLOR)"
@$(GOTEST) -v -timeout=5m ./pkg/...
@$(GOTEST) -v -timeout=15m ./internal/...
## test-integration: Run only integration tests
test-integration:
@echo "$(CYAN)Running integration tests...$(NO_COLOR)"
@echo "$(YELLOW)Cleaning test data directories...$(NO_COLOR)"
@rm -rf data/
@rm -rf test/data/
@rm -rf /tmp/metastore-test-*
@$(GOTEST) -v -timeout=20m ./test/
## test-storage: Run only storage tests
test-storage:
@echo "$(CYAN)Running storage tests...$(NO_COLOR)"
@$(GOTEST) -v ./internal/pebbledb/
## test-coverage: Run tests with coverage report
test-coverage:
@echo "$(CYAN)Running tests with coverage...$(NO_COLOR)"
@$(GOTEST) -timeout=20m -coverprofile=coverage.out ./internal/... ./test/
@go tool cover -html=coverage.out -o coverage.html
@echo "$(GREEN)Coverage report generated: coverage.html$(NO_COLOR)"
## test-maintenance: Run only Maintenance Service tests
test-maintenance:
@echo "$(CYAN)Running Maintenance Service tests...$(NO_COLOR)"
@$(GOTEST) -v -timeout=10m -run="TestMaintenance_" ./test/
@echo "$(GREEN)Maintenance tests passed!$(NO_COLOR)"
## test-quick: Run quick tests (Maintenance only, for rapid verification)
test-quick:
@echo "$(CYAN)Running quick tests...$(NO_COLOR)"
@$(GOTEST) -v -timeout=10m -run="TestMaintenance_(Status|Hash|Alarm)" ./test/
@echo "$(GREEN)Quick tests passed!$(NO_COLOR)"
## test-perf-memory: Run Memory storage performance tests
test-perf-memory:
@echo "$(CYAN)Running Memory storage performance tests...$(NO_COLOR)"
@$(GOTEST) -v -timeout=20m -run="TestMemoryPerformance_" ./test/
@echo "$(GREEN)Memory performance tests completed!$(NO_COLOR)"
## test-perf-pebble: Run Pebble storage performance tests
test-perf-pebble:
@echo "$(CYAN)Running Pebble storage performance tests...$(NO_COLOR)"
@$(GOTEST) -v -timeout=20m -run="TestPebblePerformance_" ./test/
@echo "$(GREEN)Pebble performance tests completed!$(NO_COLOR)"
## test-perf: Run all performance tests (Memory + Pebble)
test-perf:
@echo "$(CYAN)Running all performance tests...$(NO_COLOR)"
@echo "$(YELLOW)Testing Memory storage performance...$(NO_COLOR)"
@$(GOTEST) -v -timeout=20m -run="TestMemoryPerformance_" ./test/
@echo "$(YELLOW)Testing Pebble storage performance...$(NO_COLOR)"
@$(GOTEST) -v -timeout=20m -run="TestPebblePerformance_" ./test/
@echo "$(GREEN)All performance tests completed!$(NO_COLOR)"
## benchmark: Run benchmark tests
benchmark:
@echo "$(CYAN)Running benchmark tests...$(NO_COLOR)"
@$(GOTEST) -v -timeout=30m -run="Benchmark" ./test/
@echo "$(GREEN)Benchmark tests completed!$(NO_COLOR)"
## deps: Download dependencies
deps:
@echo "$(CYAN)Downloading dependencies...$(NO_COLOR)"
@$(GOGET) -v ./...
## tidy: Tidy and verify dependencies
tidy:
@echo "$(CYAN)Tidying dependencies...$(NO_COLOR)"
@$(GOMOD) tidy
@$(GOMOD) verify
## install: Install the binary to $GOPATH/bin
install: build
@echo "$(CYAN)Installing $(BINARY_NAME)...$(NO_COLOR)"
@cp $(BINARY_NAME) $(GOPATH)/bin/
@echo "$(GREEN)Installed to $(GOPATH)/bin/$(BINARY_NAME)$(NO_COLOR)"
## run-memory: Run single node with memory storage
run-memory: build
@echo "$(CYAN)Starting MetaStore with memory storage...$(NO_COLOR)"
@./$(BINARY_NAME) -id 1 -port 9121 -storage memory
## run-pebble: Run single node with Pebble storage
run-pebble: build
@echo "$(CYAN)Starting MetaStore with Pebble storage...$(NO_COLOR)"
@mkdir -p data
@./$(BINARY_NAME) -id 1 -port 9121 -storage pebble
## cluster-memory: Start 3-node cluster with memory storage (background)
cluster-memory: build
@echo "$(CYAN)Starting 3-node cluster with memory storage...$(NO_COLOR)"
@./$(BINARY_NAME) -id 1 -port 9121 -storage memory -cluster http://127.0.0.1:9021,http://127.0.0.1:9022,http://127.0.0.1:9023 > /tmp/node1.log 2>&1 &
@./$(BINARY_NAME) -id 2 -port 9122 -storage memory -cluster http://127.0.0.1:9021,http://127.0.0.1:9022,http://127.0.0.1:9023 > /tmp/node2.log 2>&1 &
@./$(BINARY_NAME) -id 3 -port 9123 -storage memory -cluster http://127.0.0.1:9021,http://127.0.0.1:9022,http://127.0.0.1:9023 > /tmp/node3.log 2>&1 &
@sleep 2
@echo "$(GREEN)Cluster started. Check logs: /tmp/node*.log$(NO_COLOR)"
@echo "$(YELLOW)Stop with: make stop-cluster$(NO_COLOR)"
## cluster-pebble: Start 3-node cluster with Pebble storage (background)
cluster-pebble: build
@echo "$(CYAN)Starting 3-node cluster with Pebble storage...$(NO_COLOR)"
@mkdir -p data
@./$(BINARY_NAME) -id 1 -port 9121 -storage pebble -cluster http://127.0.0.1:9021,http://127.0.0.1:9022,http://127.0.0.1:9023 > /tmp/node1.log 2>&1 &
@./$(BINARY_NAME) -id 2 -port 9122 -storage pebble -cluster http://127.0.0.1:9021,http://127.0.0.1:9022,http://127.0.0.1:9023 > /tmp/node2.log 2>&1 &
@./$(BINARY_NAME) -id 3 -port 9123 -storage pebble -cluster http://127.0.0.1:9021,http://127.0.0.1:9022,http://127.0.0.1:9023 > /tmp/node3.log 2>&1 &
@sleep 2
@echo "$(GREEN)Cluster started. Check logs: /tmp/node*.log$(NO_COLOR)"
@echo "$(YELLOW)Stop with: make stop-cluster$(NO_COLOR)"
## stop-cluster: Stop all running MetaStore processes
stop-cluster:
@echo "$(YELLOW)Stopping all MetaStore processes...$(NO_COLOR)"
@pkill -f $(BINARY_NAME) || true
@sleep 1
@echo "$(GREEN)All processes stopped$(NO_COLOR)"
## status: Show cluster status
status:
@echo "$(CYAN)Checking cluster status...$(NO_COLOR)"
@ps aux | grep $(BINARY_NAME) | grep -v grep || echo "No processes running"
@echo ""
@echo "$(CYAN)Data directory:$(NO_COLOR)"
@ls -la data/ 2>/dev/null || echo "No data directory"
## help: Show this help message
help:
@echo "$(CYAN)MetaStore Makefile Commands:$(NO_COLOR)"
@echo ""
@sed -n 's/^##//p' Makefile | column -t -s ':' | sed -e 's/^/ /'
@echo ""
@echo "$(YELLOW)Examples:$(NO_COLOR)"
@echo " make build # Build the binary (pure Go, no CGO)"
@echo " make test # Run all tests (excluding perf/benchmark)"
@echo " make test-unit # Run unit tests only"
@echo " make test-integration # Run integration tests only"
@echo " make test-perf # Run all performance tests"
@echo " make benchmark # Run benchmark tests"
@echo " make run-memory # Run with memory storage"
@echo " make cluster-pebble # Start 3-node Pebble cluster"
@echo " make stop-cluster # Stop all nodes"
@echo " make clean # Clean build artifacts"