func collRangeCopy(src *gkvlite.Collection, dst *gkvlite.Collection, minKey []byte, minKeyInclusive []byte, maxKeyExclusive []byte) error { var errVisit error visitor := func(i *gkvlite.Item) bool { if len(minKeyInclusive) > 0 && bytes.Compare(i.Key, minKeyInclusive) < 0 { return true } if len(maxKeyExclusive) > 0 && bytes.Compare(i.Key, maxKeyExclusive) >= 0 { return true } errVisit = dst.SetItem(i) if errVisit != nil { return false } return true } if errVisit != nil { return errVisit } return src.VisitItemsAscend(minKey, true, visitor) }
func copyColl(srcColl *gkvlite.Collection, dstColl *gkvlite.Collection, writeEvery int) (numItems uint64, lastItem *gkvlite.Item, err error) { minItem, err := srcColl.MinItem(true) if err != nil { return 0, nil, err } if minItem == nil { return 0, nil, nil } var errVisit error = nil err = srcColl.VisitItemsAscend(minItem.Key, true, func(i *gkvlite.Item) bool { if errVisit = dstColl.SetItem(i); errVisit != nil { return false } numItems++ lastItem = i if writeEvery > 0 && numItems%uint64(writeEvery) == 0 { if errVisit = dstColl.Write(); errVisit != nil { return false } } return true }) if err != nil { return 0, nil, err } if errVisit != nil { return 0, nil, errVisit } return numItems, lastItem, nil }
// You can use fmt.Printf() for the printf param. func dumpColl(printf func(format string, a ...interface{}) (n int, err error), c *gkvlite.Collection, prefix string) (int, error) { n := 0 err := c.VisitItemsAscend(nil, true, func(cItem *gkvlite.Item) bool { n++ printf("%v%s %#v\n", prefix, string(cItem.Key), cItem) return true }) return n, err }
func colItemExists(key string, col *gkvlite.Collection) bool { exists := false col.VisitItemsAscend([]byte(""), true, func(i *gkvlite.Item) bool { if key == string(i.Key) { exists = true return false } return true }) return exists }
func (p *partitionstore) visit(coll *gkvlite.Collection, start []byte, withValue bool, v func(*gkvlite.Item) bool) (err error) { if start == nil { i, err := coll.MinItem(false) if err != nil { return err } if i == nil { return nil } start = i.Key } return coll.VisitItemsAscend(start, withValue, v) }
// You can use fmt.Printf() for the printf param. func dumpCollAsItems(printf func(format string, a ...interface{}) (n int, err error), c *gkvlite.Collection, prefix string) (int, error) { n := 0 var vErr error err := c.VisitItemsAscend(nil, true, func(cItem *gkvlite.Item) bool { i := &item{} if vErr = i.fromValueBytes(cItem.Val); vErr != nil { return false } n++ printf("%v%#v, data: %v\n", prefix, i, string(i.data)) return true }) if vErr != nil { return 0, vErr } return n, err }
func testCheckColl(t *testing.T, x *gkvlite.Collection, start string, arr []string, cb func(i *gkvlite.Item)) { n := 0 err := x.VisitItemsAscend([]byte(start), true, func(i *gkvlite.Item) bool { if cb != nil { cb(i) } if n >= len(arr) { t.Errorf("visited more than expected: %v, saw: %v", len(arr), n+1) } if string(i.Key) != arr[n] { t.Errorf("expected visit item: %v, saw: %v", arr[n], i) } n++ return true }) if err != nil { t.Errorf("expected no visit error, got: %v", err) } if n != len(arr) { t.Errorf("expected # visit callbacks: %v, saw: %v", len(arr), n) } }