// Run statisfies the Statement Interface func (i *QueryStatement) Run(s *ponyExpress.StoreFront) { // Set the tracer i.Tracer = ponyExpress.NewTracer(i.tags()) vals := make(map[string]interface{}) var point models.Point runtime := time.Now() for j := 0; j < i.Count; j++ { // If the query is a simple query, send it. if len(i.Args) == 0 { b := []byte(i.TemplateString) // Make the package p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer) // Increment the tracer i.Tracer.Add(1) // Send the package s.SendPackage(p) } else { // Otherwise cherry pick field values from the commune? // TODO: Currently the program lock up here if s.GetPoint // cannot return a value, which can happen. // Seee insert.go s.Lock() point = s.GetPoint(i.Name, s.Precision) s.Unlock() setMapValues(vals, point) // Set the template string with args from the commune b := []byte(fmt.Sprintf(i.TemplateString, setArgs(vals, i.Args)...)) // Make the package p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer) // Increment the tracer i.Tracer.Add(1) // Send the package s.SendPackage(p) } } // Wait for all operations to finish i.Tracer.Wait() // Stop time timer i.runtime = time.Since(runtime) }
// Run statisfies the Statement Interface func (i *InfluxqlStatement) Run(s *ponyExpress.StoreFront) { // Set the tracer i.Tracer = ponyExpress.NewTracer(i.tags()) // Make the Package p := ponyExpress.NewPackage(ponyExpress.Query, []byte(i.Query), i.StatementID, i.Tracer) // Increment the tracer i.Tracer.Add(1) // Send the Package s.SendPackage(p) // Wait for all operations to finish i.Tracer.Wait() }
// Run statisfies the Statement Interface func (i *InsertStatement) Run(s *ponyExpress.StoreFront) { // Set variables on the InsertStatement and make the comCh comCh := i.SetVars(s) // TODO: Refactor to eleminate the ctr // Start the counter ctr := 0 // Create the first bytes buffer buf := bytes.NewBuffer([]byte{}) runtime := time.Now() for k := 0; k < i.Timestamp.Count; k++ { // Increment the counter. ctr == k + 1? ctr++ // Make the point from the template string and the stringers point := fmt.Sprintf(i.TemplateString, i.stringers.Eval(i.time)...) // Add the string to the buffer buf.WriteString(point) // Add a newline char to seperate the points buf.WriteString("\n") // If len(batch) == batchSize then send it if ctr%s.BatchSize == 0 && ctr != 0 { b := buf.Bytes() // Trimming the trailing newline character b = b[0 : len(b)-1] // Create the package p := ponyExpress.NewPackage(ponyExpress.Write, b, i.StatementID, i.Tracer) // Use Tracer to wait for all operations to finish i.Tracer.Add(1) // Send the package s.SendPackage(p) // Reset the bytes Buffer temp := bytes.NewBuffer([]byte{}) buf = temp } // TODO: Racy // Has to do with InsertStatement and QueryStatement communication if len(comCh) < cap(comCh) { select { case comCh <- point: break default: break } } } // If There are additional points remaining in the buffer send them before exiting if buf.Len() != 0 { b := buf.Bytes() // Trimming the trailing newline character b = b[0 : len(b)-1] // Create the package p := ponyExpress.NewPackage(ponyExpress.Write, b, i.StatementID, i.Tracer) // Use Tracer to wait for all operations to finish i.Tracer.Add(1) // Send the package s.SendPackage(p) } // Wait for all tracers to decrement i.Tracer.Wait() // Stop the timer i.runtime = time.Since(runtime) }