queryservice.go 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
package main

import (
	"context"
	"fmt"
	"log"

	ds "github.com/zilliztech/milvus-distributed/internal/dataservice"
	dds "github.com/zilliztech/milvus-distributed/internal/distributed/dataservice"
	"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
	"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
	"github.com/zilliztech/milvus-distributed/internal/queryservice"
)

const reTryCnt = 3

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	_, err := queryservice.NewQueryService(ctx)
	if err != nil {
		panic(err)
	}
	log.Printf("query service address : %s:%d", queryservice.Params.Address, queryservice.Params.Port)

	cnt := 0
	// init data service client
	ds.Params.Init()
	log.Printf("data service address : %s:%d", ds.Params.Address, ds.Params.Port)
	dataClient := dds.NewClient(fmt.Sprintf("%s:%d", ds.Params.Address, ds.Params.Port))
	if err = dataClient.Init(); err != nil {
		panic(err)
	}
	for cnt = 0; cnt < reTryCnt; cnt++ {
		dsStates, err := dataClient.GetComponentStates()
		if err != nil {
			log.Printf("retry cout = %d, error = %s", cnt, err.Error())
			continue
		}
		if dsStates.Status.ErrorCode != commonpb.ErrorCode_SUCCESS {
			log.Printf("retry cout = %d, error = %s", cnt, dsStates.Status.Reason)
			continue
		}
		if dsStates.State.StateCode != internalpb2.StateCode_INITIALIZING && dsStates.State.StateCode != internalpb2.StateCode_HEALTHY {
			continue
		}
		break
	}
	if cnt >= reTryCnt {
		panic("connect to data service failed")
	}

	//// init index service client
	//is.Params.Init()
	//log.Printf("index service address : %s:%d", is.Params.Address, is.Params.Port)
	//indexClient := dis.NewClient(fmt.Sprintf("%s:%d", is.Params.Address, is.Params.Port))
	//// TODO: retry to check index service status
	//
	//if err = svr(dataService); err != nil {
	//	panic(err)
	//}
	//
	//log.Printf("index service address : %s", is.Params.Address)
	//indexService := isc.NewClient(is.Params.Address)
	//
	//if err = svr.SetIndexService(indexService); err != nil {
	//	panic(err)
	//}
	//
	//if err = svr.Start(); err != nil {
	//	panic(err)
	//}
	//
	//sc := make(chan os.Signal, 1)
	//signal.Notify(sc,
	//	syscall.SIGHUP,
	//	syscall.SIGINT,
	//	syscall.SIGTERM,
	//	syscall.SIGQUIT)
	//sig := <-sc
	//log.Printf("Got %s signal to exit", sig.String())
	//_ = svr.Stop()
}