Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPS-1338 Fix nil dereference on backup reading #259

Merged
merged 6 commits into from
Nov 17, 2024
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.4.1
github.com/aerospike/aerospike-client-go/v7 v7.7.2
github.com/aerospike/aerospike-management-lib v1.5.0
github.com/aerospike/backup-go v0.1.1-0.20241111111428-0deeec9dd7a4
github.com/aerospike/backup-go v0.1.1-0.20241117160503-5fa2b88f8443
github.com/aws/aws-sdk-go-v2/config v1.28.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2
github.com/aws/smithy-go v1.22.0
Expand Down Expand Up @@ -43,7 +43,7 @@ require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.3 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.4 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.42 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ github.com/aerospike/aerospike-client-go/v7 v7.7.2 h1:RWoeEA4ofk+uDZuArrhmBaBKWw
github.com/aerospike/aerospike-client-go/v7 v7.7.2/go.mod h1:STlBtOkKT8nmp7iD+sEkr/JGEOu+4e2jGlNN0Jiu2a4=
github.com/aerospike/aerospike-management-lib v1.5.0 h1:uAEaBU+PkzbtwsSrPVokLIUeJaDrFSMtwqeCKba3xIs=
github.com/aerospike/aerospike-management-lib v1.5.0/go.mod h1:hsEptY/AmTmHoJnItJNmfJ4yCMG8LIB8YPnIpIyvGXI=
github.com/aerospike/backup-go v0.1.1-0.20241111111428-0deeec9dd7a4 h1:Gvj5D/LQV+ZMZsrusk3grOvgBW5SiBreY824zrptdVY=
github.com/aerospike/backup-go v0.1.1-0.20241111111428-0deeec9dd7a4/go.mod h1:UbeAI+l58yuq/oGBCjKNhd3dGRMX/w9hnUyFUZBPUcs=
github.com/aws/aws-sdk-go-v2 v1.32.3 h1:T0dRlFBKcdaUPGNtkBSwHZxrtis8CQU17UpNBZYd0wk=
github.com/aws/aws-sdk-go-v2 v1.32.3/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
github.com/aerospike/backup-go v0.1.1-0.20241117160503-5fa2b88f8443 h1:bwwrkvyNEgBvH1RL4nz1DsiTGhu7fbSYqfKfBlM2pro=
github.com/aerospike/backup-go v0.1.1-0.20241117160503-5fa2b88f8443/go.mod h1:gfQFGXR4pD2BEWYwVltIzuRcYqhWFlJs2ARm7w+1nQA=
github.com/aws/aws-sdk-go-v2 v1.32.4 h1:S13INUiTxgrPueTmrm5DZ+MiAo99zYzHEFh1UNkOxNE=
github.com/aws/aws-sdk-go-v2 v1.32.4/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA=
github.com/aws/aws-sdk-go-v2/config v1.28.1 h1:oxIvOUXy8x0U3fR//0eq+RdCKimWI900+SV+10xsCBw=
Expand Down
1 change: 1 addition & 0 deletions internal/server/handlers/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (s *Service) readBackupsForRoutine(w http.ResponseWriter, r *http.Request,
backups, err := backupListFunction(r.Context(), timeBounds.ToModel())
if err != nil {
hLogger.Error("failed to retrieve backup list",
slog.String("routine", routine),
slog.Bool("isFullBackup", isFullBackup),
slog.Any("timeBounds", timeBounds),
slog.Any("error", err),
Expand Down
4 changes: 2 additions & 2 deletions pkg/dto/backup_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func ConvertBackupDetailsMap(modelMap map[string][]model.BackupDetails) map[stri
result := make(map[string][]BackupDetails, len(modelMap))
for key, modelSlice := range modelMap {
dtoSlice := make([]BackupDetails, len(modelSlice))
for i, m := range modelSlice {
dtoSlice[i] = *NewBackupDetailsFromModel(&m)
for i := range modelSlice {
dtoSlice[i] = *NewBackupDetailsFromModel(&modelSlice[i])
}
result[key] = dtoSlice
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/dto/base_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ func Deserialize(v any, r io.Reader, format SerializationFormat) error {
// ConvertModelsToDTO converts an array of models to an array of DTOs
func ConvertModelsToDTO[M any, D any](models []M, dtoConstructor func(*M) D) []D {
result := make([]D, len(models))
for i, model := range models {
result[i] = dtoConstructor(&model)
for i := range models {
result[i] = dtoConstructor(&models[i])
}
return result
}

// ConvertModelMapToDTO converts a map of models to a map of DTOs
func ConvertModelMapToDTO[M any, D any](modelMap map[string]*M, dtoConstructor func(*M) *D) map[string]*D {
result := make(map[string]*D, len(modelMap))
for key, model := range modelMap {
result[key] = dtoConstructor(model)
for key, m := range modelMap {
result[key] = dtoConstructor(m)
}
return result
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/service/aerospike_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func getAllNamespacesOfCluster(client backup.AerospikeClient) ([]string, error)
return nil, fmt.Errorf("failed to get cluster info: %w", err)
}
namespaces := infoRes[namespaceInfo]
slog.Debug("Retrieved namespace info", "result", namespaces)

return strings.Split(namespaces, ";"), nil
}

Expand Down Expand Up @@ -139,3 +141,13 @@ func getActiveHosts(client backup.AerospikeClient) []*as.Host {

return activeHosts
}

// resolveBackupNamespaces returns the list of namespaces to back up.
// If `namespaces` is empty, it fetches all namespaces from the cluster via the provided client.
func resolveNamespaces(namespaces []string, client backup.AerospikeClient) ([]string, error) {
if len(namespaces) == 0 {
return getAllNamespacesOfCluster(client)
}

return namespaces, nil
}
2 changes: 1 addition & 1 deletion pkg/service/backup_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (b *BackupBackend) readMetadataList(ctx context.Context, timebounds *model.
if errors.Is(err, os.ErrNotExist) || strings.Contains(err.Error(), "is empty") {
return nil, nil
}
return nil, err
return nil, fmt.Errorf("read metadata files error: %w", err)
}

var backups []model.BackupDetails
Expand Down
12 changes: 2 additions & 10 deletions pkg/service/backup_routine_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ func newBackupRoutineHandler(
}
}

func getNamespacesToBackup(namespaces []string, client backup.AerospikeClient) ([]string, error) {
if len(namespaces) == 0 {
return getAllNamespacesOfCluster(client)
}

return namespaces, nil
}

func (h *BackupRoutineHandler) runFullBackup(ctx context.Context, now time.Time) {
duration, err := util.MeasureDuration(func() error {
return h.runFullBackupInternal(ctx, now)
Expand Down Expand Up @@ -158,7 +150,6 @@ func (h *BackupRoutineHandler) runFullBackupInternal(ctx context.Context, now ti
return err
}

// update the state
h.state.SetLastFullRun(now)

if h.backupFullPolicy.RemoveFiles.RemoveIncrementalBackup() {
Expand All @@ -182,7 +173,7 @@ func (h *BackupRoutineHandler) prepareCluster(retry executor) (*backup.Client, [
if err != nil {
return fmt.Errorf("cannot get backup client: %w", err)
}
namespaces, err = getNamespacesToBackup(h.namespaces, client.AerospikeClient())
namespaces, err = resolveNamespaces(h.namespaces, client.AerospikeClient())
if err != nil {
return fmt.Errorf("cannot retrieve namespaces from source cluster: %w", err)
}
Expand Down Expand Up @@ -274,6 +265,7 @@ func (h *BackupRoutineHandler) deleteFolder(ctx context.Context, path string) {
if err != nil {
h.logger.Error("Could not delete folder", slog.Any("err", err))
}
h.logger.Debug("Deleted folder", slog.String("path", path))
}

func (h *BackupRoutineHandler) runIncrementalBackup(ctx context.Context, now time.Time) {
Expand Down
Loading