Example #1
0
func (l *LevelDB) BatchPut(kvs []*epaxos.KVpair) error {
	b := new(leveldb.Batch)
	for i := range kvs {
		b.Set([]byte(kvs[i].Key), kvs[i].Value)
	}
	return l.ldb.Apply(*b, l.wsync)
}
Example #2
0
func (store *SStorage) Store(data []pb.HardState) error {
	assert(nil != store.db)

	// group into one batch
	var batch leveldb.Batch
	for _, hs := range data {
		key := makeDataKey(hs.Index)
		assert(0 < len(key))
		val, err := hs.Marshal()
		if nil != err {
			return err
		}

		batch.Set(key, val)
	}

	// store using default option
	return store.db.Apply(batch, nil)
}