Commit 7fe0d5a4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 897b9100
......@@ -405,7 +405,7 @@ func (conn *Connection) resyncAndDBUnlock(txn transaction.Transaction, at Tid) {
// both conn.at and at are covered by δtail - we can invalidate selectively
if (δtail.Tail() < conn.at && conn.at <= δtail.Head()) && // XXX conn.at can = δtail.Tail
(δtail.Tail() < at && at <= δtail.Head()) {
var δv []δRevEntry
var δv []ΔRevEntry
if conn.at <= at {
δv = δtail.SliceByRev(conn.at, at)
} else {
......@@ -414,7 +414,7 @@ func (conn *Connection) resyncAndDBUnlock(txn transaction.Transaction, at Tid) {
}
for _, δ := range δv {
for _, oid := range δ.changev {
for _, oid := range δ.Changev {
δobj[oid] = struct{}{}
}
}
......
......@@ -59,18 +59,18 @@ import (
type ΔTail struct {
head Tid
tail Tid
tailv []δRevEntry // XXX -> revv ?
tailv []ΔRevEntry // XXX -> revv ?
lastRevOf map[Oid]Tid // index for LastRevOf queries
// XXX -> lastRevOf = {} oid -> []rev↑ if linear scan in LastRevOf starts to eat cpu
}
// δRevEntry represents information of what have been changed in one revision.
// ΔRevEntry represents information of what have been changed in one revision.
//
// XXX -> CommitEvent? -> ΔRevEntry?
type δRevEntry struct {
rev Tid
changev []Oid
// XXX -> CommitEvent?
type ΔRevEntry struct {
Rev Tid
Changev []Oid
}
// NewΔTail creates new ΔTail object.
......@@ -112,7 +112,7 @@ func (δtail *ΔTail) Tail() Tid {
// the caller must not modify returned slice.
//
// Note: contrary to regular go slicing, low is exclusive while high is inclusive.
func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []ΔRevEntry {
tail := δtail.Tail()
head := δtail.head
if !(tail <= low && low <= high && high <= head) {
......@@ -128,14 +128,14 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
// find max j : [j].rev ≤ high XXX linear scan -> binary search
j := len(tailv)-1
for ; j >= 0 && tailv[j].rev > high; j-- {}
for ; j >= 0 && tailv[j].Rev > high; j-- {}
if j < 0 {
return nil // ø
}
// find max i : [i].rev > low XXX linear scan -> binary search
i := j
for ; i >= 0 && tailv[i].rev > low; i-- {}
for ; i >= 0 && tailv[i].Rev > low; i-- {}
i++
return tailv[i:j+1]
......@@ -154,7 +154,7 @@ func (δtail *ΔTail) Append(rev Tid, changev []Oid) {
}
δtail.head = rev
δtail.tailv = append(δtail.tailv, δRevEntry{rev, changev})
δtail.tailv = append(δtail.tailv, ΔRevEntry{rev, changev})
for _, id := range changev {
δtail.lastRevOf[id] = rev
}
......@@ -169,14 +169,14 @@ func (δtail *ΔTail) ForgetPast(revCut Tid) {
icut := 0
for i, δ := range δtail.tailv {
rev := δ.rev
rev := δ.Rev
if rev > revCut {
break
}
icut = i+1
// if forgotten revision was last for id, we have to update lastRevOf index
for _, id := range δ.changev {
for _, id := range δ.Changev {
if δtail.lastRevOf[id] == rev {
delete(δtail.lastRevOf, id)
}
......@@ -187,7 +187,7 @@ func (δtail *ΔTail) ForgetPast(revCut Tid) {
// 1) growing underlying storage array indefinitely
// 2) keeping underlying storage after forget
l := len(δtail.tailv)-icut
tailv := make([]δRevEntry, l)
tailv := make([]ΔRevEntry, l)
copy(tailv, δtail.tailv[icut:])
δtail.tailv = tailv
......@@ -226,8 +226,8 @@ func (δtail *ΔTail) LastRevOf(id Oid, at Tid) (_ Tid, exact bool) {
if l == 0 {
return at, false
}
revMin := δtail.tailv[0].rev
revMax := δtail.tailv[l-1].rev
revMin := δtail.tailv[0].Rev
revMax := δtail.tailv[l-1].Rev
if !(revMin <= at && at <= revMax) {
return at, false
}
......@@ -235,7 +235,7 @@ func (δtail *ΔTail) LastRevOf(id Oid, at Tid) (_ Tid, exact bool) {
// we have the coverage
rev, ok := δtail.lastRevOf[id]
if !ok {
return δtail.tailv[0].rev, false
return δtail.tailv[0].Rev, false
}
if rev <= at {
......@@ -246,17 +246,17 @@ func (δtail *ΔTail) LastRevOf(id Oid, at Tid) (_ Tid, exact bool) {
// XXX linear scan - see .lastRevOf comment.
for i := l - 1; i >= 0; i-- {
δ := δtail.tailv[i]
if δ.rev > at {
if δ.Rev > at {
continue
}
for _, δid := range δ.changev {
for _, δid := range δ.Changev {
if id == δid {
return δ.rev, true
return δ.Rev, true
}
}
}
// nothing found
return δtail.tailv[0].rev, false
return δtail.tailv[0].Rev, false
}
......@@ -28,22 +28,22 @@ import (
func TestΔTail(t *testing.T) {
var δtail *ΔTail
// R is syntactic sugar to create 1 δRevEntry
R := func(rev Tid, changev ...Oid) δRevEntry {
return δRevEntry{rev, changev}
// R is syntactic sugar to create 1 ΔRevEntry
R := func(rev Tid, changev ...Oid) ΔRevEntry {
return ΔRevEntry{rev, changev}
}
// δAppend is syntactic sugar for δtail.Append
δAppend := func(δ δRevEntry) {
δtail.Append(δ.rev, δ.changev)
δAppend := func(δ ΔRevEntry) {
δtail.Append(δ.Rev, δ.Changev)
}
// δCheck verifies that δtail state corresponds to provided tailv
δCheck := func(tail, head Tid, tailv ...δRevEntry) {
δCheck := func(tail, head Tid, tailv ...ΔRevEntry) {
t.Helper()
for i := 1; i < len(tailv); i++ {
if !(tailv[i-1].rev < tailv[i].rev) {
if !(tailv[i-1].Rev < tailv[i].Rev) {
panic("test tailv: rev not ↑")
}
}
......@@ -86,13 +86,13 @@ func TestΔTail(t *testing.T) {
// make sure returned region is indeed correct
tbefore := Tid(0)
if ilo-1 >= 0 {
tbefore = tailv[ilo-1].rev-1
tbefore = tailv[ilo-1].Rev-1
}
tail := tailv[ilo].rev-1
head := tailv[ihi-1].rev
tail := tailv[ilo].Rev-1
head := tailv[ihi-1].Rev
hafter := TidMax
if ihi < len(tailv) {
hafter = tailv[ihi].rev
hafter = tailv[ihi].Rev
}
if !(tbefore < rlo && rlo <= tail && head <= rhi && rhi < hafter) {
......@@ -105,23 +105,23 @@ func TestΔTail(t *testing.T) {
for ihi := ilo; ihi < len(tailv); ihi++ {
// [ilo, ihi)
sliceByRev(
tailv[ilo].rev - 1,
tailv[ihi].rev - 1,
tailv[ilo].Rev - 1,
tailv[ihi].Rev - 1,
ilo, ihi,
)
// [ilo, ihi]
sliceByRev(
tailv[ilo].rev - 1,
tailv[ihi].rev,
tailv[ilo].Rev - 1,
tailv[ihi].Rev,
ilo, ihi+1,
)
// (ilo, ihi]
if ilo+1 < len(tailv) {
sliceByRev(
tailv[ilo].rev,
tailv[ihi].rev,
tailv[ilo].Rev,
tailv[ihi].Rev,
ilo+1, ihi+1,
)
}
......@@ -129,8 +129,8 @@ func TestΔTail(t *testing.T) {
// (ilo, ihi)
if ilo+1 < len(tailv) && ilo+1 <= ihi {
sliceByRev(
tailv[ilo].rev,
tailv[ihi].rev - 1,
tailv[ilo].Rev,
tailv[ihi].Rev - 1,
ilo+1, ihi,
)
}
......@@ -140,13 +140,13 @@ func TestΔTail(t *testing.T) {
// verify lastRevOf query / index
lastRevOf := make(map[Oid]Tid)
for _, δ := range tailv {
for _, id := range δ.changev {
idRev, exact := δtail.LastRevOf(id, δ.rev)
if !(idRev == δ.rev && exact) {
t.Fatalf("LastRevOf(%v, at=%s) -> %s, %v ; want %s, %v", id, δ.rev, idRev, exact, δ.rev, true)
for _, id := range δ.Changev {
idRev, exact := δtail.LastRevOf(id, δ.Rev)
if !(idRev == δ.Rev && exact) {
t.Fatalf("LastRevOf(%v, at=%s) -> %s, %v ; want %s, %v", id, δ.Rev, idRev, exact, δ.Rev, true)
}
lastRevOf[id] = δ.rev
lastRevOf[id] = δ.Rev
}
}
......@@ -255,7 +255,7 @@ func TestΔTail(t *testing.T) {
// access to whole underlying array from a slice.
}
func tailvEqual(a, b []δRevEntry) bool {
func tailvEqual(a, b []ΔRevEntry) bool {
// for empty one can be nil and another !nil [] = reflect.DeepEqual
// does not think those are equal.
return (len(a) == 0 && len(b) == 0) ||
......
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