Skip to content

Commit

Permalink
Merge branch 'unstable' of https://github.com/gxlct008/pika into unst…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
gxlct008 committed Nov 10, 2023
2 parents 97893cc + 28831ef commit 20d6957
Show file tree
Hide file tree
Showing 10 changed files with 706 additions and 167 deletions.
39 changes: 17 additions & 22 deletions .github/workflows/pika.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
go-version: 1.19

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
id: cache
with:
path: |
Expand All @@ -52,12 +52,10 @@ jobs:
with:
key: ${{ runner.os }}-build-ubuntu-${{ hashFiles('**/CMakeLists.txt') }}
path: |
${{ github.workspace }}/build
${{ github.workspace }}/buildtrees
${{ github.workspace }}/deps
- name: Build
if: ${{ steps.cache-ubuntu.outputs.cache-hit != 'true' }}
# Build your program with the given configuration
run: cmake --build build --config ${{ env.BUILD_TYPE }}

Expand Down Expand Up @@ -122,18 +120,17 @@ jobs:
source /opt/rh/devtoolset-10/enable
cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DUSE_PIKA_TOOLS=ON -DCMAKE_CXX_FLAGS_DEBUG=-fsanitize=address
- name: Cache Build
uses: actions/cache@v3
id: cache-centos
- uses: actions/cache@v3
with:
key: ${{ runner.os }}-build-centos-${{ hashFiles('**/CMakeLists.txt') }}
path: |
${{ github.workspace }}/build
${{ github.workspace }}/buildtrees
${{ github.workspace }}/deps
path: ${{ github.workspace }}/deps
key: ${{ runner.os }}-centos-deps-${{ hashFiles('**/CMakeLists.txt') }}

- uses: actions/cache@v3
with:
path: ${{ github.workspace }}/buildtrees
key: ${{ runner.os }}-centos-buildtrees-${{ hashFiles('**/CMakeLists.txt') }}

- name: Build
if: ${{ steps.cache-centos.outputs.cache-hit != 'true' }}
run: |
source /opt/rh/devtoolset-10/enable
cmake --build build --config ${{ env.BUILD_TYPE }}
Expand Down Expand Up @@ -181,18 +178,17 @@ jobs:
export CC=/usr/local/opt/gcc@10/bin/gcc-10
cmake -B build -DCMAKE_C_COMPILER=/usr/local/opt/gcc@10/bin/gcc-10 -DUSE_PIKA_TOOLS=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_FLAGS_DEBUG=-fsanitize=address
- name: Cache Build
uses: actions/cache@v3
id: cache-macos
- uses: actions/cache@v3
with:
key: ${{ runner.os }}-build-macos-${{ hashFiles('**/CMakeLists.txt') }}
path: |
${{ github.workspace }}/build
${{ github.workspace }}/buildtrees
${{ github.workspace }}/deps
path: ${{ github.workspace }}/deps
key: ${{ runner.os }}-deps-${{ hashFiles('**/CMakeLists.txt') }}

- uses: actions/cache@v3
with:
path: ${{ github.workspace }}/buildtrees
key: ${{ runner.os }}-buildtrees-${{ hashFiles('**/CMakeLists.txt') }}

- name: Build
if: ${{ steps.cache-macos.outputs.cache-hit != 'true' }}
run: |
cmake --build build --config ${{ env.BUILD_TYPE }}
Expand Down Expand Up @@ -251,4 +247,3 @@ jobs:
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

2 changes: 2 additions & 0 deletions codis/cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Options:
if err := config.LoadFromFile(s); err != nil {
log.PanicErrorf(err, "load config %s failed", s)
}
config.ConfigFileName = s
log.Warnf("option --config = %s", s)
}
models.SetMaxSlotNum(config.MaxSlotNum)
if s, ok := utils.Argument(d, "--host-admin"); ok {
Expand Down
3 changes: 3 additions & 0 deletions codis/config/proxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ session_keepalive_period = "75s"
# Set session to be sensitive to failures. Default is false, instead of closing socket, proxy will send an error response to client.
session_break_on_failure = false

# Slowlog-log-slower-than(us), from receive command to send response, 0 is allways print slow log
slowlog_log_slower_than = 100000

# Set metrics server (such as http://localhost:28000), proxy will report json formatted metrics to specified server in a predefined period.
metrics_report_server = ""
metrics_report_period = "1s"
Expand Down
12 changes: 12 additions & 0 deletions codis/pkg/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ session_keepalive_period = "75s"
# Set session to be sensitive to failures. Default is false, instead of closing socket, proxy will send an error response to client.
session_break_on_failure = false
# Slowlog-log-slower-than(us), from receive command to send response, 0 is allways print slow log
slowlog_log_slower_than = 100000
# Set metrics server (such as http://localhost:28000), proxy will report json formatted metrics to specified server in a predefined period.
metrics_report_server = ""
metrics_report_period = "1s"
Expand Down Expand Up @@ -176,6 +179,8 @@ type Config struct {
SessionKeepAlivePeriod timesize.Duration `toml:"session_keepalive_period" json:"session_keepalive_period"`
SessionBreakOnFailure bool `toml:"session_break_on_failure" json:"session_break_on_failure"`

SlowlogLogSlowerThan int64 `toml:"slowlog_log_slower_than" json:"slowlog_log_slower_than"`

MetricsReportServer string `toml:"metrics_report_server" json:"metrics_report_server"`
MetricsReportPeriod timesize.Duration `toml:"metrics_report_period" json:"metrics_report_period"`
MetricsReportInfluxdbServer string `toml:"metrics_report_influxdb_server" json:"metrics_report_influxdb_server"`
Expand All @@ -186,6 +191,8 @@ type Config struct {
MetricsReportStatsdServer string `toml:"metrics_report_statsd_server" json:"metrics_report_statsd_server"`
MetricsReportStatsdPeriod timesize.Duration `toml:"metrics_report_statsd_period" json:"metrics_report_statsd_period"`
MetricsReportStatsdPrefix string `toml:"metrics_report_statsd_prefix" json:"metrics_report_statsd_prefix"`

ConfigFileName string `toml:"-" json:"config_file_name"`
}

func NewDefaultConfig() *Config {
Expand Down Expand Up @@ -302,6 +309,10 @@ func (c *Config) Validate() error {
return errors.New("invalid session_keepalive_period")
}

if c.SlowlogLogSlowerThan < 0 {
return errors.New("invalid slowlog_log_slower_than")
}

if c.MetricsReportPeriod < 0 {
return errors.New("invalid metrics_report_period")
}
Expand All @@ -311,5 +322,6 @@ func (c *Config) Validate() error {
if c.MetricsReportStatsdPeriod < 0 {
return errors.New("invalid metrics_report_statsd_period")
}

return nil
}
29 changes: 29 additions & 0 deletions codis/pkg/proxy/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package proxy
import (
"bytes"
"hash/crc32"
"strconv"
"strings"

"pika/codis/v2/pkg/proxy/redis"
Expand Down Expand Up @@ -228,6 +229,7 @@ func init() {
{"SUNION", 0},
{"SUNIONSTORE", FlagWrite},
{"SYNC", FlagNotAllow},
{"PCONFIG", 0},
{"TIME", FlagNotAllow},
{"TOUCH", FlagWrite},
{"TTL", 0},
Expand Down Expand Up @@ -318,3 +320,30 @@ func getHashKey(multi []*redis.Resp, opstr string) []byte {
}
return nil
}

func getWholeCmd(multi []*redis.Resp, cmd []byte) int {
var (
index = 0
bytes = 0
)
for i := 0; i < len(multi); i++ {
if index < len(cmd) {
index += copy(cmd[index:], multi[i].Value)
if i < len(multi)-i {
index += copy(cmd[index:], []byte(" "))
}
}
bytes += len(multi[i].Value)

if i == len(multi)-1 && index == len(cmd) {
more := []byte("... " + strconv.Itoa(len(multi)) + " elements " + strconv.Itoa(bytes) + " bytes.")
index = len(cmd) - len(more)
if index < 0 {
index = 0
}
index += copy(cmd[index:], more)
break
}
}
return index
}
Loading

0 comments on commit 20d6957

Please sign in to comment.