From ef47f7a222924a3161d5e376c80c450873bb7263 Mon Sep 17 00:00:00 2001 From: Andy Arthur Date: Thu, 21 Jul 2022 15:28:25 -0700 Subject: [PATCH] Remove Super Schema field from RootValue flatbuffer schema --- go/gen/fb/serial/rootvalue.go | 42 +------------ go/libraries/doltcore/doltdb/root_val.go | 79 +----------------------- go/serial/rootvalue.fbs | 1 - go/store/types/serial_message.go | 11 ---- 4 files changed, 3 insertions(+), 130 deletions(-) diff --git a/go/gen/fb/serial/rootvalue.go b/go/gen/fb/serial/rootvalue.go index 5ebfa53f51..53ea2c8f87 100644 --- a/go/gen/fb/serial/rootvalue.go +++ b/go/gen/fb/serial/rootvalue.go @@ -127,42 +127,8 @@ func (rcv *RootValue) MutateForeignKeyAddr(j int, n byte) bool { return false } -func (rcv *RootValue) SuperSchemasAddr(j int) byte { - o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) - if o != 0 { - a := rcv._tab.Vector(o) - return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) - } - return 0 -} - -func (rcv *RootValue) SuperSchemasAddrLength() int { - o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) - if o != 0 { - return rcv._tab.VectorLen(o) - } - return 0 -} - -func (rcv *RootValue) SuperSchemasAddrBytes() []byte { - o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) - if o != 0 { - return rcv._tab.ByteVector(o + rcv._tab.Pos) - } - return nil -} - -func (rcv *RootValue) MutateSuperSchemasAddr(j int, n byte) bool { - o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) - if o != 0 { - a := rcv._tab.Vector(o) - return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) - } - return false -} - func RootValueStart(builder *flatbuffers.Builder) { - builder.StartObject(4) + builder.StartObject(3) } func RootValueAddFeatureVersion(builder *flatbuffers.Builder, featureVersion int64) { builder.PrependInt64Slot(0, featureVersion, 0) @@ -179,12 +145,6 @@ func RootValueAddForeignKeyAddr(builder *flatbuffers.Builder, foreignKeyAddr fla func RootValueStartForeignKeyAddrVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1) } -func RootValueAddSuperSchemasAddr(builder *flatbuffers.Builder, superSchemasAddr flatbuffers.UOffsetT) { - builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(superSchemasAddr), 0) -} -func RootValueStartSuperSchemasAddrVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { - return builder.StartVector(1, numElems, 1) -} func RootValueEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } diff --git a/go/libraries/doltcore/doltdb/root_val.go b/go/libraries/doltcore/doltdb/root_val.go index df0e2612bb..f873ade7ff 100644 --- a/go/libraries/doltcore/doltdb/root_val.go +++ b/go/libraries/doltcore/doltdb/root_val.go @@ -83,10 +83,8 @@ type rvStorage interface { GetFeatureVersion() (FeatureVersion, bool, error) GetTablesMap(ctx context.Context, vr types.ValueReadWriter, ns tree.NodeStore) (tableMap, error) - GetSuperSchemaMap(ctx context.Context, vr types.ValueReader) (types.Map, bool, error) GetForeignKeys(ctx context.Context, vr types.ValueReader) (types.Value, bool, error) - SetSuperSchemaMap(ctx context.Context, vrw types.ValueReadWriter, m types.Map) (rvStorage, error) SetForeignKeyMap(ctx context.Context, vrw types.ValueReadWriter, m types.Value) (rvStorage, error) SetFeatureVersion(v FeatureVersion) (rvStorage, error) @@ -326,12 +324,10 @@ func EmptyRootValue(ctx context.Context, vrw types.ValueReadWriter, ns tree.Node var empty hash.Hash fkoff := builder.CreateByteVector(empty[:]) - ssoff := builder.CreateByteVector(empty[:]) serial.RootValueStart(builder) serial.RootValueAddFeatureVersion(builder, int64(DoltFeatureVersion)) serial.RootValueAddTables(builder, tablesoff) serial.RootValueAddForeignKeyAddr(builder, fkoff) - serial.RootValueAddSuperSchemasAddr(builder, ssoff) builder.FinishWithFileIdentifier(serial.RootValueEnd(builder), []byte(serial.RootValueFileID)) bs := builder.FinishedBytes() return newRootValue(vrw, ns, types.SerialMessage(bs)) @@ -500,23 +496,6 @@ func (root *RootValue) GenerateTagsForNewColumns( return newTags, nil } -// GerSuperSchemaMap returns the Noms map that tracks SuperSchemas, used to create new RootValues on checkout branch. -func (root *RootValue) GetSuperSchemaMap(ctx context.Context) (types.Map, error) { - return root.getOrCreateSuperSchemaMap(ctx) -} - -func (root *RootValue) getOrCreateSuperSchemaMap(ctx context.Context) (types.Map, error) { - m, found, err := root.st.GetSuperSchemaMap(ctx, root.vrw) - if err != nil { - return types.Map{}, err - } - if found { - return m, nil - } - - return types.NewMap(ctx, root.vrw) -} - func (root *RootValue) GetAllSchemas(ctx context.Context) (map[string]schema.Schema, error) { m := make(map[string]schema.Schema) err := root.IterTables(ctx, func(name string, table *Table, sch schema.Schema) (stop bool, err error) { @@ -839,35 +818,10 @@ func (root *RootValue) HashOf() (hash.Hash, error) { // RenameTable renames a table by changing its string key in the RootValue's table map. In order to preserve // column tag information, use this method instead of a table drop + add. func (root *RootValue) RenameTable(ctx context.Context, oldName, newName string) (*RootValue, error) { - newStorage, err := root.st.EditTablesMap(ctx, root.vrw, root.ns, []tableEdit{{old_name: oldName, name: newName}}) if err != nil { return nil, err } - - ssMap, err := root.getOrCreateSuperSchemaMap(ctx) - if err != nil { - return nil, err - } - - ssv, found, err := ssMap.MaybeGet(ctx, types.String(oldName)) - if err != nil { - return nil, err - } - if found { - ssme := ssMap.Edit().Remove(types.String(oldName)) - ssme = ssme.Set(types.String(newName), ssv) - ssMap, err = ssme.Map(ctx) - if err != nil { - return nil, err - } - - newStorage, err = newStorage.SetSuperSchemaMap(ctx, root.vrw, ssMap) - if err != nil { - return nil, err - } - } - return root.withStorage(newStorage), nil } @@ -1172,18 +1126,6 @@ func (m fbTableMap) Iter(ctx context.Context, cb func(string, hash.Hash) (bool, }) } -func (r fbRvStorage) GetSuperSchemaMap(ctx context.Context, vr types.ValueReader) (types.Map, bool, error) { - addr := hash.New(r.srv.SuperSchemasAddrBytes()) - if addr.IsEmpty() { - return types.Map{}, false, nil - } - v, err := vr.ReadValue(ctx, addr) - if err != nil { - return types.Map{}, false, err - } - return v.(types.Map), true, nil -} - func (r fbRvStorage) GetForeignKeys(ctx context.Context, vr types.ValueReader) (types.Value, bool, error) { addr := hash.New(r.srv.ForeignKeyAddrBytes()) if addr.IsEmpty() { @@ -1196,20 +1138,6 @@ func (r fbRvStorage) GetForeignKeys(ctx context.Context, vr types.ValueReader) ( return v.(types.SerialMessage), true, nil } -func (r fbRvStorage) SetSuperSchemaMap(ctx context.Context, vrw types.ValueReadWriter, m types.Map) (rvStorage, error) { - var h hash.Hash - if !m.Empty() { - ref, err := vrw.WriteValue(ctx, m) - if err != nil { - return nil, err - } - h = ref.TargetHash() - } - ret := r.clone() - copy(ret.srv.SuperSchemasAddrBytes(), h[:]) - return ret, nil -} - func (r fbRvStorage) EditTablesMap(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, edits []tableEdit) (rvStorage, error) { builder := flatbuffers.NewBuilder(80) @@ -1262,12 +1190,10 @@ func (r fbRvStorage) EditTablesMap(ctx context.Context, vrw types.ValueReadWrite tablesoff := builder.CreateByteVector(ambytes) fkoff := builder.CreateByteVector(r.srv.ForeignKeyAddrBytes()) - ssoff := builder.CreateByteVector(r.srv.SuperSchemasAddrBytes()) serial.RootValueStart(builder) serial.RootValueAddFeatureVersion(builder, r.srv.FeatureVersion()) serial.RootValueAddTables(builder, tablesoff) serial.RootValueAddForeignKeyAddr(builder, fkoff) - serial.RootValueAddSuperSchemasAddr(builder, ssoff) builder.FinishWithFileIdentifier(serial.RootValueEnd(builder), []byte(serial.RootValueFileID)) bs := builder.FinishedBytes() return fbRvStorage{serial.GetRootAsRootValue(bs, 0)}, nil @@ -1302,11 +1228,10 @@ func (r fbRvStorage) clone() fbRvStorage { } func (r fbRvStorage) DebugString(ctx context.Context) string { - return fmt.Sprintf("fbRvStorage[%d, %s, %s, %s]", + return fmt.Sprintf("fbRvStorage[%d, %s, %s]", r.srv.FeatureVersion(), "...", // TODO: Print out tables map - hash.New(r.srv.ForeignKeyAddrBytes()).String(), - hash.New(r.srv.SuperSchemasAddrBytes()).String()) + hash.New(r.srv.ForeignKeyAddrBytes()).String()) } func (r fbRvStorage) nomsValue() types.Value { diff --git a/go/serial/rootvalue.fbs b/go/serial/rootvalue.fbs index fd4656623e..3f1b869a88 100644 --- a/go/serial/rootvalue.fbs +++ b/go/serial/rootvalue.fbs @@ -22,7 +22,6 @@ table RootValue { tables:[ubyte]; // Serialized AddressMap. foreign_key_addr:[ubyte]; - super_schemas_addr:[ubyte]; } // KEEP THIS IN SYNC WITH fileidentifiers.go diff --git a/go/store/types/serial_message.go b/go/store/types/serial_message.go index 8a9d5b875d..05f4449d1c 100644 --- a/go/store/types/serial_message.go +++ b/go/store/types/serial_message.go @@ -107,7 +107,6 @@ func (sm SerialMessage) HumanReadableString() string { fmt.Fprintf(ret, "{\n") fmt.Fprintf(ret, "\tFeatureVersion: %d\n", msg.FeatureVersion()) fmt.Fprintf(ret, "\tForeignKeys: #%s\n", hash.New(msg.ForeignKeyAddrBytes()).String()) - fmt.Fprintf(ret, "\tSuperSchema: #%s\n", hash.New(msg.SuperSchemasAddrBytes()).String()) fmt.Fprintf(ret, "\tTables: {\n\t%s", TupleRowStorage(msg.TablesBytes()).HumanReadableString()) fmt.Fprintf(ret, "\t}\n") fmt.Fprintf(ret, "}") @@ -222,16 +221,6 @@ func (sm SerialMessage) walkRefs(nbf *NomsBinFormat, cb RefCallback) error { return err } } - addr = hash.New(msg.SuperSchemasAddrBytes()) - if !addr.IsEmpty() { - r, err := constructRef(nbf, addr, PrimitiveTypeMap[ValueKind], SerialMessageRefHeight) - if err != nil { - return err - } - if err = cb(r); err != nil { - return err - } - } case serial.TableFileID: msg := serial.GetRootAsTable([]byte(sm), 0) addr := hash.New(msg.SchemaBytes())