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