Skip to content

Commit

Permalink
Set up actions ci and fix check errors. (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
hslam authored Apr 16, 2021
1 parent 6c1e196 commit 87ccb1a
Show file tree
Hide file tree
Showing 74 changed files with 1,664 additions and 1,437 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: build

on: [push,pull_request]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: ^1.13

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Check
run: make check

- name: Test
run: make test

- name: Build
run: make
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
node/node
unikv/unikv
bin/*
go.mod
go.sum
tools/bin/
.DS_Store
.vscode
78 changes: 65 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,96 @@ ifeq "$(GOPATH)" ""
$(error Please set the environment variable GOPATH before running `make`)
endif

FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'

GO := GO111MODULE=on go
GOBUILD := $(GO) build $(BUILD_FLAG) -tags codes
GOTEST := $(GO) test -p 8
STATICCHECK := GO111MODULE=on staticcheck

LDFLAGS += -X "main.gitHash=`git rev-parse HEAD`"
TEST_LDFLAGS := ""

PACKAGE_LIST := go list ./...| grep -vE "cmd"
PACKAGES := $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/ngaut/$(PROJECT)/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")

# Targets
.PHONY: build linux test go-build go-build-linux go-test prepare finish
.PHONY: build linux test go-build go-build-linux go-test check

default: build

test: prepare go-test
test: go-test

go-test:
@echo "Running tests in native mode."
@export TZ='Asia/Shanghai'; \
$(GOTEST) -cover $(PACKAGES)
$(GOTEST) -race -cover $(PACKAGES)

go-build:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/unistore-server cmd/unistore-server/main.go

go-build-linux:
GOOS=linux $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/unistore-server-linux cmd/unistore-server/main.go

build: prepare go-build finish
build: go-build

linux: go-build-linux

check: fmt errcheck unconvert lint tidy check-static vet staticcheck

fmt:
@echo "gofmt (simplify)"
@gofmt -s -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT)

errcheck:tools/bin/errcheck
@echo "errcheck"
@GO111MODULE=on tools/bin/errcheck -exclude ./tools/check/errcheck_excludes.txt -ignoretests -blank $(PACKAGES)

unconvert:tools/bin/unconvert
@echo "unconvert check"
@GO111MODULE=on tools/bin/unconvert ./...

lint:tools/bin/revive
@echo "linting"
@tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES)

tidy:
@echo "go mod tidy"
./tools/check/check-tidy.sh

check-static: tools/bin/golangci-lint
@echo "golangci-lint"
./tools/bin/golangci-lint run -v --disable-all --deadline=3m \
--enable=misspell \
--enable=ineffassign \
--enable=typecheck \
--enable=varcheck \
--enable=structcheck \
--enable=deadcode \
$$($(PACKAGE_DIRECTORIES))

vet:
@echo "vet"
$(GO) vet -all $(PACKAGES) 2>&1 | $(FAIL_ON_STDOUT)

staticcheck:
@echo "staticcheck"
$(GO) get honnef.co/go/tools/cmd/staticcheck
$(STATICCHECK) ./...

tools/bin/errcheck: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/errcheck github.com/kisielk/errcheck

linux: prepare go-build-linux finish
tools/bin/unconvert: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/unconvert github.com/mdempsky/unconvert

prepare:
cp go.mod1 go.mod
cp go.sum1 go.sum
tools/bin/revive: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/revive github.com/mgechev/revive

finish:
@$(GO) mod tidy
cp go.mod go.mod1
cp go.sum go.sum1
tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.29.0
102 changes: 10 additions & 92 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,16 @@ import (

"github.com/pingcap/badger/options"
"github.com/pingcap/log"
"github.com/pingcap/tidb/store/mockstore/unistore/config"
)

// Config contains configuration options.
type Config struct {
Server Server `toml:"server"` // Unistore server options
Engine Engine `toml:"engine"` // Engine options.
RaftStore RaftStore `toml:"raftstore"` // RaftStore configs
Coprocessor Coprocessor `toml:"coprocessor"` // Coprocessor options
PessimisticTxn PessimisticTxn `toml:"pessimistic-txn"` // Pessimistic txn related
}

type Server struct {
PDAddr string `toml:"pd-addr"`
StoreAddr string `toml:"store-addr"`
StatusAddr string `toml:"status-addr"`
LogLevel string `toml:"log-level"`
RegionSize int64 `toml:"region-size"` // Average region size.
MaxProcs int `toml:"max-procs"` // Max CPU cores to use, set 0 to use all CPU cores in the machine.
Raft bool `toml:"raft"` // Enable raft.
LogfilePath string `toml:"log-file"` // Log file path for unistore server
config.Config
RaftStore RaftStore `toml:"raftstore"` // RaftStore configs
}

// RaftStore is the config for raft store.
type RaftStore struct {
PdHeartbeatTickInterval string `toml:"pd-heartbeat-tick-interval"` // pd-heartbeat-tick-interval in seconds
RaftStoreMaxLeaderLease string `toml:"raft-store-max-leader-lease"` // raft-store-max-leader-lease in milliseconds
Expand All @@ -48,46 +37,7 @@ type RaftStore struct {
CustomRaftLog bool `toml:"custom-raft-log"`
}

type Coprocessor struct {
RegionMaxKeys int64 `toml:"region-max-keys"`
RegionSplitKeys int64 `toml:"region-split-keys"`
}

type Engine struct {
DBPath string `toml:"db-path"` // Directory to store the data in. Should exist and be writable.
ValueThreshold int `toml:"value-threshold"` // If value size >= this threshold, only store value offsets in tree.
MaxMemTableSize int64 `toml:"max-mem-table-size"` // Each mem table is at most this size.
MaxTableSize int64 `toml:"max-table-size"` // Each table file is at most this size.
L1Size int64 `toml:"l1-size"`
NumMemTables int `toml:"num-mem-tables"` // Maximum number of tables to keep in memory, before stalling.
NumL0Tables int `toml:"num-L0-tables"` // Maximum number of Level 0 tables before we start compacting.
NumL0TablesStall int `toml:"num-L0-tables-stall"` // Maximum number of Level 0 tables before stalling.
VlogFileSize int64 `toml:"vlog-file-size"` // Value log file size.

// Sync all writes to disk. Setting this to true would slow down data loading significantly.")
SyncWrite bool `toml:"sync-write"`
NumCompactors int `toml:"num-compactors"`
SurfStartLevel int `toml:"surf-start-level"`
BlockCacheSize int64 `toml:"block-cache-size"`
IndexCacheSize int64 `toml:"index-cache-size"`
Compression []string `toml:"compression"` // Compression types for each level
IngestCompression string `toml:"ingest-compression"`

// Only used in tests.
VolatileMode bool

CompactL0WhenClose bool `toml:"compact-l0-when-close"`
}

type PessimisticTxn struct {
// The default and maximum delay in milliseconds before responding to TiDB when pessimistic
// transactions encounter locks
WaitForLockTimeout int64 `toml:"wait-for-lock-timeout"`

// The duration between waking up lock waiter, in milliseconds
WakeUpDelayDuration int64 `toml:"wake-up-delay-duration"`
}

// ParseCompression parses the string s and returns a compression type.
func ParseCompression(s string) options.CompressionType {
switch s {
case "snappy":
Expand All @@ -99,19 +49,12 @@ func ParseCompression(s string) options.CompressionType {
}
}

// MB represents the MB size.
const MB = 1024 * 1024

// DefaultConf returns the default configuration.
var DefaultConf = Config{
Server: Server{
PDAddr: "127.0.0.1:2379",
StoreAddr: "127.0.0.1:9191",
StatusAddr: "127.0.0.1:9291",
RegionSize: 64 * MB,
LogLevel: "info",
MaxProcs: 0,
Raft: true,
LogfilePath: "",
},
Config: config.DefaultConf,
RaftStore: RaftStore{
PdHeartbeatTickInterval: "20s",
RaftStoreMaxLeaderLease: "9s",
Expand All @@ -120,34 +63,9 @@ var DefaultConf = Config{
RaftElectionTimeoutTicks: 10,
CustomRaftLog: true,
},
Engine: Engine{
DBPath: "/tmp/badger",
ValueThreshold: 256,
MaxMemTableSize: 64 * MB,
MaxTableSize: 8 * MB,
NumMemTables: 3,
NumL0Tables: 4,
NumL0TablesStall: 8,
VlogFileSize: 256 * MB,
NumCompactors: 3,
SurfStartLevel: 8,
L1Size: 512 * MB,
Compression: make([]string, 7),
BlockCacheSize: 0, // 0 means disable block cache, use mmap to access sst.
IndexCacheSize: 0,
CompactL0WhenClose: true,
},
Coprocessor: Coprocessor{
RegionMaxKeys: 1440000,
RegionSplitKeys: 960000,
},
PessimisticTxn: PessimisticTxn{
WaitForLockTimeout: 1000, // 1000ms same with tikv default value
WakeUpDelayDuration: 100, // 100ms same with tikv default value
},
}

// parseDuration parses duration argument string.
// ParseDuration parses duration argument string.
func ParseDuration(durationStr string) time.Duration {
dur, err := time.ParseDuration(durationStr)
if err != nil {
Expand Down
File renamed without changes.
Loading

0 comments on commit 87ccb1a

Please sign in to comment.