From ea1f3570e0acefa68a88e5e861213a705f117684 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期四, 14 五月 2020 15:00:02 +0800
Subject: [PATCH] fix ExecuteWriteSql db is nil

---
 agent.go |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/agent.go b/agent.go
index fb48647..3d052b2 100644
--- a/agent.go
+++ b/agent.go
@@ -36,7 +36,6 @@
 	"github.com/hashicorp/serf/serf"
 	//"github.com/apache/servicecomb-service-center/pkg/log"
 	"log"
-	"runtime/debug"
 )
 
 const (
@@ -96,7 +95,7 @@
 // Start agent
 func (a *Agent) Start(ctx context.Context) {
 	log.Println("aaaaaaaaa")
-	log.Println(string(debug.Stack()))
+	//log.Println(string(debug.Stack()))
 	//debug.PrintStack()
 	err := a.Agent.Start()
 	if err != nil {
@@ -168,9 +167,6 @@
 				return
 			}
 			if sqlUe.Owner != a.conf.NodeName {
-				//ExecuteWriteSql(sqlUe.Sql, true)
-				//flag, _ := ExecuteSqlByGorm(sqlUe.Sql)
-				//fmt.Println("userEvent exec 1 ", sqlUe.Sql, ",Result:", results)
 				if receiveSqlInterface != nil && sqlUe.Sql !=nil && len(sqlUe.Sql) > 0 {
 					receiveSqlInterface.Forward(sqlUe.Sql[0])
 				}
@@ -220,8 +216,10 @@
 			fmt.Println("androidSync len(bytesReturn): ", len(bytesReturn))
 			if query, ok := event.(*serf.Query); ok {
 				if err := query.Respond(bytesReturn); err != nil {
-					//fmt.Printf("err: %s\n", err)
+					fmt.Println("androidSync query.Respond err:", err)
 					return
+				} else {
+					fmt.Println("androidSync query.Respond success")
 				}
 			}
 		}
@@ -231,9 +229,8 @@
 				leaveMember := ev.Members[0]
 				leaveSql := "delete from cluster_node where node_id='" + leaveMember.Name + "'"
 				//fmt.Println("leaveSql:", leaveSql)
-				_, err := ExecuteWriteSql([]string{leaveSql}, false)
-				if err != nil {
-					//fmt.Printf("err: %s\n", err)
+				if !DbHandle.Execute(leaveSql) {
+					fmt.Println("DbHandle.Execute ret false")
 				}
 
 				//fmt.Println("EventMemberLeave,current Members:", ev.Members)
@@ -491,11 +488,13 @@
 		for {
 			select {
 			case r := <-respCh:
-				//fmt.Println("Query response's len:", len(r.Payload))
+				fmt.Println("Query response's len:", len(r.Payload))
 				err := json.Unmarshal(r.Payload, &dumpSqls)
 				if err == nil {
-					//fmt.Println("dumpSql:", dumpSqls)
-					//fmt.Println("data dump success")
+					fmt.Println("dumpSql:", dumpSqls)
+					fmt.Println("data dump success")
+				} else {
+					fmt.Println("Query response.err:", err)
 				}
 				return
 			}

--
Gitblit v1.8.0