Skip to content

Commit

Permalink
add log1 option
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdimidium committed Apr 25, 2024
1 parent adf1337 commit e196be5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions chotki.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Options struct {

Src uint64
Name string
Log1 toyqueue.Records
MaxLogLen int64
RelaxedOrder bool
RestoreNetwork bool
Expand Down Expand Up @@ -214,6 +215,7 @@ func Open(dirname string, opts Options) (*Chotki, error) {
id0 := rdx.IDFromSrcSeqOff(opts.Src, 0, 0)

init := append(toyqueue.Records(nil), Log0...)
init = append(init, opts.Log1...)
init = append(init, toytlv.Record('Y',
toytlv.Record('I', id0.ZipBytes()),
toytlv.Record('R', rdx.ID0.ZipBytes()),
Expand Down
24 changes: 15 additions & 9 deletions log0.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import (
"github.com/drpcorg/chotki/toytlv"
)

const id1 = rdx.ID0 + rdx.ProInc
const ID2 = id1 + rdx.ProInc
const NamesID = ID2 + 1
const NodesID = ID2 + 2
const NodeInfoID = ID2 + 3
const (
id1 = rdx.ID0 + rdx.ProInc
id2 = id1 + rdx.ProInc

IdNames = id2 + 1
IdNodes = id2 + 2
IdNodeInfo = id2 + 3

// ID from which we count user static objects
IdLog1 = id2 + 4
)

// FORMAT: replica creation packet
var Log0 = toyqueue.Records{
Expand All @@ -31,17 +37,17 @@ var Log0 = toyqueue.Records{
toytlv.Record('T', rdx.Ttlv("M")),
),
toytlv.Record('O',
toytlv.Record('I', ID2.ZipBytes()),
toytlv.Record('I', id2.ZipBytes()),
toytlv.Record('R', id1.ZipBytes()),
toytlv.Record('M',
toytlv.Record('T', rdx.Ttlv("0")),
toytlv.Record('R', rdx.Rtlv(rdx.ID0)),
toytlv.Record('T', rdx.Ttlv("Global")),
toytlv.Record('R', rdx.Rtlv(ID2)),
toytlv.Record('R', rdx.Rtlv(id2)),
toytlv.Record('T', rdx.Ttlv("Names")),
toytlv.Record('R', rdx.Rtlv(ID2+1)),
toytlv.Record('R', rdx.Rtlv(IdNames)),
toytlv.Record('T', rdx.Ttlv("Nodes")),
toytlv.Record('R', rdx.Rtlv(ID2+2)),
toytlv.Record('R', rdx.Rtlv(IdNodes)),
),
toytlv.Record('M'),
toytlv.Record('M'),
Expand Down
2 changes: 1 addition & 1 deletion objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (cho *Chotki) IncNField(fid rdx.ID) (id rdx.ID, err error) {
return cho.AddToNField(fid, 1)
}

func (cho *Chotki) ObjectFieldMapTermId(fid rdx.ID) (themap map[string]rdx.ID, err error) {
func (cho *Chotki) ObjectFieldMapTermId(fid rdx.ID) (themap rdx.MapTR, err error) {
rdt, tlv, e := cho.ObjectFieldTLV(fid)
if e != nil {
return nil, e
Expand Down
8 changes: 4 additions & 4 deletions repl/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,21 +583,21 @@ var HelpName = errors.New("name, name Obj, name {Obj: b0b-12-1}")
func (repl *REPL) CommandName(arg *rdx.RDX) (id rdx.ID, err error) {
id = rdx.BadId
var names rdx.MapTR
names, err = repl.Host.ObjectFieldMapTermId(chotki.NamesID)
names, err = repl.Host.ObjectFieldMapTermId(chotki.IdNames)
if err != nil {
return
}
if arg == nil || arg.RdxType == rdx.None {
fmt.Println(names.String())
id = chotki.ID2
id = repl.Host.Last()
} else if arg.RdxType == rdx.Term {
key := string(arg.Text)
fmt.Printf("{%s:%s}\n", key, names[key])
} else if arg.RdxType == rdx.Mapping {
_, tlv, _ := repl.Host.ObjectFieldTLV(chotki.NamesID)
_, tlv, _ := repl.Host.ObjectFieldTLV(chotki.IdNames)
parsed := rdx.MparseTR(arg)
delta := toytlv.Record('M', rdx.MdeltaTR(tlv, parsed))
id, err = repl.Host.EditFieldTLV(chotki.NamesID, delta)
id, err = repl.Host.EditFieldTLV(chotki.IdNames, delta)
} else {
err = HelpName
}
Expand Down

0 comments on commit e196be5

Please sign in to comment.