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

fix : fix compute hash #9

Merged
merged 4 commits into from
Mar 10, 2023
Merged

fix : fix compute hash #9

merged 4 commits into from
Mar 10, 2023

Conversation

flywukong
Copy link
Collaborator

Description

fix bugs of computing hash root

README.md Outdated

1. erasure package support RSEncoder which contain basic Encode and Decode reedSolomon APIs
(1) erasure package support RSEncoder which contain basic Encode and Decode reedSolomon APIs
```
RSEncoderStorage, err := NewRSEncoder(dataShards, parityShards, int64(blockSize))
Copy link
Collaborator

@will-2012 will-2012 Mar 8, 2023

Choose a reason for hiding this comment

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

1.int64(blocksize) -> blocksize
2.Explain the meaning of blocksize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

README.md Outdated
// decodes the input erasure encoded data shards data.
func (r *RSEncoder) DecodeDataShards(content [][]byte) error {
func (r *RSEncoder) DecodeDataShards(content [][]byte) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ReconstructData or RecoverData seems clearer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

DecodeDataShards and DecodeShards is corresponding to EncodeShards.
I added some clarifications to explain the function

@@ -22,7 +22,7 @@ func EncodeRawSegment(content []byte, dataShards, parityShards int) ([][]byte, e
func DecodeRawSegment(pieceData [][]byte, segmentSize int64, dataShards, parityShards int) ([]byte, error)
Copy link
Collaborator

@will-2012 will-2012 Mar 8, 2023

Choose a reason for hiding this comment

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

1.What's the difference between segmentSize and blockSize?
2.piceceData->shardDataList maybe a good choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No difference, These two interfaces are applied on the SP side as the segments is called in gnfd side, so the naming is closer to the application layer

README.md Outdated
@@ -22,7 +22,7 @@ func EncodeRawSegment(content []byte, dataShards, parityShards int) ([][]byte, e
func DecodeRawSegment(pieceData [][]byte, segmentSize int64, dataShards, parityShards int) ([]byte, error)
```

### Compute sha256 hash of file content
### 2. Compute sha256 hash of file content

hash package support methods to compute hash roots of greenfield objects , the computed methods is based on
redundancy Strategy of greenfield
Copy link
Collaborator

Choose a reason for hiding this comment

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

Strategy-> strategy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

go/hash/hash.go Outdated
@@ -32,51 +36,44 @@ func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards
}
if n > 0 {
Copy link
Collaborator

@will-2012 will-2012 Mar 8, 2023

Choose a reason for hiding this comment

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

Maybe n != segmentSize and err == nil, need retry read from io.reader.

Copy link
Collaborator Author

@flywukong flywukong Mar 9, 2023

Choose a reason for hiding this comment

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

as the API description below , the n may be less than segmentSize (end-of-file condition) , so if the err happen, just return an error. If end-of-file condition, the n just need to be less than segmentSize .
// When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read

changed to condition to " if n > 0 && n <= int(segmentSize)"

for _, hash := range hashResult {
if len(hash) != 64 {
if len(hash) != 32 {
Copy link
Collaborator

@will-2012 will-2012 Mar 8, 2023

Choose a reason for hiding this comment

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

Define constant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@@ -86,7 +83,7 @@ func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why result = append(result, hashList[i]) ?directly return hashList?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, some adjustments have been made, the result variable is no longer needed

go/hash/hash.go Outdated
)

// ComputerHash split the reader into segment, ec encode the data, compute the hash roots of pieces
// return the hash result array list and data size
func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards int) ([]string, int64, error) {
func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards int) ([][]byte, int64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

CompluterHash's Computer is a noun, which seems inappropriate function name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to ComputeIntegrityHash

Copy link
Contributor

@sysvm sysvm left a comment

Choose a reason for hiding this comment

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

LGTM

@sysvm sysvm merged commit 5ead084 into develop Mar 10, 2023
@sysvm sysvm deleted the fix-hash branch March 10, 2023 02:31
sysvm added a commit that referenced this pull request Mar 10, 2023
* fix : fix compute hash (#9)

* docs: add checksum and integrity hash func instrument (#11)
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.

3 participants