ByteStorage / FlyDB

The high-performance kv storage engine based on bitcask paper made in golang
Apache License 2.0
1.22k stars 99 forks source link

Cli supports zset data structures (#249) #310

Closed halalala222 closed 1 month ago

halalala222 commented 1 month ago

1. prevent repeated creation of grpc connections and various command clients to avoid goroutine leaks and reduce the number of goroutines created.

before pr :

use go pprof tools

flyDB client start

HvUjdftMFV

run put test test 11 times

LEQONJJeQm

after run put test test 11 times

mpNMBhxNJS

cause by :

The specified call for each gRPC client will create a gRPC connection using grpc.Dial. However, after the call is executed, the connection will not be closed.

example : string put

// newGrpcClient returns a grpc client
func newGrpcClient(addr string) (gstring.GStringServiceClient, error) {
    conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
       return nil, err
    }
    client := gstring.NewGStringServiceClient(conn)
    return client, nil
}
// Put puts a key-value pair into the db by client api
func (c *Client) Put(key string, value interface{}) error {
    client, err := newGrpcClient(c.Addr)
    if err != nil {
        return errors.New("new grpc client error: " + err.Error())
    }
    //...
    return nil
}

after pr :

flyDB client start

2mlTP7bleC

run put test test 17 times

d2579121-15a8-4bfe-b729-30863a5ee532

after run put test test 17 times

N0r4Pfw17A

2. cli support zset

note : for ZAdds , Grumble does not support having multiple lists within multiple args,because no args can follow a list. Therefore, it is not possible to implement this functionality.

image image

qishenonly commented 1 month ago

Thank you very much for solving potential security vulnerabilities in FlyDB. After we check that your code is correct, we will merge your pr into the main branch tomorrow.