예제 #1
0
파일: dump.go 프로젝트: acgshare/bleve
func (udc *UpsideDownCouch) dumpRange(kvreader store.KVReader, rv chan interface{}, start, end []byte) {
	it := kvreader.RangeIterator(start, end)
	defer func() {
		cerr := it.Close()
		if cerr != nil {
			rv <- cerr
		}
	}()
	key, val, valid := it.Current()
	for valid {
		ck := make([]byte, len(key))
		copy(ck, key)
		cv := make([]byte, len(val))
		copy(cv, val)
		row, err := ParseFromKeyValue(ck, cv)
		if err != nil {
			rv <- err
			return
		}
		rv <- row

		it.Next()
		key, val, valid = it.Current()
	}
}
예제 #2
0
파일: util.go 프로젝트: acgshare/bleve
func visitRange(reader store.KVReader, start, end []byte, visitor KVVisitor) (err error) {
	it := reader.RangeIterator(start, end)
	defer func() {
		if cerr := it.Close(); err == nil && cerr != nil {
			err = cerr
		}
	}()
	k, v, valid := it.Current()
	for valid {
		var cont bool
		cont, err = visitor(k, v)
		if err != nil {
			// visitor encountered an error, stop and return it
			return
		}
		if !cont {
			// vistor has requested we stop iteration, return nil
			return
		}
		it.Next()
		k, v, valid = it.Current()
	}
	return
}