本文整理汇总了Golang中github.com/janelia-flyem/dvid/storage.Context.KeyRange方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.KeyRange方法的具体用法?Golang Context.KeyRange怎么用?Golang Context.KeyRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janelia-flyem/dvid/storage.Context
的用法示例。
在下文中一共展示了Context.KeyRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteAll
// DeleteAll deletes all key-value associated with a context (data instance and version).
func (db *KVAutobus) DeleteAll(ctx storage.Context, allVersions bool) error {
if ctx == nil {
return fmt.Errorf("Received nil context in DeleteAll()")
}
if !allVersions {
return fmt.Errorf("DeleteAll() not supported for immutable store unless for all versions")
}
keyBeg, keyEnd := ctx.KeyRange()
return db.deleteRange(keyBeg, keyEnd)
}
示例2: deleteAllVersions
func (db *LevelDB) deleteAllVersions(ctx storage.Context) error {
dvid.StartCgo()
var err error
var minKey, maxKey storage.Key
vctx, versioned := ctx.(storage.VersionedCtx)
if versioned {
// Don't have to worry about tombstones. Delete all keys from all versions for this instance id.
minTKey := storage.MinTKey(storage.TKeyMinClass)
maxTKey := storage.MaxTKey(storage.TKeyMaxClass)
minKey, err = vctx.MinVersionKey(minTKey)
if err != nil {
return err
}
maxKey, err = vctx.MaxVersionKey(maxTKey)
if err != nil {
return err
}
} else {
minKey, maxKey = ctx.KeyRange()
}
const BATCH_SIZE = 10000
batch := db.NewBatch(ctx).(*goBatch)
ro := levigo.NewReadOptions()
it := db.ldb.NewIterator(ro)
defer func() {
it.Close()
dvid.StopCgo()
}()
numKV := 0
it.Seek(minKey)
for {
if err := it.GetError(); err != nil {
return fmt.Errorf("Error iterating during DeleteAll for %s: %v", ctx, err)
}
if it.Valid() {
itKey := it.Key()
storage.StoreKeyBytesRead <- len(itKey)
// Did we pass the final key?
if bytes.Compare(itKey, maxKey) > 0 {
break
}
batch.WriteBatch.Delete(itKey)
if (numKV+1)%BATCH_SIZE == 0 {
if err := batch.Commit(); err != nil {
dvid.Criticalf("Error on batch commit of DeleteAll at key-value pair %d: %v\n", numKV, err)
return fmt.Errorf("Error on batch commit of DeleteAll at key-value pair %d: %v", numKV, err)
}
batch = db.NewBatch(ctx).(*goBatch)
dvid.Debugf("Deleted %d key-value pairs in ongoing DELETE ALL for %s.\n", numKV+1, ctx)
}
numKV++
it.Next()
} else {
break
}
}
if numKV%BATCH_SIZE != 0 {
if err := batch.Commit(); err != nil {
dvid.Criticalf("Error on last batch commit of DeleteAll: %v\n", err)
return fmt.Errorf("Error on last batch commit of DeleteAll: %v", err)
}
}
dvid.Debugf("Deleted %d key-value pairs via DELETE ALL for %s.\n", numKV, ctx)
return nil
}
示例3: DeleteAll
// DeleteAll removes all key-value pairs for the context. If allVersions is true,
// then all versions of the data instance are deleted.
func (db *BigTable) DeleteAll(ctx storage.Context, allVersions bool) error {
if db == nil {
return fmt.Errorf("Can't call DeleteAll() on nil BigTable")
}
if ctx == nil {
return fmt.Errorf("Received nil context in DeleteAll()")
}
//Row range corresponde to all keys corresponding to this data instace.
min, max := ctx.KeyRange()
rr := api.NewRange(encodeKey(min), encodeKey(max))
err := tbl.ReadRows(db.ctx, rr, func(r api.Row) bool {
unvKeyRow, err := decodeKey(r.Key())
if err != nil {
dvid.Errorf("Error in DeleteAll(): %v\n", err)
return false
}
if allVersions {
mut := api.NewMutation()
mut.DeleteRow()
err := tbl.Apply(db.ctx, encodeKey(unvKeyRow), mut)
if err != nil {
dvid.Errorf("Failed to delete row")
}
} else {
emptyTkey := make([]byte, 0)
_, versionToDelete, err := ctx.SplitKey(emptyTkey)
if err != nil {
dvid.Errorf("Error in DeleteAll(): %v\n", err)
return false
}
for _, readItem := range r[familyName] {
verKey, err := decodeKey(readItem.Column)
if err != nil {
dvid.Errorf("Error in DeleteAll(): %v\n", err)
return false
}
if bytes.Equal(verKey, versionToDelete) {
mut := api.NewMutation()
mut.DeleteCellsInColumn(familyName, encodeKey(verKey))
err := tbl.Apply(db.ctx, encodeKey(unvKeyRow), mut)
if err != nil {
dvid.Errorf("Failed to DeleteCellsInColumn in DeleteAll()")
}
return true // One I found the version I don't have to keep serching for it.
}
}
}
return true // keep going
}, api.RowFilter(api.StripValueFilter()))
return err
}