Commit 70a447bf authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 17bc9b4e
// Code generated by gen-set Tree *Tree; DO NOT EDIT.
// Copyright (C) 2015-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package main
// SetTree is a set of *Tree.
type SetTree map[*Tree]struct{}
// Add adds v to the set.
func (s SetTree) Add(v *Tree) {
s[v] = struct{}{}
}
// Del removes v from the set.
// it is noop if v was not in the set.
func (s SetTree) Del(v *Tree) {
delete(s, v)
}
// Has checks whether the set contains v.
func (s SetTree) Has(v *Tree) bool {
_, ok := s[v]
return ok
}
// Update adds t values to s.
func (s SetTree) Update(t SetTree) {
for v := range t {
s.Add(v)
}
}
// Elements returns all elements of set as slice.
func (s SetTree) Elements() []*Tree {
ev := make([]*Tree, len(s))
i := 0
for e := range s {
ev[i] = e
i++
}
return ev
}
......@@ -21,7 +21,7 @@ package main
// XXX -> Package xbtree complements package lab.nexedi.com/kirr/neo/go/zodb/btree.
// TODO move -> btree when ΔTail matures.
//go:generate ./gen-set main Tree *Tree zset_tree.go
////go:generate ./gen-set main Tree *Tree zset_tree.go
////go:generate ./gen-set main Value Value zset_value.go
//go:generate ./gen-set main Oid Oid zset_oid.go
......@@ -65,11 +65,11 @@ type SetKey = SetI64
//
// It covers only changes to keys from tracked subset of BTrees parts.
// In particular a key that was not explicitly requested to be tracked, even if
// it was changes in δZ, is not guaranted to be present in δB.
// it was changed in δZ, is not guaranted to be present in δB.
//
// ΔBtail provides the following operations:
//
// .Track(path) - start tracking tree nodes and keys; root=path[0], keys=path[-1].keys
// .Track(path) - start tracking tree nodes and keys; root=path[0], keys=path[-1].keys XXX keys not correct - e.g. track missing key
//
// .Update(δZ) -> δB - update BTree δ tail given raw ZODB changes
// .ForgetPast(revCut) - forget changes past revCut
......@@ -93,18 +93,21 @@ type ΔBtail struct {
// includes all changed objects, not only tracked ones.
δZtail *zodb.ΔTail
δRtail []ΔRoots // which BTree were changed; Noted only by keys ∈ tracket subset
byRoot map[*Tree]*ΔTtail // root -> k/v change history; only for keys ∈ tracket subset
// XXX vvv keys keys ∈ tracket -> keys ∈ kadj[tracket] ?
// δRtail []ΔRoots // which BTree were changed; Noted only by keys ∈ tracket subset
// byRoot map[*Tree]*ΔTtail // root -> k/v change history; only for keys ∈ tracket subset
byRoot map[zodb.Oid]*ΔTtail // root -> k/v change history; only for keys ∈ tracket subset
// XXX or ask client to provide db on every call?
db *zodb.DB // to open connections to load new/old tree|buckets
// tracked index: BTree|Bucket -> top tree element.
// XXX allow only single root (else it is "tree corrupt") ?
trackIdx map[zodb.Oid]SetTree // oid -> {} roots XXX root -> oid
// XXX as of @head state
trackIdx map[zodb.Oid]SetOid // oid -> {} roots
// tracked objects that are not yet taken into account in current δBtail
trackNew map[zodb.Oid]struct{} // XXX SetOid
trackNew SetOid
}
// ΔB represents a change in BTrees space.
......@@ -113,11 +116,13 @@ type ΔB struct {
ByRoot map[zodb.Oid]map[Key]Value // {} root -> {}(key, value)
}
/*
// ΔRoots describes which BTrees were change in one revision.
type ΔRoots struct {
Rev zodb.Tid
Roots []*Tree // root XXX -> Oid? XXX -> SetTree?
}
*/
// ΔTtail represent tail of revisional changes to one BTree.
//
......@@ -145,8 +150,8 @@ type ΔTree struct {
func NewΔBtail(at0 zodb.Tid) *ΔBtail {
return &ΔBtail{
δZtail: zodb.NewΔTail(at0),
byRoot: make(map[*Tree]*ΔTtail),
trackIdx: make(map[zodb.Oid]SetTree),
byRoot: make(map[zodb.Oid]*ΔTtail),
trackIdx: make(map[zodb.Oid]SetOid),
}
}
......@@ -190,14 +195,15 @@ func (δBtail *ΔBtail) Track(path []Node, flags TrackFlags) { // XXX Tree|Bucke
if l == 0 {
panic("empty path")
}
root := path[0].(*Tree)
treeRoot := path[0].(*Tree)
// XXX assert Tree Tree ... Tree Bucket
root := treeRoot.POid()
for _, node := range path {
oid := node.POid()
nodeRoots, ok := δBtail.trackIdx[oid]
if !ok {
nodeRoots = make(SetTree)
nodeRoots = make(SetOid)
δBtail.trackIdx[oid] = nodeRoots
// XXX .trackNew += oid
}
......@@ -231,7 +237,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) ΔB {
continue
}
for root := range roots {
δZByRoot[root.POid()] = append(δZByRoot[root.POid()], oid)
δZByRoot[root] = append(δZByRoot[root], oid)
}
}
......@@ -296,7 +302,7 @@ func (δΒtail *ΔBtail) Get(ctx context.Context, root *Tree, key Key, at zodb.T
// XXX dirty -> rebuild
// XXX -> index lastXXXOf(key) | linear scan ↓ looking for change <= at
δTtail := δΒtail.byRoot[root]
δTtail := δΒtail.byRoot[root.POid()]
if δTtail == nil {
panicf("δBtail: root<%s> not tracked", root.POid())
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment