Beispiel #1
0
func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() != 1 {
		usage()
	}

	file := flag.Arg(0)
	j, err := persistence.NewJournal(file)
	if err != nil {
		panic(err)
	}
	for {
		m, err := j.ReadMutation()
		if err == io.EOF {
			break
		}
		if err != nil {
			logf("bad journal file: %v", err)
			if *f {
				err = j.Fsck()
				if err != nil {
					log("can't fix journal")
					os.Exit(2)
				}
				log("journal successfully fixed")
				continue
			} else {
				return
			}
		}
		fmt.Println(m)
	}
}
Beispiel #2
0
func TestRestore(t *testing.T) {
	f, err := ioutil.TempFile("", "j")
	if err != nil {
		t.Fatal(err)
	}
	j := f.Name()
	f.Close()
	defer os.Remove(j)

	journal, err := persistence.NewJournal(j)
	if err != nil {
		t.Fatal(err)
	}

	for k, v := range testData {
		m := store.MustEncodeSet("/ken/"+strconv.Itoa(k), v, int64(k))
		journal.WriteMutation(m)
	}
	journal.Close()

	c := NewCluster(t, fmt.Sprintf("-j=%s", j), "-r")
	defer c.Close()
	for k, v := range testData {
		v1, _, err := c.conn.Get("/ken/"+strconv.Itoa(k), nil)
		if err != nil {
			t.Fatal(err)
		}
		v2 := string(v1)
		if v != v2 {
			t.Fatalf("restored data is not what is expected: %s != %s", v, v2)
		}
	}
}
Beispiel #3
0
func TestSave(t *testing.T) {
	c := NewCluster(t)
	defer c.Close()

	for k, v := range testData {
		c.conn.Set("/ken/"+strconv.Itoa(k), -1, []byte(v))
	}
	j, err := persistence.NewJournal(c.j)
	if err != nil {
		t.Fatal(err)
	}
	defer j.Close()
	for k, v := range testData {
		m, err := j.ReadMutation()
		if err != nil {
			t.Fatalf("bad journal file: %v", err)
		}
		k1, v1, err := decode(m)
		if err != nil {
			t.Fatalf("bad journal file: %v", err)
		}
		if k != k1 {
			t.Fatalf("bad journal file: %s != %s", k1, k)
		}
		if v != v1 {
			t.Fatalf("bad journal file: %s != %s", v1, v)
		}
	}
	_, err = j.ReadMutation()
	if err != io.EOF {
		t.Fatal("bad journal file: expected EOF")
	}
}
Beispiel #4
0
func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() != 1 {
		usage()
	}

	file := flag.Arg(0)
	j, err := persistence.NewJournal(file)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %v\n", progname, err)
		os.Exit(2)
	}
	r := bufio.NewReader(os.Stdin)
	for {
		line, prefix, err := r.ReadLine()
		if err != nil {
			return
		}
		for prefix {
			var l []byte
			l, prefix, _ = r.ReadLine()
			if err != nil {
				return
			}
			line = append(line, l...)
		}
		err = j.WriteMutation(string(line))
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s: %v\n", progname, err)
			os.Exit(4)
		}
	}
}
Beispiel #5
0
func main() {
	flag.Usage = usage
	flag.Parse()

	var err error
	journal, err = persistence.NewJournal(*j)
	if err != nil {
		fatal(err)
	}

	dial()
	if *r {
		restore()
	}
	seteph()

	go Store()
	go Notify()
	monitor()
}