Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Nov 3, 2024
1 parent d090ed2 commit 23db731
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
36 changes: 19 additions & 17 deletions pkg/service/aerospike_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,22 @@ func (nv *defaultNamespaceValidator) MissingNamespaces(
cluster *model.AerospikeCluster,
namespaces []string,
) []string {
//if len(namespaces) == 0 {
return nil
//}
//
//backupClient, err := nv.ClientManager.GetClient(cluster)
//if err != nil {
// slog.Info("Failed to connect to aerospike cluster", slog.Any("error", err))
// return nil
//}
//defer nv.ClientManager.Close(backupClient)
//
//namespacesInCluster, err := getAllNamespacesOfCluster(backupClient.AerospikeClient())
//if err != nil {
// slog.Info("Failed to retrieve namespaces from cluster", slog.Any("error", err))
//}
//
//return util.MissingElements(namespaces, namespacesInCluster)
if len(namespaces) == 0 {
return nil
}
backupClient, err := nv.ClientManager.GetClient(cluster)
if err != nil {
slog.Info("Failed to connect to aerospike cluster", slog.Any("error", err))
return nil
}
defer nv.ClientManager.Close(backupClient)

namespacesInCluster, err := getAllNamespacesOfCluster(backupClient.AerospikeClient())
if err != nil {
slog.Info("Failed to retrieve namespaces from cluster", slog.Any("error", err))
}

return util.MissingElements(namespaces, namespacesInCluster)
}

func (nv *defaultNamespaceValidator) ValidateRoutines(cluster *model.AerospikeCluster, config *model.Config) error {
Expand Down Expand Up @@ -89,14 +88,17 @@ func filterRoutinesByCluster(

// getAllNamespacesOfCluster retrieves a list of all namespaces in an Aerospike cluster.
func getAllNamespacesOfCluster(client backup.AerospikeClient) ([]string, error) {
slog.Info("Retrieving namespaces")
node, err := client.Cluster().GetRandomNode()
if err != nil {
return nil, fmt.Errorf("failed to get node: %w", err)
}
slog.Info("Got node")
infoRes, err := node.RequestInfo(&as.InfoPolicy{}, namespaceInfo)
if err != nil {
return nil, fmt.Errorf("failed to get cluster info: %w", err)
}
slog.Info("Received response")
namespaces := infoRes[namespaceInfo]
return strings.Split(namespaces, ";"), nil
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/service/client_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"fmt"
"log/slog"
"sync"
"time"

Expand Down Expand Up @@ -70,13 +71,16 @@ func (cm *ClientManagerImpl) GetClient(cluster *model.AerospikeCluster) (*backup
info.closeTimer = nil
}
info.count++
slog.Info("Got client from cache")
return info.client, nil
}

slog.Info("Creating new client")
client, err := cm.createClient(cluster)
if err != nil {
return nil, fmt.Errorf("cannot create backup client: %w", err)
}
slog.Info("Created new client")

cm.clients[cluster] = &clientInfo{
client: client,
Expand Down Expand Up @@ -113,8 +117,10 @@ func (cm *ClientManagerImpl) Close(client *backup.Client) {

for id, info := range cm.clients {
if info.client == client {
slog.Info("Decreasing client reference counter")
info.count--
if info.count == 0 {
slog.Info("Scheduling client closing")
info.closeTimer = cm.scheduleClosing(id)
}
return
Expand All @@ -134,6 +140,7 @@ func (cm *ClientManagerImpl) scheduleClosing(cluster *model.AerospikeCluster) *t

// Check if the client still exists and count is still 0
if info, exists := cm.clients[cluster]; exists && info.count == 0 {
slog.Info("Closing unused client")
info.client.AerospikeClient().Close()
delete(cm.clients, cluster)
}
Expand Down

0 comments on commit 23db731

Please sign in to comment.