MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / tryGrow

Function tryGrow

cmd/cql-fuse/block_test.go:336–371  ·  view source on GitHub ↗
(db *sql.DB, data []byte, id, newSize uint64)

Source from the content-addressed store, hash-verified

334}
335
336func tryGrow(db *sql.DB, data []byte, id, newSize uint64) ([]byte, error) {
337 originalSize := uint64(len(data))
338 data = append(data, make([]byte, newSize-originalSize)...)
339 if err := grow(db, id, originalSize, newSize); err != nil {
340 return nil, err
341 }
342 newData, err := getAllBlocks(db, id)
343 if err != nil {
344 return nil, err
345 }
346 if uint64(len(newData)) != newSize {
347 return nil, fmt.Errorf("getAllBlocks lengths don't match: got %d, expected %d", len(newData), newSize)
348 }
349 if !bytes.Equal(data, newData) {
350 return nil, fmt.Errorf("getAllBlocks data doesn't match")
351 }
352
353 if newSize == 0 {
354 return newData, nil
355 }
356
357 // Check the read as well.
358 newData, err = read(db, id, 0, newSize)
359 if err != nil {
360 return nil, err
361 }
362
363 if uint64(len(newData)) != newSize {
364 return nil, fmt.Errorf("read lengths don't match: got %d, expected %d", len(newData), newSize)
365 }
366 if !bytes.Equal(data, newData) {
367 return nil, fmt.Errorf("read data doesn't match")
368 }
369
370 return newData, nil
371}
372
373func tryShrink(db *sql.DB, data []byte, id, newSize uint64) ([]byte, error) {
374 originalSize := uint64(len(data))

Callers 1

TestShrinkGrowFunction · 0.85

Calls 4

growFunction · 0.85
getAllBlocksFunction · 0.85
readFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected