Skip to content

Commit 4b3a11b

Browse files
committed
Also extract the root directory when slicing Tree messages
This will make it possible for bb_clientd to access the root directory of a Tree objet without requiring the Tree object to be read in its entirety.
1 parent f9ea029 commit 4b3a11b

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

pkg/cas/blob_access_directory_fetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (bs *treeBlobSlicer) Slice(b buffer.Buffer, requestedChildDigest digest.Dig
109109
var slices []slicing.BlobSlice
110110
var bRequested buffer.Buffer
111111
if err := util.VisitProtoBytesFields(r, func(fieldNumber protowire.Number, offsetBytes, sizeBytes int64, fieldReader io.Reader) error {
112-
if fieldNumber == blobstore.TreeChildrenFieldNumber {
112+
if fieldNumber == blobstore.TreeRootFieldNumber || fieldNumber == blobstore.TreeChildrenFieldNumber {
113113
var childDigest digest.Digest
114114
if bRequested == nil && sizeBytes == requestedSizeBytes {
115115
// This directory has the same size as

pkg/cas/blob_access_directory_fetcher_test.go

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,18 @@ func TestBlobAccessDirectoryFetcherGetTreeChildDirectory(t *testing.T) {
237237
// Call GetTreeChildDirectory() against a valid Tree
238238
// object. The provided BlobSlicer should be capable of
239239
// extracting the locations of both children.
240-
directory1 := &remoteexecution.Directory{
240+
rootDirectory := &remoteexecution.Directory{
241+
Directories: []*remoteexecution.DirectoryNode{
242+
{
243+
Name: "directory",
244+
Digest: &remoteexecution.Digest{
245+
Hash: "ed56cd683c99acdff14b77db249819fc",
246+
SizeBytes: 54,
247+
},
248+
},
249+
},
250+
}
251+
childDirectory1 := &remoteexecution.Directory{
241252
Directories: []*remoteexecution.DirectoryNode{
242253
{
243254
Name: "subdirectory",
@@ -248,7 +259,7 @@ func TestBlobAccessDirectoryFetcherGetTreeChildDirectory(t *testing.T) {
248259
},
249260
},
250261
}
251-
directory2 := &remoteexecution.Directory{
262+
childDirectory2 := &remoteexecution.Directory{
252263
Files: []*remoteexecution.FileNode{
253264
{
254265
Name: "hello.txt",
@@ -260,25 +271,16 @@ func TestBlobAccessDirectoryFetcherGetTreeChildDirectory(t *testing.T) {
260271
},
261272
}
262273
tree := &remoteexecution.Tree{
263-
Root: &remoteexecution.Directory{
264-
Directories: []*remoteexecution.DirectoryNode{
265-
{
266-
Name: "directory",
267-
Digest: &remoteexecution.Digest{
268-
Hash: "ed56cd683c99acdff14b77db249819fc",
269-
SizeBytes: 54,
270-
},
271-
},
272-
},
273-
},
274+
Root: rootDirectory,
274275
Children: []*remoteexecution.Directory{
275-
directory1,
276-
directory2,
276+
childDirectory1,
277+
childDirectory2,
277278
},
278279
}
279280
treeDigest := digest.MustNewDigest("example", remoteexecution.DigestFunction_MD5, "ed56cd683c99acdff14b77db249819fc", 162)
280-
directory1Digest := digest.MustNewDigest("example", remoteexecution.DigestFunction_MD5, "5eede3f7e2a1a66c06ffd3906115a55b", 54)
281-
directory2Digest := digest.MustNewDigest("example", remoteexecution.DigestFunction_MD5, "a7536a0ebdeefa48280e135ea77755f0", 51)
281+
rootDirectoryDigest := digest.MustNewDigest("example", remoteexecution.DigestFunction_MD5, "49aec856854ce5d7626c7153f143030c", 51)
282+
childDirectory1Digest := digest.MustNewDigest("example", remoteexecution.DigestFunction_MD5, "5eede3f7e2a1a66c06ffd3906115a55b", 54)
283+
childDirectory2Digest := digest.MustNewDigest("example", remoteexecution.DigestFunction_MD5, "a7536a0ebdeefa48280e135ea77755f0", 51)
282284

283285
blobAccess.EXPECT().GetFromComposite(ctx, treeDigest, gomock.Any(), gomock.Any()).
284286
DoAndReturn(func(ctx context.Context, treeDigest, childDigest digest.Digest, slicer slicing.BlobSlicer) buffer.Buffer {
@@ -287,12 +289,17 @@ func TestBlobAccessDirectoryFetcherGetTreeChildDirectory(t *testing.T) {
287289
b, slices := slicer.Slice(buffer.NewProtoBufferFromProto(tree, buffer.UserProvided), childDigest)
288290
require.Equal(t, []slicing.BlobSlice{
289291
{
290-
Digest: directory1Digest,
292+
Digest: rootDirectoryDigest,
293+
OffsetBytes: 2,
294+
SizeBytes: 51,
295+
},
296+
{
297+
Digest: childDirectory1Digest,
291298
OffsetBytes: 55,
292299
SizeBytes: 54,
293300
},
294301
{
295-
Digest: directory2Digest,
302+
Digest: childDirectory2Digest,
296303
OffsetBytes: 111,
297304
SizeBytes: 51,
298305
},
@@ -304,16 +311,23 @@ func TestBlobAccessDirectoryFetcherGetTreeChildDirectory(t *testing.T) {
304311
fetchedDirectory, err := directoryFetcher.GetTreeChildDirectory(
305312
ctx,
306313
treeDigest,
307-
directory1Digest)
314+
rootDirectoryDigest)
315+
require.NoError(t, err)
316+
testutil.RequireEqualProto(t, rootDirectory, fetchedDirectory)
317+
318+
fetchedDirectory, err = directoryFetcher.GetTreeChildDirectory(
319+
ctx,
320+
treeDigest,
321+
childDirectory1Digest)
308322
require.NoError(t, err)
309-
testutil.RequireEqualProto(t, directory1, fetchedDirectory)
323+
testutil.RequireEqualProto(t, childDirectory1, fetchedDirectory)
310324

311325
fetchedDirectory, err = directoryFetcher.GetTreeChildDirectory(
312326
ctx,
313327
treeDigest,
314-
directory2Digest)
328+
childDirectory2Digest)
315329
require.NoError(t, err)
316-
testutil.RequireEqualProto(t, directory2, fetchedDirectory)
330+
testutil.RequireEqualProto(t, childDirectory2, fetchedDirectory)
317331

318332
_, err = directoryFetcher.GetTreeChildDirectory(
319333
ctx,

0 commit comments

Comments
 (0)