Example #1
0
// JailTail opens a file within this worker's jail directory and prepares a
// cross-circuit pointer to the open file
func (a *Acid) JailTail(jailFile string) (circuit.X, error) {
	abs := path.Join(config.Config.Deploy.JailDir(), circuit.WorkerAddr().WorkerID().String(), jailFile)

	cmd := exec.Command("/bin/sh", "-c", "tail -f "+abs)

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, circuit.FlattenError(err)
	}

	if err = cmd.Start(); err != nil {
		return nil, circuit.FlattenError(err)
	}

	return circuit.Ref(teleio.NewServer(&tailStdout{stdout, cmd})), nil
}
Example #2
0
func (srv *Server) Query(spaceID vena.SpaceID, minTime, maxTime vena.Time, stat vena.Stat, velocity bool) ([]*Point, error) {
	if minTime >= maxTime {
		return nil, nil
	}
	pivot := &RowKey{SpaceID: spaceID, Time: minTime}

	iter := srv.Server.DB.NewIterator(srv.Server.ReadAndCache)
	defer iter.Close()

	iter.Seek(pivot.Encode())
	if !iter.Valid() {
		return nil, nil
	}

	const limit = 1e4 // Maximum number of result points
	result := make([]*Point, 0, limit)

	for len(result) < limit && iter.Valid() {
		key, err := DecodeRowKey(iter.Key())
		if err != nil {
			return nil, circuit.FlattenError(err)
		}
		if key.SpaceID != spaceID || key.Time >= maxTime {
			break
		}
		value, err := DecodeRowValue(iter.Value())
		if err != nil {
			return nil, circuit.FlattenError(err)
		}
		result = append(result, &Point{Time: key.Time, Value: value.Value})
		iter.Next()
	}
	srv.rlk.Lock()
	srv.nquery++
	srv.rlk.Unlock()
	return result, nil
}
Example #3
0
func (srv *Server) Put(time vena.Time, spaceID vena.SpaceID, value float64) error {
	rowKey := &RowKey{SpaceID: spaceID, Time: time}
	rowValue := &RowValue{Value: value}
	srv.wlk.Lock()
	wopts := srv.WriteNoSync
	if srv.nwrite%100 == 0 {
		wopts = srv.WriteSync
	}
	srv.wlk.Unlock()
	if err := srv.DB.Put(wopts, rowKey.Encode(), rowValue.Encode()); err != nil {
		return circuit.FlattenError(err)
	}
	srv.wlk.Lock()
	srv.nwrite++
	srv.wlk.Unlock()
	return nil
}
Example #4
0
func (t *tailStdout) Close() error {
	println("CLOSING TAIL")
	err := t.ReadCloser.Close()
	t.cmd.Process.Kill()
	return circuit.FlattenError(err)
}