@@ -26,7 +26,8 @@ import (
2626// human-readable string describing a blob handle, synthesizing unspecified
2727// fields, and tracking the blob handle to support future fetches.
2828type Values struct {
29- mostRecentHandle blob.Handle
29+ mostRecentFileNum base.DiskFileNum
30+ mostRecentHandles map [base.DiskFileNum ]blob.Handle
3031 // trackedHandles maps from a blob handle to its value. The value may be nil
3132 // if the value was not specified (in which case Fetch will
3233 // deterministically derive a random value from the handle itself.)
@@ -108,6 +109,7 @@ func (bv *Values) IsBlobHandle(input string) bool {
108109func (bv * Values ) Parse (input string ) (h blob.Handle , err error ) {
109110 if bv .trackedHandles == nil {
110111 bv .trackedHandles = make (map [blob.Handle ]string )
112+ bv .mostRecentHandles = make (map [base.DiskFileNum ]blob.Handle )
111113 }
112114
113115 defer func () {
@@ -156,13 +158,13 @@ func (bv *Values) Parse(input string) (h blob.Handle, err error) {
156158 }
157159
158160 if ! fileNumSet {
159- h .FileNum = max ( bv .mostRecentHandle . FileNum , 1 )
161+ h .FileNum = bv .mostRecentFileNum
160162 }
161163 if ! blockNumSet {
162- h .BlockNum = bv .mostRecentHandle .BlockNum
164+ h .BlockNum = bv .mostRecentHandles [ h . FileNum ] .BlockNum
163165 }
164166 if ! offsetSet {
165- h .OffsetInBlock = bv .mostRecentHandle . OffsetInBlock + bv .mostRecentHandle .ValueLen
167+ h .OffsetInBlock = bv .mostRecentHandles [ h . FileNum ]. OffsetInBlock + bv .mostRecentHandles [ h . FileNum ] .ValueLen
166168 }
167169 if ! valueLenSet {
168170 if len (value ) > 0 {
@@ -171,7 +173,8 @@ func (bv *Values) Parse(input string) (h blob.Handle, err error) {
171173 h .ValueLen = 12
172174 }
173175 }
174- bv .mostRecentHandle = h
176+ bv .mostRecentFileNum = h .FileNum
177+ bv .mostRecentHandles [h .FileNum ] = h
175178 bv .trackedHandles [h ] = value
176179 return h , nil
177180}
@@ -228,7 +231,10 @@ func WriteFiles(
228231 return err
229232 }
230233 writer := blob .NewFileWriter (fileNum , writable , writerOpts )
231- for _ , handle := range handles {
234+ for i , handle := range handles {
235+ if i > 0 && handles [i - 1 ].BlockNum != handle .BlockNum {
236+ writer .FlushForTesting ()
237+ }
232238 if value , ok := bv .trackedHandles [handle ]; ok {
233239 writer .AddValue ([]byte (value ))
234240 } else {
0 commit comments