本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/internal/client.KeyValue.ValueInt方法的典型用法代碼示例。如果您正苦於以下問題:Golang KeyValue.ValueInt方法的具體用法?Golang KeyValue.ValueInt怎麽用?Golang KeyValue.ValueInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/internal/client.KeyValue
的用法示例。
在下文中一共展示了KeyValue.ValueInt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
}
}
})
}
示例2: 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)
}
}
}
}