Commit c1057693 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2bc466f3
......@@ -27,10 +27,10 @@ import (
"bytes"
"context"
"crypto/sha1"
//"io"
"io"
"math"
"net"
//"reflect"
"reflect"
"testing"
"unsafe"
......@@ -473,6 +473,62 @@ func TestMasterStorage(t *testing.T) {
println("444")
// C loads every other {<,=}serial:oid - established link is reused
ziter := zstor.Iterate(0, zodb.TidMax)
// XXX hack: disable tracing early so that C.Load() calls do not deadlock
// TODO refactor cluster creation into func
// TODO move client all loading tests into separate test where tracing will be off
pg.Done()
for {
_, dataIter, err := ziter.NextTxn()
if err == io.EOF {
break
}
if err != nil {
t.Fatalf("ziter.NextTxn: %v", err)
}
for {
datai, err := dataIter.NextData()
if err == io.EOF {
break
}
if err != nil {
t.Fatalf("ziter.NextData: %v", err)
}
for _, tidBefore := range []bool{false, true} {
xid := zodb.Xid{Oid: datai.Oid} // {=,<}tid:oid
xid.Tid = datai.Tid
xid.TidBefore = tidBefore
if tidBefore {
xid.Tid++
}
println("555")
data, tid, err := C.Load(bg, xid)
println("777")
if datai.Data != nil {
if !(bytes.Equal(data, datai.Data) && tid == datai.Tid && err == nil) {
t.Fatalf("load: %v:\nhave: %v %v %q\nwant: %v nil %q",
xid, tid, err, data, datai.Tid, datai.Data)
}
} else {
// deleted
errWant := &zodb.ErrXidMissing{xid}
if !(data == nil && tid == 0 && reflect.DeepEqual(err, errWant)) {
t.Fatalf("load: %v:\nhave: %v, %#v, %#v\nwant: %v, %#v, %#v",
xid, tid, err, data, zodb.Tid(0), errWant, []byte(nil))
}
}
}
}
}
......
......@@ -200,13 +200,15 @@ package tracing
import (
"sync"
"sync/atomic"
"fmt"
)
// big tracing lock
var traceMu sync.Mutex
var traceLocked int32 // for cheap protective checks whether Lock is held
// Lock serializes modification access to tracepoints
// Lock serializes modification access to tracepoints.
//
// Under Lock it is safe to attach/detach probes to/from tracepoints:
// - no other goroutine is attaching or detaching probes from tracepoints,
......@@ -249,13 +251,15 @@ type Probe struct {
// probefunc func(some arguments)
}
// Next returns next probe attached to the same tracepoint
// Next returns next probe attached to the same tracepoint.
//
// It is safe to iterate Next under any conditions.
func (p *Probe) Next() *Probe {
return p.next
}
// AttachProbe attaches newly created Probe to the end of a probe list
// AttachProbe attaches newly created Probe to the end of a probe list.
//
// If group is non-nil the probe is also added to the group.
// Must be called under Lock.
// Probe must be newly created.
......@@ -283,7 +287,8 @@ func AttachProbe(pg *ProbeGroup, listp **Probe, probe *Probe) {
}
}
// Detach detaches probe from a tracepoint
// Detach detaches probe from a tracepoint.
//
// Must be called under Lock
func (p *Probe) Detach() {
verifyLocked()
......@@ -313,19 +318,21 @@ func (p *Probe) Detach() {
p.prev = p
}
// ProbeGroup is a group of probes attached to tracepoints
// ProbeGroup is a group of probes attached to tracepoints.
type ProbeGroup struct {
probev []*Probe
}
// Add adds a probe to the group
// Add adds a probe to the group.
//
// Must be called under Lock
func (pg *ProbeGroup) Add(p *Probe) {
verifyLocked()
pg.probev = append(pg.probev, p)
}
// Done detaches all probes registered to the group
// Done detaches all probes registered to the group.
//
// Must be called under normal conditions, not under Lock
func (pg *ProbeGroup) Done() {
verifyUnlocked()
......@@ -333,6 +340,7 @@ func (pg *ProbeGroup) Done() {
defer Unlock()
for _, p := range pg.probev {
fmt.Printf("detaching %#v\n", p)
p.Detach()
}
pg.probev = nil
......
......@@ -59,7 +59,7 @@ func NewSyncTracer() *SyncTracer {
// Trace1 sends message with 1 tracing event to a consumer and waits for ack
func (st *SyncTracer) Trace1(event interface{}) {
ack := make(chan struct{})
//fmt.Printf("trace: send: %T %v\n", event, event)
fmt.Printf("trace: send: %T %v\n", event, event)
st.tracech <- &SyncTraceMsg{event, ack}
<-ack
}
......
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