Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: pick and fix conflict commits from develop branch #1457

Merged
merged 3 commits into from
Jul 26, 2024
Merged
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
4 changes: 0 additions & 4 deletions .codecov.yml

This file was deleted.

29 changes: 15 additions & 14 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@ jobs:
staticcheck:
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.22"

- uses: actions/cache@v3
uses: actions/setup-go@v5
with:
path: ~/go/pkg/mod
key: reviewdog-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
reviewdog-${{ runner.os }}-go-
go-version: stable
# For self-hosted, the cache path is shared across projects
# and it works well without the cache of github actions
# Enable it if we're going to use Github only
cache: false

- uses: reviewdog/action-staticcheck@v1
with:
Expand All @@ -47,14 +44,18 @@ jobs:
lint:
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: stable
# for self-hosted, the cache path is shared across projects
# and it works well without the cache of github actions
# Enable it if we're going to use Github only
cache: false

- name: Golangci Lint
# https://golangci-lint.run/
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest
31 changes: 14 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ jobs:
unit-scenario-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
- name: Unit Test
run: go test -gcflags=-l -race -covermode=atomic -coverprofile=coverage.txt ./...
go-version: '1.20'
- name: Scenario Tests
run: |
cd ..
Expand All @@ -21,19 +19,17 @@ jobs:
cd kitex-tests
./run.sh ${{github.workspace}}
cd ${{github.workspace}}
- name: Codecov
run: bash <(curl -s https://codecov.io/bash)

benchmark-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Benchmark
run: go test -gcflags='all=-N -l' -bench=. -benchmem -run=none ./...
run: go test -bench=. -benchmem -run=none ./...

compatibility-test:
strategy:
Expand All @@ -42,20 +38,21 @@ jobs:
os: [ X64, ARM64 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: false # don't use cache for self-hosted runners
- name: Unit Test
run: go test -gcflags=-l -race -covermode=atomic ./...
run: go test -race -covermode=atomic ./...

codegen-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Prepare
Expand All @@ -81,9 +78,9 @@ jobs:
windows-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Windows compatibility test
Expand Down
4 changes: 2 additions & 2 deletions pkg/loadbalance/weighted_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestWeightedPicker_Next(t *testing.T) {
weight := ins.Weight()
weightSum += weight
}
n := 10000000
n := 1000000
pickedStat := map[int]int{}
for i := 0; i < n; i++ {
picker := balancer.GetPicker(discovery.Result{
Expand All @@ -160,7 +160,7 @@ func TestWeightedPicker_Next(t *testing.T) {
expect := float64(weight) / float64(weightSum) * float64(n)
actual := float64(pickedStat[weight])
delta := math.Abs(expect - actual)
test.Assertf(t, delta/expect < 0.01, "delta(%f)/expect(%f) = %f", delta, expect, delta/expect)
test.Assertf(t, delta/expect < 0.05, "delta(%f)/expect(%f) = %f", delta, expect, delta/expect)
}

// weightSum = 0
Expand Down
3 changes: 2 additions & 1 deletion pkg/loadbalance/weighted_round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package loadbalance

import (
"context"
"runtime"
"sync"
"testing"

Expand Down Expand Up @@ -93,7 +94,7 @@ func TestWeightedRoundRobinPickerLargeInstances(t *testing.T) {
insList = append(insList, discovery.NewInstance("tcp", "nbalance", 100, nil))

picker := newWeightedRoundRobinPicker(insList)
concurrency := wrrVNodesBatchSize * 2
concurrency := 2 + runtime.GOMAXPROCS(0)*2
round := len(insList)
var wg sync.WaitGroup
for c := 0; c < concurrency; c++ {
Expand Down
4 changes: 2 additions & 2 deletions pkg/mem/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestSpan(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1024; i++ {
for i := 0; i < 128; i++ {
buf := []byte("123")
test.DeepEqual(t, bc.Copy(buf), buf)

Expand Down Expand Up @@ -92,7 +92,7 @@ func TestSpanCache(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1024; i++ {
for i := 0; i < 128; i++ {
buf := []byte("123")
test.DeepEqual(t, bc.Copy(buf), buf)

Expand Down
30 changes: 10 additions & 20 deletions pkg/protocol/bthrift/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,19 @@ import (

var (
// Binary protocol for bthrift.
Binary binaryProtocol
_ BTProtocol = binaryProtocol{}
Binary binaryProtocol
_ BTProtocol = binaryProtocol{}
spanCache = mem.NewSpanCache(1024 * 1024)
spanCacheEnable bool = false
)

var allocator Allocator

const binaryInplaceThreshold = 4096 // 4k

type binaryProtocol struct{}

// SetSpanCache enable/disable binary protocol bytes/string allocator
func SetSpanCache(enable bool) {
if enable {
SetAllocator(mem.NewSpanCache(1024 * 1024))
} else {
SetAllocator(nil)
}
}

// SetAllocator set binary protocol bytes/string allocator.
func SetAllocator(alloc Allocator) {
allocator = alloc
spanCacheEnable = enable
}

func (binaryProtocol) WriteMessageBegin(buf []byte, name string, typeID thrift.TMessageType, seqid int32) int {
Expand Down Expand Up @@ -479,9 +470,9 @@ func (binaryProtocol) ReadString(buf []byte) (value string, length int, err erro
if size < 0 || int(size) > len(buf) {
return value, length, perrors.NewProtocolErrorWithType(thrift.INVALID_DATA, "[ReadString] the string size greater than buf length")
}
alloc := allocator
if alloc != nil {
value = sliceByteToString(alloc.Copy(buf[length : length+int(size)]))
if spanCacheEnable {
data := spanCache.Copy(buf[length : length+int(size)])
value = sliceByteToString(data)
} else {
value = string(buf[length : length+int(size)])
}
Expand All @@ -500,9 +491,8 @@ func (binaryProtocol) ReadBinary(buf []byte) (value []byte, length int, err erro
if size < 0 || size > len(buf) {
return value, length, perrors.NewProtocolErrorWithType(thrift.INVALID_DATA, "[ReadBinary] the binary size greater than buf length")
}
alloc := allocator
if alloc != nil {
value = alloc.Copy(buf[length : length+size])
if spanCacheEnable {
value = spanCache.Copy(buf[length : length+size])
} else {
value = make([]byte, size)
copy(value, buf[length:length+size])
Expand Down
39 changes: 0 additions & 39 deletions pkg/protocol/bthrift/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,6 @@ func TestWriteAndReadString(t *testing.T) {
test.Assert(t, v == "kitex")
}

// TestWriteAndReadStringWithSpanCache test binary WriteString and ReadString with spanCache allocator
func TestWriteAndReadStringWithSpanCache(t *testing.T) {
buf := make([]byte, 128)
exceptWs := "000000056b69746578"
exceptSize := 9
wn := Binary.WriteString(buf, "kitex")
ws := fmt.Sprintf("%x", buf[:wn])
test.Assert(t, wn == exceptSize, wn, exceptSize)
test.Assert(t, ws == exceptWs, ws, exceptWs)

SetSpanCache(true)
v, length, err := Binary.ReadString(buf)
test.Assert(t, nil == err)
test.Assert(t, exceptSize == length)
test.Assert(t, v == "kitex")
SetSpanCache(false)
}

// TestWriteAndReadBinary test binary WriteBinary and ReadBinary
func TestWriteAndReadBinary(t *testing.T) {
buf := make([]byte, 128)
Expand All @@ -328,27 +310,6 @@ func TestWriteAndReadBinary(t *testing.T) {
}
}

// TestWriteAndReadBinaryWithSpanCache test binary WriteBinary and ReadBinary with spanCache allocator
func TestWriteAndReadBinaryWithSpanCache(t *testing.T) {
buf := make([]byte, 128)
exceptWs := "000000056b69746578"
exceptSize := 9
val := []byte("kitex")
wn := Binary.WriteBinary(buf, val)
ws := fmt.Sprintf("%x", buf[:wn])
test.Assert(t, wn == exceptSize, wn, exceptSize)
test.Assert(t, ws == exceptWs, ws, exceptWs)

SetSpanCache(true)
v, length, err := Binary.ReadBinary(buf)
test.Assert(t, nil == err)
test.Assert(t, exceptSize == length)
for i := 0; i < len(v); i++ {
test.Assert(t, val[i] == v[i])
}
SetSpanCache(false)
}

// TestWriteStringNocopy test binary WriteStringNocopy with small content
func TestWriteStringNocopy(t *testing.T) {
buf := make([]byte, 128)
Expand Down
5 changes: 0 additions & 5 deletions pkg/protocol/bthrift/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,3 @@ type BTProtocol interface {
ReadBinary(buf []byte) (value []byte, length int, err error)
Skip(buf []byte, fieldType thrift.TType) (length int, err error)
}

type Allocator interface {
Make(n int) []byte
Copy(buf []byte) (p []byte)
}
Loading