Skip to content

Commit

Permalink
Fixing master build by making map store size and eviction configurabl…
Browse files Browse the repository at this point in the history
…e for test server (#876)
  • Loading branch information
lucifercr07 authored Sep 30, 2024
1 parent 180beef commit fb59ab3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Config struct {
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
StoreMapInitSize int `mapstructure:"storemapinitsize"`
} `mapstructure:"server"`
Auth struct {
UserName string `mapstructure:"username"`
Expand Down Expand Up @@ -100,6 +101,7 @@ var baseConfig = Config{
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
StoreMapInitSize int `mapstructure:"storemapinitsize"`
}{
Addr: DefaultHost,
Port: DefaultPort,
Expand All @@ -120,6 +122,7 @@ var baseConfig = Config{
LogLevel: "info",
PrettyPrintLogs: false,
EnableMultiThreading: false,
StoreMapInitSize: 1024000,
},
Auth: struct {
UserName string `mapstructure:"username"`
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -45,8 +44,9 @@ require (
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831
github.com/gorilla/websocket v1.5.3
github.com/google/btree v1.1.3
github.com/google/go-cmp v0.6.0
github.com/gorilla/websocket v1.5.3
github.com/ohler55/ojg v1.24.0
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/xid v1.6.0
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/commands/async/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ func fireCommandAndGetRESPParser(conn net.Conn, cmd string) *clientio.RESPParser
}

func RunTestServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerOptions) {
// Override configs to test server config, this is enabled to handle test env runs
// as those envs are resource constrained
config.DiceConfig.Network.IOBufferLength = 16
config.DiceConfig.Server.WriteAOFOnCleanup = false
config.DiceConfig.Server.StoreMapInitSize = 1024
config.DiceConfig.Server.EvictionRatio = 0.4
config.DiceConfig.Server.KeysLimit = 2000000

if opt.Port != 0 {
config.DiceConfig.Server.Port = opt.Port
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/server/max_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func TestMaxConnection(t *testing.T) {

var maxConnLimit = maxConnTestOptions.MaxClients + 2
connections := make([]net.Conn, maxConnLimit)
defer func() {
// Ensure all connections are closed at the end of the test
for _, conn := range connections {
if conn != nil {
conn.Close()
}
}
}()

for i := 0; i < maxConnLimit; i++ {
conn, err := getConnection(maxConnTestOptions.Port)
if err == nil {
Expand All @@ -51,6 +60,8 @@ func TestMaxConnection(t *testing.T) {
result := commands.FireCommand(connections[0], "ABORT")
if result != "OK" {
t.Fatalf("Unexpected response to ABORT command: %v", result)
} else {
slog.Info("Closed server for max_conn_test")
}
wg.Wait()
}
4 changes: 3 additions & 1 deletion integration_tests/server/server_abort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestServerRestartAfterAbort(t *testing.T) {

conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", config.DiceConfig.Server.Port))
if err != nil {
t.Fatalf("Server should be running after restart: %v", err)
t.Fatalf("Server should be running at start: %v", err)
}

// Send ABORT command to shut down server
Expand All @@ -100,9 +100,11 @@ func TestServerRestartAfterAbort(t *testing.T) {

// wait for the server to shut down
time.Sleep(2 * time.Second)
testServerOptions.Logger.Info("Wait completed for server shutdown")

wg.Wait()

testServerOptions.Logger.Info("Restarting server after abort for server_abort_test")
// restart server
ctx2, cancel2 := context.WithCancel(context.Background())
t.Cleanup(cancel2)
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/hmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ func (h HashMap) incrementFloatValue(field string, incr float64) (string, error)
h[field] = fmt.Sprintf("%v", total)

return strValue, nil
}
}
2 changes: 1 addition & 1 deletion internal/server/cmd_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
WorkerCmdsMeta = map[string]CmdsMeta{}

// Metadata for global commands that don't interact with shards.
// INFO and PING are examples of global commands.
// PING is an example of global command.
pingCmdMeta = CmdsMeta{
Cmd: "PING",
CmdType: Global,
Expand Down
8 changes: 4 additions & 4 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ type Store struct {

func NewStore(watchChan chan WatchEvent) *Store {
return &Store{
store: swiss.New[string, *object.Obj](1024000),
expires: swiss.New[*object.Obj, uint64](1024000),
store: swiss.New[string, *object.Obj](config.DiceConfig.Server.StoreMapInitSize),
expires: swiss.New[*object.Obj, uint64](config.DiceConfig.Server.StoreMapInitSize),
watchChan: watchChan,
}
}

func ResetStore(store *Store) *Store {
store.numKeys = 0
store.store = swiss.New[string, *object.Obj](1024000)
store.expires = swiss.New[*object.Obj, uint64](1024000)
store.store = swiss.New[string, *object.Obj](config.DiceConfig.Server.StoreMapInitSize)
store.expires = swiss.New[*object.Obj, uint64](config.DiceConfig.Server.StoreMapInitSize)

return store
}
Expand Down

0 comments on commit fb59ab3

Please sign in to comment.