// DelKeyWithPrefix deletes keys with prefix. func DelKeyWithPrefix(rm kv.RetrieverMutator, prefix kv.Key) error { var keys []kv.Key iter, err := rm.Seek(prefix) if err != nil { return errors.Trace(err) } defer iter.Close() for { if err != nil { return errors.Trace(err) } if iter.Valid() && iter.Key().HasPrefix(prefix) { keys = append(keys, iter.Key().Clone()) err = iter.Next() if err != nil { return errors.Trace(err) } } else { break } } for _, key := range keys { err := rm.Delete(key) if err != nil { return errors.Trace(err) } } return nil }
// Drop removes the KV index from store. func (c *index) Drop(rm kv.RetrieverMutator) error { it, err := rm.Seek(c.prefix) if err != nil { return errors.Trace(err) } defer it.Close() // remove all indices for it.Valid() { if !it.Key().HasPrefix(c.prefix) { break } err := rm.Delete(it.Key()) if err != nil { return errors.Trace(err) } err = it.Next() if err != nil { return errors.Trace(err) } } return nil }