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

feat: metadata backup returns bucket manifests #21601

Merged
merged 6 commits into from
Jun 4, 2021

Conversation

williamhbaker
Copy link
Contributor

@williamhbaker williamhbaker commented Jun 3, 2021

Closes #21567

This PR finishes the implementation of the backup/metadata endpoint with the full array of bucket data manifests as described in https://github.com/influxdata/openapi/blob/master/src/oss/schemas/BucketMetadataManifests.yml etc.

I also modified the logic for handleBackupMetadata to use CreatePart instead of CreateFormFile. This seems more appropriate for the multipart/mixed response type, although it does require manually setting more of the headers.

I haven't come up with an easy way to unit test the WriteManifest function. Ideally we would have an end-to-end test of some kind that would cover it as well as the entire backup/metadata endpoint to make sure the response can actually be parsed, processed, and successfully restored eventually.

@williamhbaker williamhbaker requested a review from danxmoran June 3, 2021 20:29
Copy link
Contributor

@danxmoran danxmoran left a comment

Choose a reason for hiding this comment

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

LGTM

backup/backup.go Outdated
return err
}

l := []influxdb.BucketMetadataManifest{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could do this as a small optimization:

l := make([]influxdb.BucketMetadataManifest, 0, len(bkts))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! I did that for this and the other similar functions.

backup/backup.go Outdated
// retentionPolicyToManifest and the various similar functions that follow are for converting
// from the structs in the meta package to the manifest structs
func retentionPolicyToManifest(meta []meta.RetentionPolicyInfo) []influxdb.RetentionPolicyManifest {
r := []influxdb.RetentionPolicyManifest{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could pre-set the capacity here via make but it's probably less important since buckets in 2.x only have 1 retention policy

// 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.
func (b BucketManifestWriter) WriteManifest(ctx context.Context, w io.Writer) error {
bkts, _, err := b.ts.FindBuckets(ctx, influxdb.BucketFilter{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Making sure: in a "real" DB this call (and the calls to OrganizationService) don't try to take a lock on the KV store, right? i.e. we don't deadlock here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They both need read locks, for example the FindBuckets goes through here & FindOrganizationByID go through here, both of which end up getting the lock here.

The handleBackupMetadata gets a read lock on the KV at the start of the process and holds it until the end. So once the handler has the lock, the subsequent calls in the process can also get a read lock.

That all sounds great of course, but one other thing I forgot to mention in the initial comment is that I am actually able to successfully hit the api/v2/backup/metadata endpoint and everything works fine, so that's some verification that it doesn't deadlock 😄

@williamhbaker williamhbaker merged commit 34a4a8e into master Jun 4, 2021
@williamhbaker williamhbaker deleted the wb-bucket-manifest-21584 branch June 4, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement new backup API to include sqlite
2 participants