Example #1
0
func writePoints(num int, gorutineClient *client.Client, conf *Config, wg *sync.WaitGroup) {
	defer wg.Done()

	limit := 0
	// batchCount := 1000 / conf.BatchCountPerSecond
	// writeTimeDuration := (time.Duration(batchCount)) * time.Millisecond

	// writeTimer := time.NewTimer(writeTimeDuration)

	batchSize := conf.BatchSize

	batchPointsInSameSeries := conf.BatchPointsInSameSeries

	tagKeySet := conf.TagKeySet
	fieldKeySet := conf.FieldKeySet

	r := rand.New(rand.NewSource(time.Now().UnixNano()))

	for {
		// <-writeTimer.C
		pts := make([]client.Point, batchSize)

		for i := 0; i < batchSize; i++ {
			tagSet := make(map[string]string, len(tagKeySet))
			// tagSet := make(map[string]string, len(tagKeySet)+1)
			fieldSet := make(map[string]interface{}, len(fieldKeySet))

			for _, tag := range tagKeySet {
				tagSet[tag] = tag + "_" + strconv.Itoa(num)
			}

			if !batchPointsInSameSeries {
				for _, tag := range tagKeySet {
					tagSet[tag] = tag + strconv.Itoa(i)
				}
			}

			for index, val := range fieldKeySet {

				valueContent := conf.FieldValueRange[index]

				if valueContent.Type == "float" {
					start, _ := strconv.ParseFloat(conf.FieldValueRange[index].Start, 32)
					end, _ := strconv.ParseFloat(conf.FieldValueRange[index].End, 32)
					v := start + r.Float64()*(end-start)
					fieldSet[val] = v
				}

				if conf.FieldValueRange[index].Type == "integer" {
					start, _ := strconv.Atoi(conf.FieldValueRange[index].Start)
					end, _ := strconv.Atoi(conf.FieldValueRange[index].End)
					v := start + r.Intn(end-start)
					fieldSet[val] = v
				}

				if conf.FieldValueRange[index].Type == "string" {
				}

				if conf.FieldValueRange[index].Type == "bool" {
				}
			}

			pts[i] = client.Point{
				Measurement: conf.Measurement,
				Tags:        tagSet,
				Fields:      fieldSet,
				Time:        time.Now(),
				Precision:   conf.Precision,
			}
		}

		qlog.Info(pts[0].Time.UnixNano())

		bp := client.BatchPoints{
			Points:          pts,
			Database:        conf.Database,
			RetentionPolicy: conf.Retention,
		}

		qlog.Debugf("gorutine number is %d, Write %d points", num, len(bp.Points))

		_, err := gorutineClient.Write(bp)

		if err != nil {
			qlog.Debug(err)
			return
		}
		limit++
		if limit == conf.GorutineBatchLimit {
			qlog.Debugf("The %d has finished %d batches", num, limit)
			return
		}

		// writeTimer.Reset(writeTimeDuration)
	}
}
Example #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
}