mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-14 19:38:56 -05:00
rip out prolly.ConflictIndex
This commit is contained in:
@@ -16,11 +16,10 @@ package durable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
"github.com/dolthub/dolt/go/store/prolly"
|
||||
"github.com/dolthub/dolt/go/store/prolly/shim"
|
||||
"github.com/dolthub/dolt/go/store/prolly/tree"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
@@ -38,8 +37,7 @@ func RefFromConflictIndex(ctx context.Context, vrw types.ValueReadWriter, idx Co
|
||||
return refFromNomsValue(ctx, vrw, idx.(nomsConflictIndex).index)
|
||||
|
||||
case types.Format_DOLT_1:
|
||||
b := shim.ValueFromConflictMap(idx.(prollyConflictIndex).index)
|
||||
return refFromNomsValue(ctx, vrw, b)
|
||||
return types.Ref{}, fmt.Errorf("__DOLT_1__ conflicts should be stored in ArtifactIndex")
|
||||
|
||||
default:
|
||||
return types.Ref{}, errNbfUnkown
|
||||
@@ -56,14 +54,8 @@ func NewEmptyConflictIndex(ctx context.Context, vrw types.ValueReadWriter, ns tr
|
||||
}
|
||||
return ConflictIndexFromNomsMap(m, vrw), nil
|
||||
|
||||
//case types.Format_DOLT_1:
|
||||
// kd, oursVD := shim.MapDescriptorsFromSchema(oursSch)
|
||||
// theirsVD := shim.ValueDescriptorFromSchema(theirsSch)
|
||||
// baseVD := shim.ValueDescriptorFromSchema(baseSch)
|
||||
//
|
||||
// m := prolly.NewEmptyConflictMap(ns, kd, oursVD, theirsVD, baseVD)
|
||||
//
|
||||
// return ConflictIndexFromProllyMap(m), nil
|
||||
case types.Format_DOLT_1:
|
||||
return nil, fmt.Errorf("__DOLT_1__ conflicts should be stored in ArtifactIndex")
|
||||
|
||||
default:
|
||||
return nil, errNbfUnkown
|
||||
@@ -81,16 +73,6 @@ func NomsMapFromConflictIndex(i ConflictIndex) types.Map {
|
||||
return i.(nomsConflictIndex).index
|
||||
}
|
||||
|
||||
func ConflictIndexFromProllyMap(m prolly.ConflictMap) ConflictIndex {
|
||||
return prollyConflictIndex{
|
||||
index: m,
|
||||
}
|
||||
}
|
||||
|
||||
func ProllyMapFromConflictIndex(i ConflictIndex) prolly.ConflictMap {
|
||||
return i.(prollyConflictIndex).index
|
||||
}
|
||||
|
||||
func conflictIndexFromRef(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, ourSch, theirSch, baseSch schema.Schema, r types.Ref) (ConflictIndex, error) {
|
||||
return conflictIndexFromAddr(ctx, vrw, ns, ourSch, theirSch, baseSch, r.TargetHash())
|
||||
}
|
||||
@@ -106,8 +88,7 @@ func conflictIndexFromAddr(ctx context.Context, vrw types.ValueReadWriter, ns tr
|
||||
return ConflictIndexFromNomsMap(v.(types.Map), vrw), nil
|
||||
|
||||
case types.Format_DOLT_1:
|
||||
m := shim.ConflictMapFromValue(v, ourSch, theirSch, baseSch, ns)
|
||||
return ConflictIndexFromProllyMap(m), nil
|
||||
return nil, fmt.Errorf("__DOLT_1__ conflicts should be stored in ArtifactIndex")
|
||||
|
||||
default:
|
||||
return nil, errNbfUnkown
|
||||
@@ -130,19 +111,3 @@ func (i nomsConflictIndex) Count() uint64 {
|
||||
func (i nomsConflictIndex) Format() *types.NomsBinFormat {
|
||||
return i.vrw.Format()
|
||||
}
|
||||
|
||||
type prollyConflictIndex struct {
|
||||
index prolly.ConflictMap
|
||||
}
|
||||
|
||||
func (i prollyConflictIndex) HashOf() (hash.Hash, error) {
|
||||
return i.index.HashOf(), nil
|
||||
}
|
||||
|
||||
func (i prollyConflictIndex) Count() uint64 {
|
||||
return uint64(i.index.Count())
|
||||
}
|
||||
|
||||
func (i prollyConflictIndex) Format() *types.NomsBinFormat {
|
||||
return i.index.Format()
|
||||
}
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
// Copyright 2021 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 prolly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
"github.com/dolthub/dolt/go/store/pool"
|
||||
"github.com/dolthub/dolt/go/store/prolly/tree"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
"github.com/dolthub/dolt/go/store/val"
|
||||
)
|
||||
|
||||
type Conflict val.Triple[val.Tuple]
|
||||
|
||||
func (c Conflict) OurValue() val.Tuple {
|
||||
return val.Triple[val.Tuple](c).First()
|
||||
}
|
||||
|
||||
func (c Conflict) TheirValue() val.Tuple {
|
||||
return val.Triple[val.Tuple](c).Second()
|
||||
}
|
||||
|
||||
func (c Conflict) BaseValue() val.Tuple {
|
||||
return val.Triple[val.Tuple](c).Third()
|
||||
}
|
||||
|
||||
type ConflictIter kvIter[val.Tuple, Conflict]
|
||||
|
||||
type ConflictMap struct {
|
||||
conflicts orderedTree[val.Tuple, Conflict, val.TupleDesc]
|
||||
keyDesc val.TupleDesc
|
||||
ourDesc val.TupleDesc
|
||||
theirDesc val.TupleDesc
|
||||
baseDesc val.TupleDesc
|
||||
}
|
||||
|
||||
func NewConflictMap(root tree.Node, ns tree.NodeStore, key, ours, theirs, base val.TupleDesc) ConflictMap {
|
||||
conflicts := orderedTree[val.Tuple, Conflict, val.TupleDesc]{
|
||||
root: root,
|
||||
ns: ns,
|
||||
order: key,
|
||||
}
|
||||
return ConflictMap{
|
||||
conflicts: conflicts,
|
||||
keyDesc: key,
|
||||
ourDesc: ours,
|
||||
theirDesc: theirs,
|
||||
baseDesc: base,
|
||||
}
|
||||
}
|
||||
|
||||
func NewEmptyConflictMap(ns tree.NodeStore, key, ours, theirs, base val.TupleDesc) ConflictMap {
|
||||
panic("delete me")
|
||||
}
|
||||
|
||||
func (c ConflictMap) Count() int {
|
||||
return c.conflicts.count()
|
||||
}
|
||||
|
||||
func (c ConflictMap) Height() int {
|
||||
return c.conflicts.height()
|
||||
}
|
||||
|
||||
func (c ConflictMap) HashOf() hash.Hash {
|
||||
return c.conflicts.hashOf()
|
||||
}
|
||||
|
||||
func (c ConflictMap) Node() tree.Node {
|
||||
return c.conflicts.root
|
||||
}
|
||||
|
||||
func (c ConflictMap) Format() *types.NomsBinFormat {
|
||||
return c.conflicts.ns.Format()
|
||||
}
|
||||
|
||||
func (c ConflictMap) Descriptors() (key, ours, theirs, base val.TupleDesc) {
|
||||
return c.keyDesc, c.ourDesc, c.theirDesc, c.baseDesc
|
||||
}
|
||||
|
||||
func (c ConflictMap) WalkAddresses(ctx context.Context, cb tree.AddressCb) error {
|
||||
return c.conflicts.walkAddresses(ctx, cb)
|
||||
}
|
||||
|
||||
func (c ConflictMap) WalkNodes(ctx context.Context, cb tree.NodeCb) error {
|
||||
return c.conflicts.walkNodes(ctx, cb)
|
||||
}
|
||||
|
||||
func (c ConflictMap) Get(ctx context.Context, key val.Tuple, cb KeyValueFn[val.Tuple, Conflict]) (err error) {
|
||||
return c.conflicts.get(ctx, key, cb)
|
||||
}
|
||||
|
||||
func (c ConflictMap) Has(ctx context.Context, key val.Tuple) (ok bool, err error) {
|
||||
return c.conflicts.has(ctx, key)
|
||||
}
|
||||
|
||||
func (c ConflictMap) IterAll(ctx context.Context) (ConflictIter, error) {
|
||||
return c.conflicts.iterAll(ctx)
|
||||
}
|
||||
|
||||
func (c ConflictMap) IterOrdinalRange(ctx context.Context, start, stop uint64) (ConflictIter, error) {
|
||||
return c.conflicts.iterOrdinalRange(ctx, start, stop)
|
||||
}
|
||||
|
||||
// Pool returns the pool.BuffPool of the underlying conflicts' tree.NodeStore
|
||||
func (c ConflictMap) Pool() pool.BuffPool {
|
||||
return c.conflicts.ns.Pool()
|
||||
}
|
||||
|
||||
func (c ConflictMap) Editor() ConflictEditor {
|
||||
return ConflictEditor{
|
||||
conflicts: c.conflicts.mutate(),
|
||||
keyDesc: c.keyDesc,
|
||||
ourDesc: c.ourDesc,
|
||||
theirDesc: c.theirDesc,
|
||||
baseDesc: c.baseDesc,
|
||||
}
|
||||
}
|
||||
|
||||
type ConflictEditor struct {
|
||||
conflicts orderedMap[val.Tuple, Conflict, val.TupleDesc]
|
||||
keyDesc val.TupleDesc
|
||||
ourDesc val.TupleDesc
|
||||
theirDesc val.TupleDesc
|
||||
baseDesc val.TupleDesc
|
||||
}
|
||||
|
||||
func (wr ConflictEditor) Add(ctx context.Context, key, ourVal, theirVal, baseVal val.Tuple) error {
|
||||
p := wr.conflicts.tree.ns.Pool()
|
||||
c := val.NewTriple(p, ourVal, theirVal, baseVal)
|
||||
return wr.conflicts.put(ctx, key, Conflict(c))
|
||||
}
|
||||
|
||||
func (wr ConflictEditor) Delete(ctx context.Context, key val.Tuple) error {
|
||||
return wr.conflicts.delete(ctx, key)
|
||||
}
|
||||
|
||||
func (wr ConflictEditor) Flush(ctx context.Context) (ConflictMap, error) {
|
||||
panic("delete me")
|
||||
//tr := wr.conflicts.tree
|
||||
//serializer := message.NewProllyMapSerializer()
|
||||
//
|
||||
//root, err := tree.ApplyMutations(ctx, tr.ns, tr.root, serializer, wr.conflicts.mutations(), tr.compareItems)
|
||||
//if err != nil {
|
||||
// return ConflictMap{}, err
|
||||
//}
|
||||
//
|
||||
//return ConflictMap{
|
||||
// conflicts: orderedTree[val.Tuple, Conflict, val.TupleDesc]{
|
||||
// root: root,
|
||||
// ns: tr.ns,
|
||||
// order: tr.order,
|
||||
// },
|
||||
// keyDesc: wr.keyDesc,
|
||||
// ourDesc: wr.ourDesc,
|
||||
// theirDesc: wr.theirDesc,
|
||||
// baseDesc: wr.baseDesc,
|
||||
//}, nil
|
||||
}
|
||||
|
||||
// ConflictDebugFormat formats a ConflictMap.
|
||||
func ConflictDebugFormat(ctx context.Context, m ConflictMap) (string, error) {
|
||||
kd, ourVD, theirVD, baseVD := m.Descriptors()
|
||||
iter, err := m.IterAll(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
c := m.Count()
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString(fmt.Sprintf("Prolly Map (count: %d) {\n", c))
|
||||
for {
|
||||
k, v, err := iter.Next(ctx)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
sb.WriteString("\t")
|
||||
sb.WriteString(kd.Format(k))
|
||||
sb.WriteString(": ")
|
||||
if len(v.OurValue()) == 0 {
|
||||
sb.WriteString("NULL")
|
||||
} else {
|
||||
sb.WriteString(ourVD.Format(v.OurValue()))
|
||||
}
|
||||
sb.WriteString(", ")
|
||||
if len(v.TheirValue()) == 0 {
|
||||
sb.WriteString("NULL")
|
||||
} else {
|
||||
sb.WriteString(theirVD.Format(v.TheirValue()))
|
||||
}
|
||||
sb.WriteString(", ")
|
||||
if len(v.BaseValue()) == 0 {
|
||||
sb.WriteString("NULL")
|
||||
} else {
|
||||
sb.WriteString(baseVD.Format(v.BaseValue()))
|
||||
}
|
||||
sb.WriteString(",\n")
|
||||
}
|
||||
sb.WriteString("}")
|
||||
return sb.String(), nil
|
||||
}
|
||||
@@ -32,10 +32,6 @@ func ValueFromMap(m prolly.Map) types.Value {
|
||||
return tree.ValueFromNode(m.Node())
|
||||
}
|
||||
|
||||
func ValueFromConflictMap(m prolly.ConflictMap) types.Value {
|
||||
return tree.ValueFromNode(m.Node())
|
||||
}
|
||||
|
||||
func ValueFromArtifactMap(m prolly.ArtifactMap) types.Value {
|
||||
return tree.ValueFromNode(m.Node())
|
||||
}
|
||||
@@ -47,14 +43,6 @@ func MapFromValue(v types.Value, sch schema.Schema, ns tree.NodeStore) prolly.Ma
|
||||
return prolly.NewMap(root, ns, kd, vd)
|
||||
}
|
||||
|
||||
func ConflictMapFromValue(v types.Value, ourSchema, theirSchema, baseSchema schema.Schema, ns tree.NodeStore) prolly.ConflictMap {
|
||||
root := NodeFromValue(v)
|
||||
kd, ourVD := MapDescriptorsFromSchema(ourSchema)
|
||||
theirVD := ValueDescriptorFromSchema(theirSchema)
|
||||
baseVD := ValueDescriptorFromSchema(baseSchema)
|
||||
return prolly.NewConflictMap(root, ns, kd, ourVD, theirVD, baseVD)
|
||||
}
|
||||
|
||||
func MapDescriptorsFromSchema(sch schema.Schema) (kd, vd val.TupleDesc) {
|
||||
kd = KeyDescriptorFromSchema(sch)
|
||||
vd = ValueDescriptorFromSchema(sch)
|
||||
|
||||
Reference in New Issue
Block a user