Skip to content
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ case err != nil:

### 对外契约只有两样

`client` 包(本 SDK)与上面的 BanNet 协议规范。除此之外的包都是内部实现,可能随版本变动。
`client`(SDK)、`proto`(协议常量与编解码)、`predicate`(SCAN 谓词)三个包,加上上面的
BanNet 协议规范。这一边界由编译器强制:其余实现包都在 `internal/` 之下,模块外无法导入。

仓库内另有一条 gRPC 传输(`internal/kvgrpc`),但它**不是对外接口**,已置于 `internal/`
之下由编译器强制——模块外无法导入。把 `.proto` 交给使用方自行生成客户端,等于把内部传输
Expand Down
2 changes: 1 addition & 1 deletion bannet/wire_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/NeverENG/BanDB/bannet"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/proto"
)

// TestScanResponseSurvivesWire 复现并守护 SCAN 的网络缝:一个多条命中的响应
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
"sync/atomic"
"time"

"github.com/NeverENG/BanDB/pkg/predicate"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/predicate"
"github.com/NeverENG/BanDB/proto"
)

// 默认参数。均可经 Options 覆盖。
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/NeverENG/BanDB/bannet"
"github.com/NeverENG/BanDB/client"
"github.com/NeverENG/BanDB/config"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/proto"
"github.com/NeverENG/BanDB/service"
)

Expand Down
2 changes: 1 addition & 1 deletion client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net"
"time"

"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/proto"
)

// 线格式(与 pkg/proto 的包注释一致,服务端对应实现为 bannet.DataPack):
Expand Down
2 changes: 1 addition & 1 deletion client/wire_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/NeverENG/BanDB/bannet"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/proto"
)

// TestFrameEncodingMatchesServer 交叉校验 SDK 的帧编码与服务端实现逐字节一致。
Expand Down
22 changes: 17 additions & 5 deletions cmd/ban-bench/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"time"

"github.com/NeverENG/BanDB/bannet"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/pkg/utils"
"github.com/NeverENG/BanDB/proto"
)

type Config struct {
Expand Down Expand Up @@ -315,7 +314,7 @@ func put(conn *net.TCPConn, key, value []byte) error {
binary.LittleEndian.PutUint32(keyLen, uint32(len(key)))
binary.LittleEndian.PutUint32(valLen, uint32(len(value)))

data := utils.ByteBuilder(keyLen, valLen, key, value)
data := concatBytes(keyLen, valLen, key, value)
if err := send(conn, proto.MsgPut, data); err != nil {
return err
}
Expand All @@ -333,7 +332,7 @@ func put(conn *net.TCPConn, key, value []byte) error {
func get(conn *net.TCPConn, key []byte) ([]byte, error) {
keyLen := make([]byte, 4)
binary.LittleEndian.PutUint32(keyLen, uint32(len(key)))
data := utils.ByteBuilder(keyLen, key)
data := concatBytes(keyLen, key)

if err := send(conn, proto.MsgGet, data); err != nil {
return nil, err
Expand All @@ -359,7 +358,7 @@ func get(conn *net.TCPConn, key []byte) ([]byte, error) {
func del(conn *net.TCPConn, key []byte) error {
keyLen := make([]byte, 4)
binary.LittleEndian.PutUint32(keyLen, uint32(len(key)))
data := utils.ByteBuilder(keyLen, key)
data := concatBytes(keyLen, key)

if err := send(conn, proto.MsgDelete, data); err != nil {
return err
Expand All @@ -379,3 +378,16 @@ func makeKey(idx int, keySize int) []byte {
s := fmt.Sprintf("%0*x", keySize, idx)
return []byte(s)
}

// concatBytes 按总长度一次分配后拼接多个字节切片。
func concatBytes(parts ...[]byte) []byte {
n := 0
for _, p := range parts {
n += len(p)
}
out := make([]byte, 0, n)
for _, p := range parts {
out = append(out, p...)
}
return out
}
2 changes: 1 addition & 1 deletion cmd/ban-cli/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

bandb "github.com/NeverENG/BanDB/client"
"github.com/NeverENG/BanDB/pkg/predicate"
"github.com/NeverENG/BanDB/predicate"
)

// cmdTimeout 是交互模式下单条命令的超时。
Expand Down
4 changes: 2 additions & 2 deletions cmd/ban-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/NeverENG/BanDB/bannet"
"github.com/NeverENG/BanDB/pkg/metrics"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/internal/metrics"
"github.com/NeverENG/BanDB/proto"
"github.com/NeverENG/BanDB/service"
"github.com/NeverENG/BanDB/service/ingesthook"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ban-server/server_pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/NeverENG/BanDB/bannet"
"github.com/NeverENG/BanDB/pkg/metrics"
"github.com/NeverENG/BanDB/pkg/proto"
"github.com/NeverENG/BanDB/internal/metrics"
"github.com/NeverENG/BanDB/proto"
"github.com/NeverENG/BanDB/service"
"github.com/NeverENG/BanDB/service/ingesthook"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions pkg/utils/byteBuilder.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/proto/scan.go → proto/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/binary"
"fmt"

"github.com/NeverENG/BanDB/pkg/predicate"
"github.com/NeverENG/BanDB/predicate"
)

// SCAN 请求负载布局(小端):
Expand Down
2 changes: 1 addition & 1 deletion pkg/proto/scan_test.go → proto/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"testing"

"github.com/NeverENG/BanDB/pkg/predicate"
"github.com/NeverENG/BanDB/predicate"
)

func TestScanRequestRoundTrip(t *testing.T) {
Expand Down
Loading
Loading