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

[v2] Blob Metadata Store #818

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ian-shim
Copy link
Contributor

Why are these changes needed?

Set up v2 blob metadata store. Only implements few basic methods for now.

Checks

  • I've made sure the lint is passing in this PR.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

core/data.go Outdated Show resolved Hide resolved
@ian-shim ian-shim marked this pull request as ready for review October 18, 2024 06:13
return &dynamodb.CreateTableInput{
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: aws.String("PK"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you document the tables that are abbreviations? It's not obvious to me what PK and SK stand for.


blobKeyPrefix = "BlobKey#"
dispersalIDPrefix = "DispersalID#"
blobMetadataSK = "BlobMetadata"
Copy link
Collaborator

@pschork pschork Oct 18, 2024

Choose a reason for hiding this comment

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

So we're not using immutable design where blob metadata updates create a new unique sortable item via compound SK like BlobMetadata#UUID7 or BlobMetadata#EpochSeconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah as discussed offline, some fields (BlobStatus) will be updated

Comment on lines 14 to 32
type BlobMetadata struct {
core.BlobHeaderV2 `json:"blob_header"`

BlobKey core.BlobKey `json:"blob_key"`
BlobStatus BlobStatus `json:"blob_status"`
// Expiry is Unix timestamp of the blob expiry in seconds from epoch
Expiry uint64 `json:"expiry"`
NumRetries uint `json:"num_retries"`
BlobSize uint64 `json:"blob_size"`
RequestedAt uint64 `json:"requested_at"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a high level struct that will get reused in a bunch of places, would it be worth while to add godocs? (This request is non-blocking, feel free to disregard it if you don't think they are worthwile.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call

Comment on lines 10 to 16
type BlobMetadataStore interface {
PutBlobMetadata(ctx context.Context, metadata *v2.BlobMetadata) error
GetBlobMetadata(ctx context.Context, blobKey core.BlobKey) (*v2.BlobMetadata, error)
GetBlobMetadataByStatus(ctx context.Context, status v2.BlobStatus) ([]*v2.BlobMetadata, error)
GetBlobMetadataCountByStatus(ctx context.Context, status v2.BlobStatus) (int32, error)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add godocs if you think it's worth it. (This request is non-blocking, feel free to disregard it if you don't think they are worthwile.)

return &dynamodb.CreateTableInput{
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: aws.String("PK"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you document the tables that are abbreviations? It's not obvious to me what PK and SK stand for.

Comment on lines 14 to 32
type BlobMetadata struct {
core.BlobHeaderV2 `json:"blob_header"`

BlobKey core.BlobKey `json:"blob_key"`
BlobStatus BlobStatus `json:"blob_status"`
// Expiry is Unix timestamp of the blob expiry in seconds from epoch
Expiry uint64 `json:"expiry"`
NumRetries uint `json:"num_retries"`
BlobSize uint64 `json:"blob_size"`
RequestedAt uint64 `json:"requested_at"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this eventually contain information such as blob header and/or blob cert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It already includes blob header. It represents an disperser internal record tracked in DB. Blob cert will be a separate type and we can probably reuse what's defined in core/v2

data = append(data, paymentBytes...)

return crypto.Keccak256(data)
func (pm *PaymentMetadata) Hash() ([32]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this hash function to make it compatible with solidity
cc @hopeyen

Copy link
Contributor

@mooselumph mooselumph left a comment

Choose a reason for hiding this comment

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

looks good!

OperatorResponseIndexName = "OperatorResponseIndex"

blobKeyPrefix = "BlobKey#"
dispersalIDPrefix = "DispersalID#"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in a follow up PR, removed for now


// GetBlobMetadataByStatus returns all the metadata with the given status
// Because this function scans the entire index, it should only be used for status with a limited number of items.
func (s *blobMetadataStore) GetBlobMetadataByStatus(ctx context.Context, status v2.BlobStatus) ([]*v2.BlobMetadata, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would there ever be a need for a batched version of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by a batched version?

// Existing fields
AccountID string
// AccountID is the ETH account address for the payer
AccountID string `json:"account_id"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the json serialization used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used when we marshal/unmarshal the struct to/from json, i.e. in dataapi.
I've removed these for now

return hash, nil
}

func (pm *PaymentMetadata) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this belong in core? Is there any way to have this code in the blobstore?

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 need to belong in the same package as where the type is defined. We can wrap and clone these types in blobstore but not sure if that's worth it

@@ -59,7 +81,153 @@ func (b *BlobHeader) GetEncodingParams() (encoding.EncodingParams, error) {
NumChunks: uint64(params.NumChunks),
ChunkLength: uint64(length),
}, nil
}

func (b *BlobHeader) BlobKey() (BlobKey, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@ian-shim ian-shim force-pushed the v2-blob-metadata branch 2 times, most recently from 0dbb4c9 to 1b63aee Compare October 24, 2024 23:38
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.

4 participants