Skip to content
Open
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
31 changes: 28 additions & 3 deletions backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/tenant"
"github.com/influxdata/influxdb/v2/v1/services/meta"
"go.uber.org/zap"
)

type BucketManifestWriter struct {
ts *tenant.Service
mc *meta.Client
ts *tenant.Service
mc *meta.Client
logger *zap.Logger
}

func NewBucketManifestWriter(ts *tenant.Service, mc *meta.Client) BucketManifestWriter {
Expand All @@ -22,6 +24,10 @@ func NewBucketManifestWriter(ts *tenant.Service, mc *meta.Client) BucketManifest
}
}

func (b *BucketManifestWriter) WithLogger(logger *zap.Logger) {
b.logger = logger
}

// WriteManifest writes a bucket manifest describing all of the buckets that exist in the database.
// It is intended to be used to write to an HTTP response after appropriate measures have been taken
// to ensure that the request is authorized.
Expand All @@ -40,11 +46,30 @@ func (b BucketManifestWriter) WriteManifest(ctx context.Context, w io.Writer) er
}

dbInfo := b.mc.Database(bkt.ID.String())
if dbInfo == nil {
b.logger.Error("Backup: could not find database", zap.String("id", bkt.ID.String()))
continue
}

var description *string
if bkt.Description != "" {
description = &bkt.Description
}
rpManifests := retentionPolicyToManifest(dbInfo.RetentionPolicies)

if b.logger != nil {
for _, rpManifest := range rpManifests {
for _, sg := range rpManifest.ShardGroups {
if len(sg.Shards) <= 0 && sg.DeletedAt == nil {
b.logger.Warn("Backup: ShardGroup has not been deleted and has no shards",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we print the database and retention policy (or bucket, or whatever) here?

zap.String("bucket", bkt.Name),
zap.String("rp", bkt.RetentionPolicyName),
zap.Uint64("shard-group-id", sg.ID), zap.Time("start-time", sg.StartTime),
zap.Time("end-time", sg.EndTime))
}
}
}
}

l = append(l, influxdb.BucketMetadataManifest{
OrganizationID: bkt.OrgID,
Expand All @@ -53,7 +78,7 @@ func (b BucketManifestWriter) WriteManifest(ctx context.Context, w io.Writer) er
BucketName: bkt.Name,
Description: description,
DefaultRetentionPolicy: dbInfo.DefaultRetentionPolicy,
RetentionPolicies: retentionPolicyToManifest(dbInfo.RetentionPolicies),
RetentionPolicies: rpManifests,
})
}

Expand Down
1 change: 1 addition & 0 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) {
ts.BucketService = dbrp.NewBucketService(m.log, ts.BucketService, dbrpSvc)

bucketManifestWriter := backup.NewBucketManifestWriter(ts, metaClient)
bucketManifestWriter.WithLogger(m.log.With(zap.String("service", "bucket-manifest-writer")))

onboardingLogger := m.log.With(zap.String("handler", "onboard"))
onboardOpts := []tenant.OnboardServiceOptionFn{tenant.WithOnboardingLogger(onboardingLogger)}
Expand Down
12 changes: 12 additions & 0 deletions http/restore_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ func (h *RestoreHandler) handleRestoreBucketMetadata(w http.ResponseWriter, r *h
return
}

for _, rps := range b.RetentionPolicies {
for _, sg := range rps.ShardGroups {
if len(sg.Shards) <= 0 && sg.DeletedAt == nil {
h.Logger.Warn("Restore: ShardGroup has not been deleted and has no shards",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comment above, can we print the database and retention policy, or bucket, or whatever?

zap.String("bucket", b.BucketName),
zap.String("rp", rps.Name),
zap.Uint64("shard-group-id", sg.ID), zap.Time("start-time", sg.StartTime),
zap.Time("end-time", sg.EndTime))
}
}
}

// Create the bucket - This will fail if the bucket already exists.
// TODO: Could we support restoring to an existing bucket?
var description string
Expand Down