TryReadChunk Read the encoded KV data using chunkIdx from storage file and decode it. Return error if the read IO fails. Return false if the data is not managed by the ShardManager.
(chunkIdx uint64, commit common.Hash)
| 291 | // Return error if the read IO fails. |
| 292 | // Return false if the data is not managed by the ShardManager. |
| 293 | func (sm *ShardManager) TryReadChunk(chunkIdx uint64, commit common.Hash) ([]byte, bool, error) { |
| 294 | kvIdx := chunkIdx / sm.chunksPerKv |
| 295 | cIdx := chunkIdx % sm.chunksPerKv |
| 296 | shardIdx := kvIdx / sm.kvEntries |
| 297 | if ds, ok := sm.shardMap[shardIdx]; ok { |
| 298 | b, err := ds.ReadChunk(kvIdx, cIdx, commit) // read all the data |
| 299 | return b, true, err |
| 300 | } else { |
| 301 | return nil, false, nil |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | // TryReadChunkEncoded Read the encoded KV data using chunkIdx from storage file and return it. |
| 306 | // Return error if the read IO fails. |