Esempio n. 1
0
func decodeBatchToMem(data []byte, expectSeq uint64, mdb *memdb.DB) (seq uint64, batchLen int, err error) {
	seq, batchLen, err = decodeBatchHeader(data)
	if err != nil {
		return 0, 0, err
	}
	if seq < expectSeq {
		return 0, 0, newErrBatchCorrupted("invalid sequence number")
	}
	data = data[batchHeaderLen:]
	var ik []byte
	var decodedLen int
	err = decodeBatch(data, func(i int, index batchIndex) error {
		if i >= batchLen {
			return newErrBatchCorrupted("invalid records length")
		}
		ik = makeInternalKey(ik, index.k(data), seq+uint64(i), index.keyType)
		if err := mdb.Put(ik, index.v(data)); err != nil {
			return err
		}
		decodedLen++
		return nil
	})
	if err == nil && decodedLen != batchLen {
		err = newErrBatchCorrupted(fmt.Sprintf("invalid records length: %d vs %d", batchLen, decodedLen))
	}
	return
}
Esempio n. 2
0
func (b *Batch) memReplay(to *memdb.DB) error {
	var ikScratch []byte
	return b.decodeRec(func(i int, kt keyType, key, value []byte) error {
		ikScratch = makeInternalKey(ikScratch, key, b.seq+uint64(i), kt)
		return to.Put(ikScratch, value)
	})
}
Esempio n. 3
0
func (b *Batch) putMem(seq uint64, mdb *memdb.DB) error {
	var ik []byte
	for i, index := range b.index {
		ik = makeInternalKey(ik, index.k(b.data), seq+uint64(i), index.keyType)
		if err := mdb.Put(ik, index.v(b.data)); err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 4
0
func (b *Batch) memReplay(to *memdb.DB) error {
	return b.decodeRec(func(i int, kt kType, key, value []byte) {
		ikey := newIkey(key, b.seq+uint64(i), kt)
		to.Put(ikey, value)
	})
}