Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

storage: extend the ExternalStorage interface and implements #446

Merged
merged 17 commits into from
Aug 13, 2020

Conversation

glorv
Copy link
Collaborator

@glorv glorv commented Jul 30, 2020

What problem does this PR solve?

extend the ExternalStorage interface and implement the new methods for local and s3 storage. This extension is currently used in lightning to support restore from s3 storage.

What is changed and how it works?

Add new methods for ExternalStorage:

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

type ExtrenalStorage interface {
	// Open a Reader by file name
	Open(ctx context.Context, name string) (ReadSeekCloser, error)
	// WalkDir traverse all the files in a dir
	WalkDir(ctx context.Context, fn func(string, int64) error) error
}

Since s3 GetObject does not provide seek directly, we implement this by: 1) read and skip the bytes if the distance is small, else we open a new reader set the start position to the seek position.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change

Side effects

Related changes

Release Note

  • No release note

@glorv glorv requested review from kennytm and 3pointer July 30, 2020 07:39
pkg/storage/s3.go Outdated Show resolved Hide resolved
pkg/storage/s3.go Outdated Show resolved Hide resolved
pkg/storage/s3.go Outdated Show resolved Hide resolved
pkg/storage/gcs.go Show resolved Hide resolved
@glorv
Copy link
Collaborator Author

glorv commented Jul 31, 2020

/run-all-tests

1 similar comment
@glorv
Copy link
Collaborator Author

glorv commented Aug 3, 2020

/run-all-tests

Comment on lines 10 to 13
func DefineFlags(flags *pflag.FlagSet) {
defineS3Flags(flags)
DefineS3Flags(flags)
defineGCSFlags(flags)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the rationale of only exposing S3 but not GCS?

@glorv
Copy link
Collaborator Author

glorv commented Aug 3, 2020

@kennytm Shall we change the s3 and gcs flag definitions from pflag to flag so that lightning can share the same definitions without migrating into pflag?

@kennytm
Copy link
Collaborator

kennytm commented Aug 3, 2020

@glorv we don't really need those flags since they can be passed via URL parameters (s3://bucket/prefix?region=us-east-1 etc).

Given that pflag refuses to support -long-options, migrating Lightning to pflag requires approval of products dept.

Comment on lines +373 to +378
// FIXME: we test in minio, when request with Range, the result.AcceptRanges is a bare string 'range',
// not sure whether this is a feature or bug
//if rangeOffset != nil && (result.AcceptRanges == nil || *result.AcceptRanges != *rangeOffset) {
// return nil, errors.Errorf("open file '%s' failed, expected range: %s, got: %v",
// name, *rangeOffset, result.AcceptRanges)
//}
Copy link
Member

Choose a reason for hiding this comment

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

Have we tested in AWS S3?

Comment on lines +77 to +78
// export for test.
func NewLocalStorage(base string) (*LocalStorage, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Where is the test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

used in lightning tests

return realOffset, nil
}

// if seek ahead no more than 64k, we read add drop these data
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// if seek ahead no more than 64k, we read add drop these data
// if seek ahead no more than 64k, we discard these data

return 0, err
}

newReader, err := r.storage.open(context.Background(), r.name, realOffset, 0)
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid use Background context.

@glorv
Copy link
Collaborator Author

glorv commented Aug 10, 2020

/run-all-tests

1 similar comment
@glorv
Copy link
Collaborator Author

glorv commented Aug 10, 2020

/run-all-tests

@overvenus
Copy link
Member

LGTM

@ti-srebot ti-srebot added the status/LGT1 LGTM1 label Aug 11, 2020
@overvenus
Copy link
Member

/run-all-tests

Copy link
Collaborator

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT1 LGTM1 label Aug 11, 2020
@ti-srebot ti-srebot added the status/LGT2 LGTM2 label Aug 11, 2020
@overvenus
Copy link
Member

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 1ab8511 into pingcap:master Aug 13, 2020
glorv added a commit to glorv/br that referenced this pull request Aug 17, 2020
…ap#446)

* update storage

* update

* fix

* export s3 flags

* fix local path

* fix s3 reader

* fix range offset

* fix the req range errors

* fix comments

* fix review comments

* fix some comments

* update

* fix

* update

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
3pointer pushed a commit that referenced this pull request Aug 17, 2020
…#462)

* update storage

* update

* fix

* export s3 flags

* fix local path

* fix s3 reader

* fix range offset

* fix the req range errors

* fix comments

* fix review comments

* fix some comments

* update

* fix

* update

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
@glorv glorv deleted the storage branch April 8, 2021 04:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants