Beispiel #1
0
func main() {
	log.SetFlags(0)

	flag.Parse()

	// Set the data directory.
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Data path argument required")
	}

	if *start == 0 || *stop == 0 {
		flag.Usage()
		log.Fatal("start and stop commits are required")
	}

	dbpath := flag.Arg(0)

	client := cluster.NewLocalClient("http://"+*node, 1)

	meta, err := client.StreamsMetadata()
	if err != nil {
		log.Fatal(err)
	}

	err = cluster.Merge(dbpath, *start, *stop, meta.Closed)
	if err != nil {
		log.Fatal(err)
	}
}
Beispiel #2
0
func main() {
	log.SetFlags(0)

	flag.Parse()

	// Set the data directory.
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Data path argument required")
	}

	dbpath := flag.Arg(0)

	client := cluster.NewLocalClient("http://"+*node, 1)

	meta, err := client.StreamsMetadata()
	if err != nil {
		log.Fatal(err)
	}

	err = cluster.Cleanup(dbpath, meta.Current, meta.Closed)
	if err != nil {
		log.Fatal(err)
	}
}
Beispiel #3
0
func main() {
	log.SetFlags(0)

	flag.Parse()

	// Set the data directory.
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Data path argument required")
	}

	log.SetFlags(log.LstdFlags)

	client := cluster.NewLocalClient("http://"+*node, 1)
	reader := cluster.NewReader(flag.Arg(0))
	streams := make(map[uint64]stream.Stream)

	http.HandleFunc("/events", func(w http.ResponseWriter, req *http.Request) {
		req.Body.Close()

		var count int
		var err error

		index := req.FormValue("index")
		value := req.FormValue("value")
		after, _ := strconv.ParseInt(req.FormValue("after"), 10, 64)
		continuation := req.FormValue("continuation")
		limit, _ := strconv.Atoi(req.FormValue("limit"))

		meta, con, err := client.Offset(index, value)
		if err != nil {
			write(w, 500, map[string]interface{}{
				"error": err.Error(),
			})

			return
		}

		reader.Update(meta.Peers, meta.Closed, meta.Current, currentStream(reader, streams, meta.Current))

		events := make([]string, 0, limit)

		if limit == 0 {
			limit = 20
		}

		if index != "" {
			if continuation == "" {
				continuation = con
			}

			continuation, err = reader.Scan(index, value, uint64(after), continuation, func(e *stream.Event) bool {
				count += 1
				events = append(events, string(e.Data))
				return count < limit
			})
		} else {
			continuation, err = reader.Iterate(uint64(after), continuation, func(e *stream.Event) bool {
				count += 1
				events = append(events, string(e.Data))
				return count < limit
			})
		}

		res := map[string]interface{}{
			"events":       events,
			"continuation": continuation,
			"most_recent":  meta.MostRecent,
		}

		if err != nil {
			res["error"] = err.Error()
			write(w, 500, res)
		}

		write(w, 200, res)
	})

	err := http.ListenAndServe(fmt.Sprintf("%s:%d", *host, *port), nil)
	if err != nil {
		log.Fatal(err)
	}
}