mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-12 10:32:27 -06:00
fix copyright, add close opened cs test
This commit is contained in:
@@ -23,6 +23,7 @@ package nbs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -492,17 +493,19 @@ func (fm *fakeManifest) set(version string, lock addr, root hash.Hash, specs, ap
|
||||
}
|
||||
|
||||
func newFakeTableSet(q MemoryQuotaProvider) tableSet {
|
||||
return tableSet{p: newFakeTablePersister(q), q: NewUnlimitedMemQuotaProvider(), rl: make(chan struct{}, 1)}
|
||||
return tableSet{p: newFakeTablePersister(q), q: q, rl: make(chan struct{}, 1)}
|
||||
}
|
||||
|
||||
func newFakeTablePersister(q MemoryQuotaProvider) tablePersister {
|
||||
return fakeTablePersister{q, map[addr]tableReader{}, &sync.RWMutex{}}
|
||||
func newFakeTablePersister(q MemoryQuotaProvider) fakeTablePersister {
|
||||
return fakeTablePersister{q, map[addr]tableReader{}, map[addr]bool{}, map[addr]bool{}, &sync.RWMutex{}}
|
||||
}
|
||||
|
||||
type fakeTablePersister struct {
|
||||
q MemoryQuotaProvider
|
||||
sources map[addr]tableReader
|
||||
mu *sync.RWMutex
|
||||
q MemoryQuotaProvider
|
||||
sources map[addr]tableReader
|
||||
sourcesToFail map[addr]bool
|
||||
opened map[addr]bool
|
||||
mu *sync.RWMutex
|
||||
}
|
||||
|
||||
var _ tablePersister = fakeTablePersister{}
|
||||
@@ -610,8 +613,12 @@ func compactSourcesToBuffer(sources chunkSources) (name addr, data []byte, chunk
|
||||
}
|
||||
|
||||
func (ftp fakeTablePersister) Open(ctx context.Context, name addr, chunkCount uint32, stats *Stats) (chunkSource, error) {
|
||||
ftp.mu.RLock()
|
||||
defer ftp.mu.RUnlock()
|
||||
ftp.mu.Lock()
|
||||
defer ftp.mu.Unlock()
|
||||
if _, ok := ftp.sourcesToFail[name]; ok {
|
||||
return nil, errors.New("intentional failure")
|
||||
}
|
||||
ftp.opened[name] = true
|
||||
return chunkSourceAdapter{ftp.sources[name], name}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ package nbs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -144,6 +145,15 @@ func TestTableSetExtract(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func persist(t *testing.T, p tablePersister, chunks ...[]byte) {
|
||||
for _, c := range chunks {
|
||||
mt := newMemTable(testMemTableSize)
|
||||
mt.addChunk(computeAddr(c), c)
|
||||
_, err := p.Persist(context.Background(), mt, nil, &Stats{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTableSetRebase(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
q := NewUnlimitedMemQuotaProvider()
|
||||
@@ -208,3 +218,34 @@ func TestTableSetPhysicalLen(t *testing.T) {
|
||||
|
||||
assert.True(mustUint64(ts.physicalLen()) > indexSize(mustUint32(ts.count())))
|
||||
}
|
||||
|
||||
func TestTableSetClosesOpenedChunkSourcesOnErr(t *testing.T) {
|
||||
q := NewUnlimitedMemQuotaProvider()
|
||||
p := newFakeTablePersister(q)
|
||||
persist(t, p, testChunks...)
|
||||
|
||||
var mem uint64 = 0
|
||||
var sources []addr
|
||||
for addr := range p.sources {
|
||||
sources = append(sources, addr)
|
||||
mem += indexMemSize(1)
|
||||
}
|
||||
|
||||
idx := rand.Intn(len(testChunks))
|
||||
addrToFail := sources[idx]
|
||||
p.sourcesToFail[addrToFail] = true
|
||||
|
||||
var specs []tableSpec
|
||||
for _, addr := range sources {
|
||||
specs = append(specs, tableSpec{addr, 1})
|
||||
}
|
||||
|
||||
ts := tableSet{p: p, q: q, rl: make(chan struct{}, 1)}
|
||||
_, err := ts.Rebase(context.Background(), specs, &Stats{})
|
||||
require.Error(t, err)
|
||||
|
||||
for _ = range p.opened {
|
||||
mem -= indexMemSize(1)
|
||||
}
|
||||
require.EqualValues(t, mem, q.Usage())
|
||||
}
|
||||
|
||||
@@ -216,8 +216,8 @@ var CopiedNomsFiles []CopiedNomsFile = []CopiedNomsFile{
|
||||
{Path: "store/nbs/manifest_cache_test.go", NomsPath: "go/nbs/manifest_cache_test.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/mem_table.go", NomsPath: "go/nbs/mem_table.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/mem_table_test.go", NomsPath: "go/nbs/mem_table_test.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/mmap_table_reader.go", NomsPath: "go/nbs/mmap_table_reader.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/mmap_table_reader_test.go", NomsPath: "go/nbs/mmap_table_reader_test.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/file_table_reader.go", NomsPath: "go/nbs/mmap_table_reader.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/file_table_reader_test.go", NomsPath: "go/nbs/mmap_table_reader_test.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/persisting_chunk_source.go", NomsPath: "go/nbs/persisting_chunk_source.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/persisting_chunk_source_test.go", NomsPath: "go/nbs/persisting_chunk_source_test.go", HadCopyrightNotice: true},
|
||||
{Path: "store/nbs/root_tracker_test.go", NomsPath: "go/nbs/root_tracker_test.go", HadCopyrightNotice: true},
|
||||
|
||||
Reference in New Issue
Block a user