Ejemplo n.º 1
0
func main() {

	config.Init("f", "", "benchmark.conf")

	var wg sync.WaitGroup
	var conf Config
	// timer := time.NewTimer(3 * time.Minute)
	if err := config.Load(&conf); err != nil {
		qlog.Fatal("config.Load failed:", err)
		return
	}

	qlog.SetOutputLevel(conf.DebugLevel)
	host, err := url.Parse(conf.URL)
	if err != nil {
		return
	}

	dbUrl := conf.URL + "/query?q=" + url.QueryEscape(fmt.Sprintf("create database %s", conf.Database))
	rpURL := conf.URL + "/query?q=" + url.QueryEscape(fmt.Sprintf("create retention policy %s on %s duration 3d replication 1", conf.URL, conf.Database, conf.Retention))
	http.Get(dbUrl)
	http.Get(rpURL)

	var gorutineClients []*client.Client
	gorutineClients = make([]*client.Client, conf.GorutineNum)

	qlog.Debugf("The gorutineNum is %d", conf.GorutineNum)

	for i := 0; i < conf.GorutineNum; i++ {

		gorutineClients[i], err = client.NewClient(client.Config{URL: *host})
		if err != nil {
			return
		}

		wg.Add(1)
		go writePoints(i, gorutineClients[i], &conf, &wg)
	}
	wg.Wait()

	// <-timer.C
	return
}
Ejemplo n.º 2
0
func main() {
	qlog.SetOutputLevel(0)
	db, err := raftboltdb.NewBoltStore(PATH)
	lastIdx, err := db.LastIndex()
	firtIdx, err := db.FirstIndex()
	for i := int(firtIdx); i <= int(lastIdx); i++ {
		log := new(raft.Log)
		if err = db.GetLog(uint64(i), log); err != nil {
			qlog.Debug(err)
			continue
		}

		switch log.Type {
		case raft.LogCommand:
			qlog.Info("The raftlog type is LogCommand")
			var cmd internal.Command
			if err := proto.Unmarshal(log.Data, &cmd); err != nil {
				qlog.Debug(err)
				continue
			}
			command := cmd.GetType()
			qlog.Infof("The command is: %s", command)
			if command == internal.Command_CreateNodeCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_CreateNodeCommand_Command)
				v, ok := ext.(*internal.CreateNodeCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetHost()", v.GetHost())
			}

			if command == internal.Command_CreateDatabaseCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_CreateDatabaseCommand_Command)
				v, ok := ext.(*internal.CreateDatabaseCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetName()", v.GetName())
				qlog.Debug("v.String()", v.String())
			}

			if command == internal.Command_CreateRetentionPolicyCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_CreateRetentionPolicyCommand_Command)
				v, ok := ext.(*internal.CreateRetentionPolicyCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetDatabase()", v.GetDatabase())
				qlog.Debug("v.GetRetentionPolicy()", v.GetRetentionPolicy())
				qlog.Debug("v.String()", v.String())
			}

			if command == internal.Command_SetDefaultRetentionPolicyCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_SetDefaultRetentionPolicyCommand_Command)
				v, ok := ext.(*internal.SetDefaultRetentionPolicyCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetDatabase()", v.GetDatabase())
				qlog.Debug("v.GetName()", v.GetName())
				qlog.Debug("v.String()", v.String())
			}

		case raft.LogNoop:
			qlog.Info("The raftlog type is LogNoop")
		case raft.LogAddPeer:
			qlog.Info("The raftlog type is LogAddPeer")
			peers := decodePeers(log.Data)

			if len(peers) == 0 {
				qlog.Debug("peers == 0")
				continue
			}
			qlog.Infof("peers is:%s", peers)

		case raft.LogRemovePeer:
			qlog.Info("The raftlog type is LogAddPeer")
		}
	}
	return
}