go/store/nbs: Keep GetChunkLocations, make a new GetChunkLocationsWithPaths.

This commit is contained in:
Aaron Son
2022-09-02 11:23:38 -07:00
parent 564afdbaee
commit 9345cbcb98
4 changed files with 41 additions and 12 deletions
+20 -3
View File
@@ -319,19 +319,36 @@ func (gcs *GenerationalNBS) SupportedOperations() TableFileStoreOps {
return gcs.newGen.SupportedOperations()
}
func (gcs *GenerationalNBS) GetChunkLocations(hashes hash.HashSet) (map[string]map[hash.Hash]Range, error) {
res, err := gcs.newGen.GetChunkLocations(hashes)
func (gcs *GenerationalNBS) GetChunkLocationsWithPaths(hashes hash.HashSet) (map[string]map[hash.Hash]Range, error) {
res, err := gcs.newGen.GetChunkLocationsWithPaths(hashes)
if err != nil {
return nil, err
}
if len(hashes) > 0 {
prefix := gcs.RelativeOldGenPath()
toadd, err := gcs.oldGen.GetChunkLocationsWithPaths(hashes)
if err != nil {
return nil, err
}
for k, v := range toadd {
res[prefix + "/" + k] = v
}
}
return res, nil
}
func (gcs *GenerationalNBS) GetChunkLocations(hashes hash.HashSet) (map[hash.Hash]map[hash.Hash]Range, error) {
res, err := gcs.newGen.GetChunkLocations(hashes)
if err != nil {
return nil, err
}
if len(hashes) > 0 {
toadd, err := gcs.oldGen.GetChunkLocations(hashes)
if err != nil {
return nil, err
}
for k, v := range toadd {
res[filepath.ToSlash(filepath.Join(prefix, k))] = v
res[k] = v
}
}
return res, nil
+18 -6
View File
@@ -116,10 +116,22 @@ type Range struct {
Length uint32
}
func (nbs *NomsBlockStore) GetChunkLocations(hashes hash.HashSet) (map[string]map[hash.Hash]Range, error) {
func (nbs *NomsBlockStore) GetChunkLocationsWithPaths(hashes hash.HashSet) (map[string]map[hash.Hash]Range, error) {
locs, err := nbs.GetChunkLocations(hashes)
if err != nil {
return nil, err
}
toret := make(map[string]map[hash.Hash]Range, len(locs))
for k, v := range locs {
toret[k.String()] = v
}
return toret, nil
}
func (nbs *NomsBlockStore) GetChunkLocations(hashes hash.HashSet) (map[hash.Hash]map[hash.Hash]Range, error) {
gr := toGetRecords(hashes)
ranges := make(map[string]map[hash.Hash]Range)
ranges := make(map[hash.Hash]map[hash.Hash]Range)
f := func(css chunkSources) error {
for _, cs := range css {
switch tr := cs.(type) {
@@ -129,7 +141,7 @@ func (nbs *NomsBlockStore) GetChunkLocations(hashes hash.HashSet) (map[string]ma
return err
}
if len(offsetRecSlice) > 0 {
y, ok := ranges[hash.Hash(tr.h).String()]
y, ok := ranges[hash.Hash(tr.h)]
if !ok {
y = make(map[hash.Hash]Range)
@@ -146,10 +158,10 @@ func (nbs *NomsBlockStore) GetChunkLocations(hashes hash.HashSet) (map[string]ma
gr = toGetRecords(hashes)
}
ranges[hash.Hash(tr.h).String()] = y
ranges[hash.Hash(tr.h)] = y
}
case *chunkSourceAdapter:
y, ok := ranges[hash.Hash(tr.h).String()]
y, ok := ranges[hash.Hash(tr.h)]
if !ok {
y = make(map[hash.Hash]Range)
@@ -174,7 +186,7 @@ func (nbs *NomsBlockStore) GetChunkLocations(hashes hash.HashSet) (map[string]ma
}
}
ranges[hash.Hash(tr.h).String()] = y
ranges[hash.Hash(tr.h)] = y
for _, h := range foundHashes {
delete(hashes, h)
+1 -1
View File
@@ -34,7 +34,7 @@ type store interface {
nbs.TableFileStore
Path() (string, bool)
GetChunkLocations(hashes hash.HashSet) (map[string]map[hash.Hash]nbs.Range, error)
GetChunkLocationsWithPaths(hashes hash.HashSet) (map[string]map[hash.Hash]nbs.Range, error)
}
var _ store = &nbs.NomsBlockStore{}
+2 -2
View File
@@ -125,7 +125,7 @@ func (rs *RemoteChunkStore) GetDownloadLocations(ctx context.Context, req *remot
return nil, err
}
locations, err := cs.GetChunkLocations(hashes)
locations, err := cs.GetChunkLocationsWithPaths(hashes)
if err != nil {
return nil, err
}
@@ -184,7 +184,7 @@ func (rs *RemoteChunkStore) StreamDownloadLocations(stream remotesapi.ChunkStore
}
hashes, _ := remotestorage.ParseByteSlices(req.ChunkHashes)
locations, err := cs.GetChunkLocations(hashes)
locations, err := cs.GetChunkLocationsWithPaths(hashes)
if err != nil {
return err
}