func (udc *UpsideDownCouch) dumpPrefix(kvreader store.KVReader, rv chan interface{}, prefix []byte) { start := prefix if start == nil { start = []byte{0} } it := kvreader.PrefixIterator(start) 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() } }
func visitPrefix(reader store.KVReader, prefix []byte, visitor KVVisitor) (err error) { start := prefix if start == nil { start = []byte{0} } it := reader.PrefixIterator(prefix) 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 }
func (udc *UpsideDownCouch) countDocs(kvreader store.KVReader) (count uint64, err error) { it := kvreader.PrefixIterator([]byte{'b'}) defer func() { if cerr := it.Close(); err == nil && cerr != nil { err = cerr } }() _, _, valid := it.Current() for valid { count++ it.Next() _, _, valid = it.Current() } return }
func (udc *UpsideDownCouch) loadSchema(kvreader store.KVReader) (err error) { it := kvreader.PrefixIterator([]byte{'f'}) defer func() { if cerr := it.Close(); err == nil && cerr != nil { err = cerr } }() key, val, valid := it.Current() for valid { var fieldRow *FieldRow fieldRow, err = NewFieldRowKV(key, val) if err != nil { return } udc.fieldCache.AddExisting(fieldRow.name, fieldRow.index) it.Next() key, val, valid = it.Current() } val, err = kvreader.Get([]byte{'v'}) if err != nil { return } var vr *VersionRow vr, err = NewVersionRowKV([]byte{'v'}, val) if err != nil { return } if vr.version != Version { err = IncompatibleVersion return } return }