本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/internal/client.KeyValue类的典型用法代码示例。如果您正苦于以下问题:Golang KeyValue类的具体用法?Golang KeyValue怎么用?Golang KeyValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KeyValue类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: start
func (ia *idAllocator) start() {
ia.stopper.RunWorker(func() {
ctx := ia.AnnotateCtx(context.Background())
defer close(ia.ids)
for {
var newValue int64
for newValue <= int64(ia.minID) {
var err error
var res client.KeyValue
for r := retry.Start(base.DefaultRetryOptions()); r.Next(); {
idKey := ia.idKey.Load().(roachpb.Key)
if err := ia.stopper.RunTask(func() {
res, err = ia.db.Inc(ctx, idKey, int64(ia.blockSize))
}); err != nil {
log.Warning(ctx, err)
return
}
if err == nil {
newValue = res.ValueInt()
break
}
log.Warningf(ctx, "unable to allocate %d ids from %s: %s", ia.blockSize, idKey, err)
}
if err != nil {
panic(fmt.Sprintf("unexpectedly exited id allocation retry loop: %s", err))
}
}
end := newValue + 1
start := end - int64(ia.blockSize)
if start < int64(ia.minID) {
start = int64(ia.minID)
}
// Add all new ids to the channel for consumption.
for i := start; i < end; i++ {
select {
case ia.ids <- uint32(i):
case <-ia.stopper.ShouldStop():
return
}
}
}
})
}
开发者ID:knz,项目名称:cockroach,代码行数:48,代码来源:id_alloc.go
示例2: ProcessKV
// ProcessKV processes the given key/value, setting values in the row
// accordingly. If debugStrings is true, returns pretty printed key and value
// information in prettyKey/prettyValue (otherwise they are empty strings).
func (rf *RowFetcher) ProcessKV(
kv client.KeyValue, debugStrings bool,
) (prettyKey string, prettyValue string, err error) {
if debugStrings {
prettyKey = fmt.Sprintf("/%s/%s%s", rf.desc.Name, rf.index.Name, prettyEncDatums(rf.keyVals))
}
if rf.indexKey == nil {
// This is the first key for the row.
rf.indexKey = []byte(kv.Key[:len(kv.Key)-len(rf.keyRemainingBytes)])
// Reset the row to nil; it will get filled in with the column
// values as we decode the key-value pairs for the row.
for i := range rf.row {
rf.row[i].UnsetDatum()
}
// Fill in the column values that are part of the index key.
for i, v := range rf.keyVals {
rf.row[rf.indexColIdx[i]] = v
}
}
if !rf.isSecondaryIndex && len(rf.keyRemainingBytes) > 0 {
_, familyID, err := encoding.DecodeUvarintAscending(rf.keyRemainingBytes)
if err != nil {
return "", "", err
}
family, err := rf.desc.FindFamilyByID(FamilyID(familyID))
if err != nil {
return "", "", err
}
switch kv.Value.GetTag() {
case roachpb.ValueType_TUPLE:
prettyKey, prettyValue, err = rf.processValueTuple(family, kv, debugStrings, prettyKey)
default:
prettyKey, prettyValue, err = rf.processValueSingle(family, kv, debugStrings, prettyKey)
}
if err != nil {
return "", "", err
}
} else {
if rf.implicitVals != nil {
// This is a unique index; decode the implicit column values from
// the value.
_, err := DecodeKeyVals(&rf.alloc, rf.implicitVals, nil, kv.ValueBytes())
if err != nil {
return "", "", err
}
for i, id := range rf.index.ImplicitColumnIDs {
if idx, ok := rf.colIdxMap[id]; ok && rf.valNeededForCol[idx] {
rf.row[idx] = rf.implicitVals[i]
}
}
if debugStrings {
prettyValue = prettyEncDatums(rf.implicitVals)
}
}
if log.V(2) {
if rf.implicitVals != nil {
log.Infof(context.TODO(), "Scan %s -> %s", kv.Key, prettyEncDatums(rf.implicitVals))
} else {
log.Infof(context.TODO(), "Scan %s", kv.Key)
}
}
}
if debugStrings && prettyValue == "" {
prettyValue = parser.DNull.String()
}
return prettyKey, prettyValue, nil
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:79,代码来源:rowfetcher.go
示例3: testGossipRestartInner
func testGossipRestartInner(
ctx context.Context, t *testing.T, c cluster.Cluster, cfg cluster.TestConfig,
) {
// This already replicates the first range (in the local setup).
// The replication of the first range is important: as long as the
// first range only exists on one node, that node can trivially
// acquire the range lease. Once the range is replicated, however,
// nodes must be able to discover each other over gossip before the
// lease can be acquired.
num := c.NumNodes()
deadline := timeutil.Now().Add(cfg.Duration)
waitTime := longWaitTime
if cfg.Duration < waitTime {
waitTime = shortWaitTime
}
for timeutil.Now().Before(deadline) {
log.Infof(ctx, "waiting for initial gossip connections")
CheckGossip(ctx, t, c, waitTime, HasPeers(num))
CheckGossip(ctx, t, c, waitTime, hasClusterID)
CheckGossip(ctx, t, c, waitTime, hasSentinel)
log.Infof(ctx, "killing all nodes")
for i := 0; i < num; i++ {
if err := c.Kill(ctx, i); err != nil {
t.Fatal(err)
}
}
log.Infof(ctx, "restarting all nodes")
for i := 0; i < num; i++ {
if err := c.Restart(ctx, i); err != nil {
t.Fatal(err)
}
}
log.Infof(ctx, "waiting for gossip to be connected")
CheckGossip(ctx, t, c, waitTime, HasPeers(num))
CheckGossip(ctx, t, c, waitTime, hasClusterID)
CheckGossip(ctx, t, c, waitTime, hasSentinel)
for i := 0; i < num; i++ {
db, err := c.NewClient(ctx, i)
if err != nil {
t.Fatal(err)
}
if i == 0 {
if err := db.Del(ctx, "count"); err != nil {
t.Fatal(err)
}
}
var kv client.KeyValue
if err := db.Txn(ctx, func(txn *client.Txn) error {
var err error
kv, err = txn.Inc("count", 1)
return err
}); err != nil {
t.Fatal(err)
} else if v := kv.ValueInt(); v != int64(i+1) {
t.Fatalf("unexpected value %d for write #%d (expected %d)", v, i, i+1)
}
}
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:66,代码来源:gossip_peerings_test.go
注:本文中的github.com/cockroachdb/cockroach/pkg/internal/client.KeyValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论