From 54480e6f402018d29f62b861179a280a3c2e6cb5 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 14 五月 2020 13:57:02 +0800 Subject: [PATCH] rm no use import --- agent.go | 70 ++++++++++++++++++++-------------- 1 files changed, 41 insertions(+), 29 deletions(-) diff --git a/agent.go b/agent.go index c3b488c..ac0ff1f 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 { @@ -130,6 +129,26 @@ receiveSqlInterface = c } +type DbHandler interface { + Execute(sql string) bool +} + +type DbDumpHandler interface { + Dump(tables string) string +} + +//鏁版嵁搴揺xecute鍙ユ焺 +var DbHandle DbHandler +//鏁版嵁搴撳浠藉彞鏌�,鍙湪syncdb涓敤鍒� +var dbDumpH DbDumpHandler + +func RegisterDbHandler(h DbHandler) { + DbHandle = h +} + +func RegisterDbDumpHandler(h DbDumpHandler) { + dbDumpH = h +} // HandleEvent Handles serf.EventMemberJoin events, // which will wait for members to join until the number of group members is equal to "groupExpect" @@ -192,27 +211,18 @@ //fmt.Println(string(ev.Payload)) var tableNames []string err := json.Unmarshal(ev.Payload, &tableNames) - if err !=nil { - //fmt.Println("Query tableNames unmarshal err") - return - } + fmt.Println("androidSync tableNames:", tableNames, "err:", err) - rows, err := ExecuteQuerySql(tableNames) - if err != nil { - //fmt.Println("err: ", err) - return - } - var rowsReturn []Rows - for _, r := range rows { - rowsReturn = append(rowsReturn, *r) - } + dumpData := dbDumpH.Dump(strings.Join(tableNames, ",")) - bytesReturn, err := json.Marshal(rowsReturn) - //fmt.Println("results: ", bytesReturn) + bytesReturn, _ := json.Marshal(dumpData) + 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") } } } @@ -442,21 +452,21 @@ func (a *Agent) GetTableDataFromCluster(tableNames []string) (*[]string, error) { //members: get name of first member mbs := a.GroupMembers(a.conf.ClusterID) - var specmembername string + specmembername := "" for _, m := range mbs { //fmt.Println("m", m) if m.Name != a.conf.NodeName { //鍓嶇紑锛欴SVAD:鍒嗘瀽鏈嶅姟鍣� DSPAD:杩涘嚭鍏ad - if strings.HasPrefix(a.conf.NodeName, "DSVAD"){ - if strings.HasPrefix(m.Name, "DSVAD") { + if strings.HasPrefix(a.conf.NodeName, "PSPAD"){ + if strings.HasPrefix(m.Name, "PSPAD") { specmembername = m.Name break } - }else{ - specmembername = m.Name - break } } } + //if specmembername == "" { + // return nil, errors.New("other pad node not found in memberlist") + //} //fmt.Println("mbs:", mbs, "a.conf.BindAddr:", a.conf.BindAddr, "specmembername:", specmembername) //query: get db file. @@ -469,9 +479,9 @@ resp, err := a.Query(QueryEventUpdateDBData, tBytes, ¶ms) if err == nil || !strings.Contains(err.Error(), "cannot contain") { - //fmt.Println("err: ", err) + //fmt.Println("QueryEventUpdateDBData err: ") } - //fmt.Println("Query.resp.err:", err, "resp:", resp) + fmt.Println("Query.resp.err:", err, "resp:", resp) var wg sync.WaitGroup wg.Add(1) @@ -482,11 +492,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