Example #1
0
func (stable *boltDBStable) StoreLogs(logs []*Rlog) {

	var lastLog *Rlog
	err := stable.db.Batch(func(tx *bolt.Tx) error {

		for _, log := range logs {

			bucket := tx.Bucket(boltLogs)
			key := convertUint64ToBytes(log.Index)

			encLog := make([]byte, 0, 512)
			enc := codec.NewEncoderBytes(&encLog, msgPackHandle)

			if err := enc.Encode(log); err != nil {
				return err
			}

			if err := bucket.Put(key, encLog); err != nil {
				return err
			}

			lastLog = log
		}

		return nil
	})

	if err != nil {
		panic("Could not store logs")
	}

}
Example #2
0
func (r *Raft) writeSnapshot(snap *fsmSnapshot) error {

	encSnap := make([]byte, 0, 512)
	enc := codec.NewEncoderBytes(&encSnap, msgPackHandle)
	err := enc.Encode(snap)
	if err != nil {
		return err
	}

	err = ioutil.WriteFile(fmt.Sprintf("%s/snapshot/snapshot.bin", r.config.BaseDir), encSnap, 0700)

	r.workingSnapshot = snap
	return err

}