go/store/{nbs,datas/pull}: Add some tests for the GetManyCompressed behavior of GhostBlockStore.

This commit is contained in:
Aaron Son
2025-01-14 17:38:42 -08:00
parent f45fa52eac
commit 567342b23a
4 changed files with 128 additions and 1 deletions
+33
View File
@@ -71,6 +71,39 @@ func TestChunkJournalPuller(t *testing.T) {
})
}
func TestPuller(t *testing.T) {
t.Run("GhostChunk", func(t *testing.T) {
ctx := context.Background()
gs, err := nbs.NewGhostBlockStore(t.TempDir())
waf, err := types.WalkAddrsForChunkStore(gs)
require.NoError(t, err)
ghost := hash.Parse("e6esqr35dkqnc7updhj6ap5v82sahm9r")
gs.PersistGhostHashes(ctx, hash.NewHashSet(ghost))
statsCh := make(chan Stats)
go func() {
for _ = range statsCh {}
}()
dir := filepath.Join(os.TempDir(), uuid.New().String())
err = os.MkdirAll(dir, os.ModePerm)
require.NoError(t, err)
nbf := types.Format_Default.VersionString()
q := nbs.NewUnlimitedMemQuotaProvider()
st, err := nbs.NewLocalJournalingStore(ctx, nbf, dir, q)
require.NoError(t, err)
plr, err := NewPuller(ctx, t.TempDir(), 128, gs, st, waf, []hash.Hash{ghost}, statsCh)
require.NoError(t, err)
err = plr.Pull(ctx)
require.ErrorIs(t, err, nbs.ErrGhostChunkRequested)
})
}
func addTableValues(ctx context.Context, vrw types.ValueReadWriter, m types.Map, tableName string, alternatingKeyVals ...types.Value) (types.Map, error) {
val, ok, err := m.MaybeGet(ctx, types.String(tableName))
@@ -95,6 +95,12 @@ func TestCmpChunkTableWriter(t *testing.T) {
compareContentsOfTables(t, ctx, hashes, tr, outputTR)
}
func TestCmpChunkTableWriterGhostChunk(t *testing.T) {
tw, err := NewCmpChunkTableWriter("")
require.NoError(t, err)
require.Error(t, tw.AddCmpChunk(NewGhostCompressedChunk(hash.Parse("6af71afc2ea0hmp4olev0vp9q1q5gvb1"))))
}
func TestContainsDuplicates(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
require.False(t, containsDuplicates(prefixIndexSlice{}))
+3 -1
View File
@@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"github.com/dolthub/dolt/go/store/constants"
"github.com/dolthub/dolt/go/store/chunks"
"github.com/dolthub/dolt/go/store/hash"
)
@@ -147,7 +148,8 @@ func (g GhostBlockStore) Put(ctx context.Context, c chunks.Chunk, getAddrs chunk
}
func (g GhostBlockStore) Version() string {
panic("GhostBlockStore does not support Version")
// This should never be used, but it makes testing a bit more ergonomic in a few places.
return constants.FormatDefaultString
}
func (g GhostBlockStore) AccessMode() chunks.ExclusiveAccessMode {
+86
View File
@@ -0,0 +1,86 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package nbs
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/dolthub/dolt/go/store/chunks"
"github.com/dolthub/dolt/go/store/hash"
)
func TestGhostBlockStore(t *testing.T) {
ctx := context.Background()
path := t.TempDir()
bs, err := NewGhostBlockStore(path)
require.NoError(t, err)
ghost, absent := hash.Parse("ifho8m890r9787lrpthif5ce6ru353fr"), hash.Parse("6af71afc2ea0hmp4olev0vp9q1q5gvb1")
require.NoError(t, bs.PersistGhostHashes(context.Background(), hash.NewHashSet(ghost)))
t.Run("Get", func(t *testing.T) {
t.Run("Ghost", func(t *testing.T) {
c, err := bs.Get(ctx, ghost)
require.NoError(t, err)
require.True(t, c.IsGhost())
})
t.Run("Absent", func(t *testing.T) {
c, err := bs.Get(ctx, absent)
require.NoError(t, err)
require.False(t, c.IsGhost())
require.True(t, c.IsEmpty())
})
})
t.Run("Has", func(t *testing.T) {
t.Run("Ghost", func(t *testing.T) {
h, err := bs.Has(ctx, ghost)
require.NoError(t, err)
require.True(t, h)
})
t.Run("Absent", func(t *testing.T) {
h, err := bs.Has(ctx, absent)
require.NoError(t, err)
require.False(t, h)
})
})
t.Run("HasMany", func(t *testing.T) {
a, err := bs.HasMany(ctx, hash.NewHashSet(absent, ghost))
require.NoError(t, err)
require.Len(t, a, 1)
require.True(t, a.Has(absent))
require.False(t, a.Has(ghost))
})
t.Run("GetMany", func(t *testing.T) {
var got []chunks.Chunk
err := bs.GetMany(ctx, hash.NewHashSet(absent, ghost), func(_ context.Context, c *chunks.Chunk) {
got = append(got, *c)
})
require.NoError(t, err)
require.Len(t, got, 1)
require.True(t, got[0].IsGhost())
require.Equal(t, ghost, got[0].Hash())
})
t.Run("GetManyCompressed", func(t *testing.T) {
var got []CompressedChunk
err := bs.GetManyCompressed(ctx, hash.NewHashSet(absent, ghost), func(_ context.Context, c CompressedChunk) {
got = append(got, c)
})
require.NoError(t, err)
require.Len(t, got, 1)
require.True(t, got[0].IsGhost())
require.Equal(t, ghost, got[0].Hash())
})
}