Removed debug print statements in acl.go file

This commit is contained in:
Kelvin Clement Mwinuka
2024-06-05 21:44:00 +08:00
parent 66b2842e11
commit ee13c29c9a
4 changed files with 1280 additions and 1270 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -101,6 +101,7 @@ type EchoVault struct {
listener atomic.Value // Holds the TCP listener. listener atomic.Value // Holds the TCP listener.
quit chan struct{} // Channel that signals the closing of all client connections. quit chan struct{} // Channel that signals the closing of all client connections.
stopTTL chan struct{} // Channel that signals the TTL sampling goroutine to stop execution.
} }
// WithContext is an options that for the NewEchoVault function that allows you to // WithContext is an options that for the NewEchoVault function that allows you to
@@ -145,7 +146,8 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
commands = append(commands, str.Commands()...) commands = append(commands, str.Commands()...)
return commands return commands
}(), }(),
quit: make(chan struct{}), quit: make(chan struct{}),
stopTTL: make(chan struct{}),
} }
for _, option := range options { for _, option := range options {
@@ -274,9 +276,14 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
if echovault.config.EvictionPolicy != constants.NoEviction { if echovault.config.EvictionPolicy != constants.NoEviction {
go func() { go func() {
ticker := time.NewTicker(echovault.config.EvictionInterval) ticker := time.NewTicker(echovault.config.EvictionInterval)
for _ = range ticker.C { for {
if err := echovault.evictKeysWithExpiredTTL(context.Background()); err != nil { select {
log.Printf("evict with ttl: %v\n", err) case <-ticker.C:
if err := echovault.evictKeysWithExpiredTTL(context.Background()); err != nil {
log.Printf("evict with ttl: %v\n", err)
}
case <-echovault.stopTTL:
break
} }
} }
}() }()
@@ -555,6 +562,7 @@ func (server *EchoVault) rewriteAOF() error {
func (server *EchoVault) ShutDown() { func (server *EchoVault) ShutDown() {
if server.listener.Load() != nil { if server.listener.Load() != nil {
go func() { server.quit <- struct{}{} }() go func() { server.quit <- struct{}{} }()
go func() { server.stopTTL <- struct{}{} }()
log.Println("closing tcp listener...") log.Println("closing tcp listener...")
if err := server.listener.Load().(net.Listener).Close(); err != nil { if err := server.listener.Load().(net.Listener).Close(); err != nil {
log.Printf("listener close: %v\n", err) log.Printf("listener close: %v\n", err)

View File

@@ -70,14 +70,14 @@ func getBindAddr() net.IP {
} }
func setupServer( func setupServer(
serverId string, serverId string,
bootstrapCluster bool, bootstrapCluster bool,
forwardCommand bool, forwardCommand bool,
bindAddr, bindAddr,
joinAddr string, joinAddr string,
port, port,
raftPort, raftPort,
mlPort int, mlPort int,
) (*EchoVault, error) { ) (*EchoVault, error) {
conf := DefaultConfig() conf := DefaultConfig()
conf.DataDir = "./testdata" conf.DataDir = "./testdata"

View File

@@ -435,8 +435,6 @@ func (acl *ACL) AuthorizeConnection(conn *net.Conn, cmd []string, command intern
} }
// 9. Check if write keys are in IncludedWriteKeys // 9. Check if write keys are in IncludedWriteKeys
fmt.Println("KEYS: ", writeKeys)
fmt.Println("ALLOWED KEYS: ", connection.User.IncludedWriteKeys)
if !slices.ContainsFunc(writeKeys, func(key string) bool { if !slices.ContainsFunc(writeKeys, func(key string) bool {
return slices.ContainsFunc(connection.User.IncludedWriteKeys, func(writeKeyGlob string) bool { return slices.ContainsFunc(connection.User.IncludedWriteKeys, func(writeKeyGlob string) bool {
if acl.GlobPatterns[writeKeyGlob].Match(key) { if acl.GlobPatterns[writeKeyGlob].Match(key) {