当前位置: 首页>>代码示例>>Golang>>正文


Golang KeyValue.ValueInt方法代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/client.KeyValue.ValueInt方法的典型用法代码示例。如果您正苦于以下问题:Golang KeyValue.ValueInt方法的具体用法?Golang KeyValue.ValueInt怎么用?Golang KeyValue.ValueInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cockroachdb/cockroach/client.KeyValue的用法示例。


在下文中一共展示了KeyValue.ValueInt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestGossipRestart

// TestGossipRestart verifies that the gossip network can be
// re-bootstrapped after a time when all nodes were down
// simultaneously.
func TestGossipRestart(t *testing.T) {
	// 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 leader lease. Once the range is replicated, however,
	// nodes must be able to discover each other over gossip before the
	// lease can be acquired.
	c := StartCluster(t)
	defer c.AssertAndStop(t)
	num := c.NumNodes()

	log.Infof("waiting for initial gossip connections")
	checkGossip(t, c, 20*time.Second, hasPeers(num))
	checkGossip(t, c, time.Second, hasClusterID)
	checkGossip(t, c, time.Second, hasSentinel)

	log.Infof("killing all nodes")
	for i := 0; i < num; i++ {
		if err := c.Kill(i); err != nil {
			t.Fatal(err)
		}
	}

	log.Infof("restarting all nodes")
	for i := 0; i < num; i++ {
		if err := c.Restart(i); err != nil {
			t.Fatal(err)
		}
	}

	log.Infof("waiting for gossip to be connected")
	checkGossip(t, c, 20*time.Second, hasPeers(num))
	checkGossip(t, c, time.Second, hasClusterID)
	checkGossip(t, c, time.Second, hasSentinel)

	for i := 0; i < num; i++ {
		db, dbStopper := c.MakeClient(t, i)
		if i == 0 {
			if err := db.Del("count"); err != nil {
				t.Fatal(err)
			}
		}
		var kv client.KeyValue
		if err := db.Txn(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)
		}
		dbStopper.Stop()
	}
}
开发者ID:Ralkage,项目名称:cockroach,代码行数:58,代码来源:gossip_peerings_test.go

示例2: start

func (ia *idAllocator) start() {
	ia.stopper.RunWorker(func() {
		defer close(ia.ids)

		for {
			var newValue int64
			for newValue <= int64(ia.minID) {
				var (
					err error
					res client.KeyValue
				)
				for r := retry.Start(idAllocationRetryOpts); r.Next(); {
					if ia.stopper.StartTask() {
						idKey := ia.idKey.Load().(proto.Key)
						res, err = ia.db.Inc(idKey, int64(ia.blockSize))
						ia.stopper.FinishTask()

						if err == nil {
							newValue = res.ValueInt()
							break
						}

						log.Warningf("unable to allocate %d ids from %s: %s", ia.blockSize, idKey, err)
					} else {
						return
					}
				}
				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:chinnitv,项目名称:cockroach,代码行数:50,代码来源:id_alloc.go

示例3: unmarshalValue

func unmarshalValue(col structured.ColumnDescriptor, kv client.KeyValue) parser.Datum {
	if kv.Exists() {
		switch col.Type.Kind {
		case structured.ColumnType_BIT, structured.ColumnType_INT:
			return parser.DInt(kv.ValueInt())
		case structured.ColumnType_FLOAT:
			return parser.DFloat(math.Float64frombits(uint64(kv.ValueInt())))
		case structured.ColumnType_CHAR, structured.ColumnType_TEXT,
			structured.ColumnType_BLOB:
			return parser.DString(kv.ValueBytes())
		}
	}
	return parser.DNull
}
开发者ID:elkingtoncode,项目名称:LampDB,代码行数:14,代码来源:scan.go

示例4: unmarshalValue

func (n *scanNode) unmarshalValue(kv client.KeyValue) (parser.Datum, bool) {
	kind, ok := n.colKind[n.colID]
	if !ok {
		n.err = fmt.Errorf("column-id \"%d\" does not exist", n.colID)
		return nil, false
	}
	if kv.Exists() {
		switch kind {
		case ColumnType_INT:
			return parser.DInt(kv.ValueInt()), true
		case ColumnType_BOOL:
			return parser.DBool(kv.ValueInt() != 0), true
		case ColumnType_FLOAT:
			return parser.DFloat(math.Float64frombits(uint64(kv.ValueInt()))), true
		case ColumnType_STRING, ColumnType_BYTES:
			return parser.DString(kv.ValueBytes()), true
		case ColumnType_DATE:
			var t time.Time
			if err := t.UnmarshalBinary(kv.ValueBytes()); err != nil {
				return nil, false
			}
			return parser.DDate{Time: t}, true
		case ColumnType_TIMESTAMP:
			var t time.Time
			if err := t.UnmarshalBinary(kv.ValueBytes()); err != nil {
				return nil, false
			}
			return parser.DTimestamp{Time: t}, true
		case ColumnType_INTERVAL:
			return parser.DInterval{Duration: time.Duration(kv.ValueInt())}, true
		}
	}
	return parser.DNull, true
}
开发者ID:yosiat,项目名称:cockroach,代码行数:34,代码来源:scan.go

示例5: unmarshalValue

func unmarshalValue(col structured.ColumnDescriptor, kv client.KeyValue) driver.Value {
	if !kv.Exists() {
		return nil
	}
	switch col.Type.Kind {
	case structured.ColumnType_BIT, structured.ColumnType_INT:
		return kv.ValueInt()
	case structured.ColumnType_FLOAT:
		return math.Float64frombits(uint64(kv.ValueInt()))
	case structured.ColumnType_CHAR, structured.ColumnType_BINARY,
		structured.ColumnType_TEXT, structured.ColumnType_BLOB:
		// TODO(pmattis): The conversion to string isn't strictly necessary, but
		// makes log messages more readable right now.
		return string(kv.ValueBytes())
	}
	return kv.ValueBytes()
}
开发者ID:Jaekyun,项目名称:cockroach,代码行数:17,代码来源:conn.go

示例6: unmarshalValue

func unmarshalValue(col structured.ColumnDescriptor, kv client.KeyValue) sqlwire.Datum {
	var d sqlwire.Datum
	if !kv.Exists() {
		return d
	}
	switch col.Type.Kind {
	case structured.ColumnType_BIT, structured.ColumnType_INT:
		tmp := kv.ValueInt()
		d.IntVal = &tmp
	case structured.ColumnType_FLOAT:
		tmp := math.Float64frombits(uint64(kv.ValueInt()))
		d.FloatVal = &tmp
	case structured.ColumnType_CHAR, structured.ColumnType_TEXT,
		structured.ColumnType_BLOB:
		// TODO(pmattis): The conversion to string isn't strictly necessary, but
		// makes log messages more readable right now.
		tmp := string(kv.ValueBytes())
		d.StringVal = &tmp
	}
	return d
}
开发者ID:zmoon111,项目名称:cockroach,代码行数:21,代码来源:server.go

示例7: unmarshalValue

func (n *scanNode) unmarshalValue(kv client.KeyValue) (parser.Datum, bool) {
	kind, ok := n.colKind[n.colID]
	if !ok {
		n.err = fmt.Errorf("column-id \"%d\" does not exist", n.colID)
		return nil, false
	}
	if kv.Exists() {
		switch kind {
		case ColumnType_INT:
			return parser.DInt(kv.ValueInt()), true
		case ColumnType_BOOL:
			return parser.DBool(kv.ValueInt() != 0), true
		case ColumnType_FLOAT:
			return parser.DFloat(math.Float64frombits(uint64(kv.ValueInt()))), true
		case ColumnType_STRING, ColumnType_BYTES:
			return parser.DString(kv.ValueBytes()), true
		}
	}
	return parser.DNull, true
}
开发者ID:knorwood,项目名称:cockroach,代码行数:20,代码来源:scan.go

示例8: testGossipRestartInner

func testGossipRestartInner(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 leader 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("waiting for initial gossip connections")
		checkGossip(t, c, waitTime, hasPeers(num))
		checkGossip(t, c, waitTime, hasClusterID)
		checkGossip(t, c, waitTime, hasSentinel)

		log.Infof("killing all nodes")
		for i := 0; i < num; i++ {
			if err := c.Kill(i); err != nil {
				t.Fatal(err)
			}
		}

		log.Infof("restarting all nodes")
		for i := 0; i < num; i++ {
			if err := c.Restart(i); err != nil {
				t.Fatal(err)
			}
		}

		log.Infof("waiting for gossip to be connected")
		checkGossip(t, c, waitTime, hasPeers(num))
		checkGossip(t, c, waitTime, hasClusterID)
		checkGossip(t, c, waitTime, hasSentinel)

		for i := 0; i < num; i++ {
			db, dbStopper := c.NewClient(t, i)
			if i == 0 {
				if err := db.Del("count"); err != nil {
					t.Fatal(err)
				}
			}
			var kv client.KeyValue
			if err := db.Txn(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)
			}
			dbStopper.Stop()
		}
	}
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:62,代码来源:gossip_peerings_test.go


注:本文中的github.com/cockroachdb/cockroach/client.KeyValue.ValueInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。