go/store/types: Thread context in Compare.

This commit is contained in:
Aaron Son
2023-03-03 15:54:59 -08:00
parent 6444dcd4dd
commit 2d32f99d1c
11 changed files with 16 additions and 15 deletions

View File

@@ -434,6 +434,8 @@ func TestReadReplica(t *testing.T) {
}
defer os.Chdir(cwd)
ctx := context.Background()
multiSetup := testcommands.NewMultiRepoTestSetup(t.Fatal)
defer multiSetup.Close()
defer os.RemoveAll(multiSetup.Root)
@@ -471,7 +473,7 @@ func TestReadReplica(t *testing.T) {
defer sc.StopServer()
replicatedTable := "new_table"
multiSetup.CreateTable(sourceDbName, replicatedTable)
multiSetup.CreateTable(ctx, sourceDbName, replicatedTable)
multiSetup.StageAll(sourceDbName)
_ = multiSetup.CommitWithWorkingSet(sourceDbName)
multiSetup.PushToRemote(sourceDbName, "remote1", "main")

View File

@@ -298,10 +298,10 @@ func createTestDataTable(ctx context.Context, ddb *doltdb.DoltDB) (*table.InMemT
return imt, sch
}
func (mr *MultiRepoTestSetup) CreateTable(dbName, tblName string) {
func (mr *MultiRepoTestSetup) CreateTable(ctx context.Context, dbName, tblName string) {
dEnv := mr.envs[dbName]
imt, sch := createTestDataTable(context.TODO(), dEnv.DoltDB)
imt, sch := createTestDataTable(ctx, dEnv.DoltDB)
rows := make([]row.Row, imt.NumRows())
for i := 0; i < imt.NumRows(); i++ {
r, err := imt.GetRow(i)

View File

@@ -38,7 +38,7 @@ func NewStash(ctx context.Context, nbf *types.NomsBinFormat, vrw types.ValueRead
return hash.Hash{}, types.Ref{}, err
}
isCommit, err := IsCommit(headCommit)
isCommit, err := IsCommit(ctx, headCommit)
if err != nil {
return hash.Hash{}, types.Ref{}, err
}

View File

@@ -56,7 +56,7 @@ func NewEmptyBlob(vrw ValueReadWriter) (Blob, error) {
// Less implements the LesserValuable interface.
func (b Blob) Less(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (bool, error) {
res, err := b.Compare(nbf, other)
res, err := b.Compare(ctx, nbf, other)
if err != nil {
return false, err
}
@@ -64,10 +64,9 @@ func (b Blob) Less(ctx context.Context, nbf *NomsBinFormat, other LesserValuable
return res < 0, nil
}
func (b Blob) Compare(nbf *NomsBinFormat, other LesserValuable) (int, error) {
func (b Blob) Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (int, error) {
if b2, ok := other.(Blob); ok {
// Blobs can have an arbitrary length, so we compare in chunks rather than loading it entirely
ctx := context.Background()
b1Length := b.Len()
b2Length := b2.Len()
b1Reader := b.Reader(ctx)

View File

@@ -159,7 +159,7 @@ func (fep *EPMerger) ReachedEOF() bool {
}
type comparableValue interface {
Compare(ctx context.Context, vr types.ValueReader, other types.LesserValuable) (int, error)
Compare(ctx context.Context, nbf *types.NomsBinFormat, other types.LesserValuable) (int, error)
}
// search does a binary search or a sorted []entry and returns an integer representing the insertion index where the
@@ -174,7 +174,7 @@ func search(ctx context.Context, vr types.ValueReader, readerIdx int, key types.
}
var res int
res, err = comparable.Compare(ctx, vr, vals[i].key)
res, err = comparable.Compare(ctx, vr.Format(), vals[i].key)
if err != nil {
return false
} else if res < 0 {

View File

@@ -562,7 +562,7 @@ func (mes mapEntrySequence) Less(ctx context.Context, nbf *NomsBinFormat, other
panic("not implemented")
}
func (mes mapEntrySequence) Compare(nbf *NomsBinFormat, other LesserValuable) (int, error) {
func (mes mapEntrySequence) Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (int, error) {
panic("not implemented")
}

View File

@@ -653,7 +653,7 @@ func (es emptySequence) Less(ctx context.Context, nbf *NomsBinFormat, other Less
panic("empty sequence")
}
func (es emptySequence) Compare(nbf *NomsBinFormat, other LesserValuable) (int, error) {
func (es emptySequence) Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (int, error) {
panic("empty sequence")
}

View File

@@ -47,7 +47,7 @@ type sequence interface {
Kind() NomsKind
Len() uint64
Less(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (bool, error)
Compare(nbf *NomsBinFormat, other LesserValuable) (int, error)
Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (int, error)
numLeaves() uint64
seqLen() int
treeLevel() uint64

View File

@@ -112,7 +112,7 @@ func (ts testSequence) Less(ctx context.Context, nbf *NomsBinFormat, other Lesse
panic("not reached")
}
func (ts testSequence) Compare(nbf *NomsBinFormat, other LesserValuable) (int, error) {
func (ts testSequence) Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (int, error) {
panic("not reached")
}

View File

@@ -824,7 +824,7 @@ func (t Tuple) TupleCompare(ctx context.Context, nbf *NomsBinFormat, otherTuple
if err != nil {
return 0, err
}
res, err = blob.Compare(nbf, otherBlob)
res, err = blob.Compare(ctx, nbf, otherBlob)
if err != nil {
return 0, err
}

View File

@@ -283,7 +283,7 @@ func (v valueImpl) Less(ctx context.Context, nbf *NomsBinFormat, other LesserVal
return isLess, nil
}
func (v valueImpl) Compare(nbf *NomsBinFormat, other LesserValuable) (int, error) {
func (v valueImpl) Compare(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (int, error) {
return valueCompare(nbf, v, other.(Value))
}