本文整理汇总了Golang中github.com/janelia-flyem/dvid/storage.VersionedCtx.TKeyFromKey方法的典型用法代码示例。如果您正苦于以下问题:Golang VersionedCtx.TKeyFromKey方法的具体用法?Golang VersionedCtx.TKeyFromKey怎么用?Golang VersionedCtx.TKeyFromKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janelia-flyem/dvid/storage.VersionedCtx
的用法示例。
在下文中一共展示了VersionedCtx.TKeyFromKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: versionedRange
// versionedRange sends a range of key-value pairs for a particular version down a channel.
func (db *KVAutobus) versionedRange(vctx storage.VersionedCtx, kStart, kEnd storage.TKey, ch chan errorableKV, keysOnly bool) {
minKey, err := vctx.MinVersionKey(kStart)
if err != nil {
ch <- errorableKV{nil, err}
return
}
maxKey, err := vctx.MaxVersionKey(kEnd)
if err != nil {
ch <- errorableKV{nil, err}
return
}
maxVersionKey, err := vctx.MaxVersionKey(kStart)
if err != nil {
ch <- errorableKV{nil, err}
return
}
kvs, err := db.getRange(minKey, maxKey)
if err != nil {
ch <- errorableKV{nil, err}
return
}
versions := []*storage.KeyValue{}
for _, kv := range kvs {
if !keysOnly {
storage.StoreValueBytesRead <- len(kv.V)
}
storage.StoreKeyBytesRead <- len(kv.K)
// Did we pass all versions for last key read?
if bytes.Compare(kv.K, maxVersionKey) > 0 {
indexBytes, err := vctx.TKeyFromKey(kv.K)
if err != nil {
ch <- errorableKV{nil, err}
return
}
maxVersionKey, err = vctx.MaxVersionKey(indexBytes)
if err != nil {
ch <- errorableKV{nil, err}
return
}
// log.Printf("->maxVersionKey %v (transmitting %d values)\n", maxVersionKey, len(values))
sendKV(vctx, versions, ch)
versions = []*storage.KeyValue{}
}
// Did we pass the final key?
if bytes.Compare(kv.K, maxKey) > 0 {
if len(versions) > 0 {
sendKV(vctx, versions, ch)
}
ch <- errorableKV{nil, nil}
return
}
// log.Printf("Appending value with key %v\n", itKey)
versions = append(versions, kv)
}
}
示例2: versionedRange
// versionedRange sends a range of key-value pairs for a particular version down a channel.
func (db *LevelDB) versionedRange(vctx storage.VersionedCtx, kStart, kEnd storage.TKey, ch chan errorableKV, keysOnly bool) {
dvid.StartCgo()
ro := levigo.NewReadOptions()
it := db.ldb.NewIterator(ro)
defer func() {
it.Close()
dvid.StopCgo()
}()
minKey, err := vctx.MinVersionKey(kStart)
if err != nil {
ch <- errorableKV{nil, err}
return
}
maxKey, err := vctx.MaxVersionKey(kEnd)
if err != nil {
ch <- errorableKV{nil, err}
return
}
values := []*storage.KeyValue{}
maxVersionKey, err := vctx.MaxVersionKey(kStart)
if err != nil {
ch <- errorableKV{nil, err}
return
}
// log.Printf(" minKey %v\n", minKey)
// log.Printf(" maxKey %v\n", maxKey)
// log.Printf(" maxVersionKey %v\n", maxVersionKey)
it.Seek(minKey)
var itValue []byte
for {
if it.Valid() {
if !keysOnly {
itValue = it.Value()
storage.StoreValueBytesRead <- len(itValue)
}
itKey := it.Key()
// log.Printf(" +++valid key %v\n", itKey)
storage.StoreKeyBytesRead <- len(itKey)
// Did we pass all versions for last key read?
if bytes.Compare(itKey, maxVersionKey) > 0 {
indexBytes, err := vctx.TKeyFromKey(itKey)
if err != nil {
ch <- errorableKV{nil, err}
return
}
maxVersionKey, err = vctx.MaxVersionKey(indexBytes)
if err != nil {
ch <- errorableKV{nil, err}
return
}
// log.Printf("->maxVersionKey %v (transmitting %d values)\n", maxVersionKey, len(values))
sendKV(vctx, values, ch)
values = []*storage.KeyValue{}
}
// Did we pass the final key?
if bytes.Compare(itKey, maxKey) > 0 {
if len(values) > 0 {
sendKV(vctx, values, ch)
}
ch <- errorableKV{nil, nil}
return
}
// log.Printf("Appending value with key %v\n", itKey)
values = append(values, &storage.KeyValue{itKey, itValue})
it.Next()
} else {
if err = it.GetError(); err != nil {
ch <- errorableKV{nil, err}
} else {
sendKV(vctx, values, ch)
ch <- errorableKV{nil, nil}
}
return
}
}
}