-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,18 @@ import ( | |
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// ComputerHash split the reader into segment, ec encode the data, compute the hash roots of pieces | ||
// ComputeIntegrityHash 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) ([][]byte, int64, error) { | ||
func ComputeIntegrityHash(reader io.Reader, segmentSize int64, dataShards, parityShards int) ([][]byte, int64, error) { | ||
var segChecksumList [][]byte | ||
var result [][]byte | ||
ecShards := dataShards + parityShards | ||
encodeData := make([][][]byte, ecShards) | ||
|
||
encodeData := make([][][]byte, ecShards) | ||
for i := 0; i < ecShards; i++ { | ||
encodeData[i] = make([][]byte, 0) | ||
} | ||
|
||
hashList := make([][]byte, ecShards+1) | ||
contentLen := int64(0) | ||
// read the data by segment size | ||
for { | ||
|
@@ -34,7 +34,8 @@ func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards | |
} | ||
break | ||
} | ||
if n > 0 { | ||
|
||
if n > 0 && n <= int(segmentSize) { | ||
contentLen += int64(n) | ||
data := seg[:n] | ||
// compute segment hash | ||
|
@@ -53,14 +54,12 @@ func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards | |
} | ||
|
||
// combine the hash root of pieces of the PrimarySP | ||
segmentRootHash := GenerateIntegrityHash(segChecksumList) | ||
result = append(result, segmentRootHash) | ||
hashList[0] = GenerateIntegrityHash(segChecksumList) | ||
|
||
// compute the hash root of pieces of the SecondarySP | ||
wg := &sync.WaitGroup{} | ||
spLen := len(encodeData) | ||
wg.Add(spLen) | ||
hashList := make([][]byte, spLen) | ||
for spID, content := range encodeData { | ||
go func(data [][]byte, id int) { | ||
defer wg.Done() | ||
|
@@ -70,16 +69,13 @@ func ComputerHash(reader io.Reader, segmentSize int64, dataShards, parityShards | |
checksumList = append(checksumList, piecesHash) | ||
} | ||
|
||
hashList[id] = GenerateIntegrityHash(checksumList) | ||
hashList[id+1] = GenerateIntegrityHash(checksumList) | ||
}(content, spID) | ||
} | ||
|
||
wg.Wait() | ||
|
||
for i := 0; i < spLen; i++ { | ||
result = append(result, hashList[i]) | ||
} | ||
return result, contentLen, nil | ||
return hashList, contentLen, nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why result = append(result, hashList[i]) ?directly return hashList? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
// ComputerHashFromFile open a local file and compute hash result | ||
|
@@ -92,11 +88,11 @@ func ComputerHashFromFile(filePath string, segmentSize int64, dataShards, parity | |
} | ||
defer f.Close() | ||
|
||
return ComputerHash(f, segmentSize, dataShards, parityShards) | ||
return ComputeIntegrityHash(f, segmentSize, dataShards, parityShards) | ||
} | ||
|
||
// ComputerHashFromBuffer support compute hash from byte buffer | ||
func ComputerHashFromBuffer(content []byte, segmentSize int64, dataShards, parityShards int) ([][]byte, int64, error) { | ||
reader := bytes.NewReader(content) | ||
return ComputerHash(reader, segmentSize, dataShards, parityShards) | ||
return ComputeIntegrityHash(reader, segmentSize, dataShards, parityShards) | ||
} |
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
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.
1.What's the difference between segmentSize and blockSize?
2.piceceData->shardDataList maybe a good choice.
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.
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