-
Notifications
You must be signed in to change notification settings - Fork 170
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
[v2] s3 Blob Store #841
Merged
Merged
[v2] s3 Blob Store #841
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package blobstore | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Layr-Labs/eigenda/common/aws/s3" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
) | ||
|
||
type BlobStore struct { | ||
bucketName string | ||
s3Client s3.Client | ||
logger logging.Logger | ||
} | ||
|
||
func NewBlobStore(s3BucketName string, s3Client s3.Client, logger logging.Logger) *BlobStore { | ||
return &BlobStore{ | ||
bucketName: s3BucketName, | ||
s3Client: s3Client, | ||
logger: logger, | ||
} | ||
} | ||
|
||
// StoreBlob adds a blob to the blob store | ||
func (b *BlobStore) StoreBlob(ctx context.Context, blobKey string, data []byte) error { | ||
err := b.s3Client.UploadObject(ctx, b.bucketName, blobKey, data) | ||
if err != nil { | ||
b.logger.Errorf("failed to upload blob in bucket %s: %v", b.bucketName, err) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// GetBlob retrieves a blob from the blob store | ||
func (b *BlobStore) GetBlob(ctx context.Context, blobKey string) ([]byte, error) { | ||
data, err := b.s3Client.DownloadObject(ctx, b.bucketName, blobKey) | ||
if err != nil { | ||
b.logger.Errorf("failed to download blob from bucket %s: %v", b.bucketName, err) | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package blobstore_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStoreGetBlob(t *testing.T) { | ||
err := blobStore.StoreBlob(context.Background(), "testBlobKey", []byte("testBlobData")) | ||
assert.NoError(t, err) | ||
data, err := blobStore.GetBlob(context.Background(), "testBlobKey") | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("testBlobData"), data) | ||
} | ||
|
||
func TestGetBlobNotFound(t *testing.T) { | ||
data, err := blobStore.GetBlob(context.Background(), "nonExistentBlobKey") | ||
assert.Error(t, err) | ||
assert.Nil(t, data) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we eventually merge the fragmented uploading utility, we will want to revisit this code. A prerequisite to using fragmented uploads will be to store extra metadata for each blob (i.e. fragment size + blob size needed to download without round trips).
No need to wait to merge this PR. The fact that blobs are fragmeneted in S3 should be invisible to things utilizing this API. As long as we don't deploy this code to production environments, a switchover to the fragmented strategy won't be that tricky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we want the fragmented uploading in the blob store. This is not the relay store that stores chunks, but the one that stores whole blobs. I think this simple wrapper can serve the blob store in the long run too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok waiting to have the discussion for how we want to store blobs. It's mostly a question as to whether we want to try and improve latency for really big blobs. Since we don't really support super big blobs currently, it might be something we can avoid dealing with for the MVP.