<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"os"
	"path"
	"strconv"
	"time"

	"github.com/coreos/etcd/etcdserver"
	"github.com/coreos/etcd/etcdserver/etcdhttp"
	"github.com/coreos/etcd/raft"
	"github.com/coreos/etcd/store"
	"github.com/coreos/etcd/wal"
)

var (
	fid     = flag.String("id", "0xBEEF", "Id of this server")
	timeout = flag.Duration("timeout", 10*time.Second, "Request Timeout")
	laddr   = flag.String("l", ":8080", "HTTP service address (e.g., ':8080')")
	dir     = flag.String("d", "", "Directory to store wal files and snapshot files")

	peers = etcdhttp.Peers{}
)

func init() {
	flag.Var(peers, "peers", "your peers")
}

func main() {
	flag.Parse()

	id, err := strconv.ParseInt(*fid, 0, 64)
	if err != nil {
		log.Fatal(err)
	}

	if peers.Pick(id) == "" {
		log.Fatalf("%#x=<addr> must be specified in peers", id)
	}

	if *dir == "" {
		*dir = fmt.Sprintf("%v", *fid)
		log.Printf("main: no data dir is given, use default data dir ./%s", *dir)
	}
	if err := os.MkdirAll(*dir, 0700); err != nil {
		log.Fatal(err)
	}

	waldir := path.Join(*dir, "wal")

	var w *wal.WAL
	var n raft.Node
	if wal.Exist(waldir) {
		// TODO(xiangli): check snapshot; not open from zero
		w, err = wal.OpenFromIndex(waldir, 0)
		if err != nil {
			log.Fatal(err)
		}
		// TODO(xiangli): save/recovery nodeID?
		_, st, ents, err := w.ReadAll()
		if err != nil {
			log.Fatal(err)
		}
		n = raft.Restart(id, peers.Ids(), 10, 1, st, ents)
	} else {<commit_msg>main: use data-dir as the path to data directory flag<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"os"
	"path"
	"strconv"
	"time"

	"github.com/coreos/etcd/etcdserver"
	"github.com/coreos/etcd/etcdserver/etcdhttp"
	"github.com/coreos/etcd/raft"
	"github.com/coreos/etcd/store"
	"github.com/coreos/etcd/wal"
)

var (
	fid     = flag.String("id", "0xBEEF", "Id of this server")
	timeout = flag.Duration("timeout", 10*time.Second, "Request Timeout")
	laddr   = flag.String("l", ":8080", "HTTP service address (e.g., ':8080')")
	dir     = flag.String("data-dir", "", "Path to the data directory")
	peers   = etcdhttp.Peers{}
)

func init() {
	flag.Var(peers, "peers", "your peers")
}

func main() {
	flag.Parse()

	id, err := strconv.ParseInt(*fid, 0, 64)
	if err != nil {
		log.Fatal(err)
	}

	if peers.Pick(id) == "" {
		log.Fatalf("%#x=<addr> must be specified in peers", id)
	}

	if *dir == "" {
		*dir = fmt.Sprintf("%v", *fid)
		log.Printf("main: no data-dir is given, use default data-dir ./%s", *dir)
	}
	if err := os.MkdirAll(*dir, 0700); err != nil {
		log.Fatal(err)
	}

	waldir := path.Join(*dir, "wal")

	var w *wal.WAL
	var n raft.Node
	if wal.Exist(waldir) {
		// TODO(xiangli): check snapshot; not open from zero
		w, err = wal.OpenFromIndex(waldir, 0)
		if err != nil {
			log.Fatal(err)
		}
		// TODO(xiangli): save/recovery nodeID?
		_, st, ents, err := w.ReadAll()
		if err != nil {
			log.Fatal(err)
		}
		n = raft.Restart(id, peers.Ids(), 10, 1, st, ents)
	} else {
{'fraction_non_alphanumeric': 0.1927831607083194, 'fraction_numerical': 0.014700968927497494, 'mean_word_length': 3.3900293255131966, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5569976', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1254, 'n_words': 294}