From 1e6e48cc3ac0c9b8894db9cd7cef1ccf4f3573e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ber=C4=8Di=C4=8D?= Date: Thu, 22 Aug 2019 16:29:50 +0200 Subject: [PATCH] tmp-debug --- go/storage/client/client.go | 17 ++++++++++++++++- go/storage/client/watcher.go | 19 ++++++++++++++++++- go/storage/mkvs/urkel/urkel_test.go | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/go/storage/client/client.go b/go/storage/client/client.go index 6d92a42496f..17cfd7a828d 100644 --- a/go/storage/client/client.go +++ b/go/storage/client/client.go @@ -5,8 +5,10 @@ package client import ( "context" cryptorand "crypto/rand" + "fmt" "io" "math/rand" + "os" "sync" "time" @@ -78,6 +80,7 @@ func (b *storageClientBackend) getStorageWatcher(runtimeID signature.MapKey) (st defer b.runtimeWatchersLock.RUnlock() watcher := b.runtimeWatchers[runtimeID] + fmt.Printf("getStorageWatcher on %p returning %p from %+v\n", b, watcher, b.runtimeWatchers) if watcher == nil { b.logger.Error("worker/storage/client: no watcher for runtime", "runtime_id", runtimeID, @@ -113,6 +116,8 @@ func (b *storageClientBackend) WatchRuntime(id signature.PublicKey) error { // Watcher doesn't exist. Start new watcher. watcher = newWatcher(b.ctx, id, b.identity.TLSCertificate, b.scheduler, b.registry) b.runtimeWatchers[id.ToMapKey()] = watcher + fmt.Printf("inserted watcher %p into runtimeWatchers\n", watcher) + os.Stdout.Sync() // Signal init when the first registered runtime is initialized. if !b.signaledInit { @@ -480,6 +485,7 @@ func (b *storageClientBackend) readWithClient( } clientStates := watcher.getClientStates() + fmt.Printf("client %p: client states array from watcher %p is %+v\n", b, watcher, clientStates) n := len(clientStates) if n == 0 { b.logger.Error("readWithClient: no connected nodes for runtime", @@ -498,7 +504,16 @@ func (b *storageClientBackend) readWithClient( state := clientStates[randIndex] // Skip this node when reading. - if state.node.ID.Equal(b.identity.NodeSigner.Public()) { + node := state.node + if node == nil { + fmt.Printf("\033[31;1m ** node is nil\033[0m %+v\n", state) + time.Sleep(2 * time.Second) + } + //nodeId := node.ID + identity := b.identity + signer := identity.NodeSigner + selfID := signer.Public() + if node != nil && node.ID.Equal(selfID) { continue } diff --git a/go/storage/client/watcher.go b/go/storage/client/watcher.go index f72d8d0abd6..05ceadcc86a 100644 --- a/go/storage/client/watcher.go +++ b/go/storage/client/watcher.go @@ -4,6 +4,8 @@ import ( "context" "crypto/tls" "crypto/x509" + "fmt" + "os" "sync" "google.golang.org/grpc" @@ -49,10 +51,12 @@ func (w *debugWatcherState) initialized() <-chan struct{} { func newDebugWatcher(state *clientState) storageWatcher { initCh := make(chan struct{}) close(initCh) - return &debugWatcherState{ + ret := &debugWatcherState{ initCh: initCh, clientState: state, } + fmt.Printf("created debug watcher %p\n", ret) + return ret } // watcherState contains storage watcher state. @@ -117,9 +121,14 @@ func (w *watcherState) getClientStates() []clientState { w.RLock() defer w.RUnlock() clientStates := []clientState{} + fmt.Printf(">>>>\n") + fmt.Printf("current clientStates array is %+v\n", w.clientStates) + defer fmt.Printf("watcher %p returning actual array %+v\n", w, clientStates) for _, state := range w.clientStates { clientStates = append(clientStates, *state) + fmt.Printf("copied %+v into %+v\n", *state, clientStates[len(clientStates)-1]) } + fmt.Printf("<<<<\n") return clientStates } func (w *watcherState) updateStorageNodeConnections() { @@ -203,16 +212,21 @@ func (w *watcherState) updateStorageNodeConnections() { manualResolver.UpdateState(resolverState) numConnNodes++ + if node == nil { + fmt.Printf("\033[31;1m ** node is nil in watcher\033[0m\n") + } connClientStates = append(connClientStates, &clientState{ node: node, client: storage.NewStorageClient(conn), conn: conn, resolverCleanupCb: cleanupCb, }) + fmt.Printf("appended new clientState: %+v\n", connClientStates[len(connClientStates)-1]) w.logger.Debug("storage node connection updated", "node", node, ) } + fmt.Printf("--------------\n") if numConnNodes == 0 { w.logger.Error("failed to connect to any of the storage committee members", "nodes", nodeList, @@ -262,6 +276,7 @@ func (w *watcherState) watch(ctx context.Context) { nodeListCh, sub := w.registry.WatchNodeList() defer sub.Close() + fmt.Printf("watcher %p starting up\n", w) for { select { case <-ctx.Done(): @@ -330,6 +345,8 @@ func newWatcher( scheduledNodes: make(map[signature.MapKey]bool), clientStates: []*clientState{}, } + fmt.Printf("created watcher %p\n", watcher) + os.Stdout.Sync() go watcher.watch(ctx) diff --git a/go/storage/mkvs/urkel/urkel_test.go b/go/storage/mkvs/urkel/urkel_test.go index 01d3a3c9808..3e2bed9cbe8 100644 --- a/go/storage/mkvs/urkel/urkel_test.go +++ b/go/storage/mkvs/urkel/urkel_test.go @@ -51,7 +51,7 @@ func writeLogToMap(wl writelog.WriteLog) map[string]string { return writeLogSet } -func foldWriteLogIterator(t *testing.T, w db.WriteLogIterator) writelog.WriteLog { +func foldWriteLogIterator(t *testing.T, w writelog.Iterator) writelog.WriteLog { writeLog := writelog.WriteLog{} for {