本文整理汇总了Golang中github.com/cockroachdb/cockroach/roachpb.Value类的典型用法代码示例。如果您正苦于以下问题:Golang Value类的具体用法?Golang Value怎么用?Golang Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Value类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: printRaftLogEntry
func printRaftLogEntry(kv engine.MVCCKeyValue) (bool, error) {
var meta engine.MVCCMetadata
if err := meta.Unmarshal(kv.Value); err != nil {
return false, err
}
value := roachpb.Value{
RawBytes: meta.RawBytes,
}
var ent raftpb.Entry
if err := value.GetProto(&ent); err != nil {
return false, err
}
if len(ent.Data) > 0 {
_, cmdData := storage.DecodeRaftCommand(ent.Data)
var cmd roachpb.RaftCommand
if err := cmd.Unmarshal(cmdData); err != nil {
return false, err
}
ent.Data = nil
fmt.Printf("%s\n", &ent)
fmt.Printf("%s\n", &cmd)
} else {
fmt.Printf("%s: EMPTY\n", &ent)
}
return false, nil
}
开发者ID:younggi,项目名称:cockroach,代码行数:26,代码来源:debug.go
示例2: StoreData
// StoreData writes the supplied time series data to the cockroach server.
// Stored data will be sampled at the supplied resolution.
func (db *DB) StoreData(r Resolution, data []tspb.TimeSeriesData) error {
var kvs []roachpb.KeyValue
// Process data collection: data is converted to internal format, and a key
// is generated for each internal message.
for _, d := range data {
idatas, err := d.ToInternal(r.KeyDuration(), r.SampleDuration())
if err != nil {
return err
}
for _, idata := range idatas {
var value roachpb.Value
if err := value.SetProto(&idata); err != nil {
return err
}
kvs = append(kvs, roachpb.KeyValue{
Key: MakeDataKey(d.Name, d.Source, r, idata.StartTimestampNanos),
Value: value,
})
}
}
// Send the individual internal merge requests.
b := client.Batch{}
for _, kv := range kvs {
b.AddRawRequest(&roachpb.MergeRequest{
Span: roachpb.Span{
Key: kv.Key,
},
Value: kv.Value,
})
}
return db.db.Run(&b)
}
开发者ID:csdigi,项目名称:cockroach,代码行数:37,代码来源:db.go
示例3: setAppliedIndex
func setAppliedIndex(
ctx context.Context,
eng engine.ReadWriter,
ms *enginepb.MVCCStats,
rangeID roachpb.RangeID,
appliedIndex,
leaseAppliedIndex uint64,
) error {
var value roachpb.Value
value.SetInt(int64(appliedIndex))
if err := engine.MVCCPut(ctx, eng, ms,
keys.RaftAppliedIndexKey(rangeID),
hlc.ZeroTimestamp,
value,
nil /* txn */); err != nil {
return err
}
value.SetInt(int64(leaseAppliedIndex))
return engine.MVCCPut(ctx, eng, ms,
keys.LeaseAppliedIndexKey(rangeID),
hlc.ZeroTimestamp,
value,
nil /* txn */)
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:25,代码来源:replica_state.go
示例4: setFrozenStatus
func setFrozenStatus(
eng engine.ReadWriter, ms *enginepb.MVCCStats, rangeID roachpb.RangeID, frozen bool,
) error {
var val roachpb.Value
val.SetBool(frozen)
return engine.MVCCPut(context.Background(), eng, ms,
keys.RangeFrozenStatusKey(rangeID), hlc.ZeroTimestamp, val, nil)
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:8,代码来源:replica_state.go
示例5: insertCPutFn
// insertCPutFn is used by insertRow when conflicts should be respected.
// logValue is used for pretty printing.
func insertCPutFn(b *client.Batch, key *roachpb.Key, value *roachpb.Value) {
// TODO(dan): We want do this V(2) log everywhere in sql. Consider making a
// client.Batch wrapper instead of inlining it everywhere.
if log.V(2) {
log.InfofDepth(1, "CPut %s -> %s", *key, value.PrettyPrint())
}
b.CPut(key, value, nil)
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:10,代码来源:rowwriter.go
示例6: setLastIndex
// setLastIndex persists a new last index.
func setLastIndex(eng engine.Engine, rangeID roachpb.RangeID, lastIndex uint64) error {
var value roachpb.Value
value.SetInt(int64(lastIndex))
return engine.MVCCPut(eng, nil, keys.RaftLastIndexKey(rangeID),
roachpb.ZeroTimestamp,
value,
nil /* txn */)
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:10,代码来源:replica_raftstorage.go
示例7: setLastIndex
func setLastIndex(eng engine.ReadWriter, rangeID roachpb.RangeID, lastIndex uint64) error {
var value roachpb.Value
value.SetInt(int64(lastIndex))
return engine.MVCCPut(context.Background(), eng, nil, keys.RaftLastIndexKey(rangeID),
hlc.ZeroTimestamp,
value,
nil /* txn */)
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:9,代码来源:replica_state.go
示例8: maybeUnmarshalInline
func maybeUnmarshalInline(v []byte, dest proto.Message) error {
var meta enginepb.MVCCMetadata
if err := meta.Unmarshal(v); err != nil {
return err
}
value := roachpb.Value{
RawBytes: meta.RawBytes,
}
return value.GetProto(dest)
}
开发者ID:csdigi,项目名称:cockroach,代码行数:10,代码来源:debug.go
示例9: setAppliedIndex
// setAppliedIndex persists a new applied index.
func setAppliedIndex(eng engine.Engine, ms *engine.MVCCStats, rangeID roachpb.RangeID, appliedIndex uint64) error {
var value roachpb.Value
value.SetInt(int64(appliedIndex))
return engine.MVCCPut(eng, ms,
keys.RaftAppliedIndexKey(rangeID),
roachpb.ZeroTimestamp,
value,
nil /* txn */)
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:11,代码来源:replica_raftstorage.go
示例10: mustGetInt
// mustGetInt decodes an int64 value from the bytes field of the receiver
// and panics if the bytes field is not 0 or 8 bytes in length.
func mustGetInt(v *roachpb.Value) int64 {
if v == nil {
return 0
}
i, err := v.GetInt()
if err != nil {
panic(err)
}
return i
}
开发者ID:harryge00,项目名称:cockroach,代码行数:12,代码来源:client_raft_test.go
示例11: newInfo
func newInfo(val float64) Info {
now := timeutil.Now()
v := roachpb.Value{Timestamp: hlc.Timestamp{WallTime: now.UnixNano()}}
v.SetFloat(val)
return Info{
Value: v,
OrigStamp: now.UnixNano(),
TTLStamp: now.Add(time.Millisecond).UnixNano(),
}
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:12,代码来源:info_test.go
示例12: writeRandomTimeSeriesDataToRange
func writeRandomTimeSeriesDataToRange(
t testing.TB,
store *storage.Store,
rangeID roachpb.RangeID,
keyPrefix []byte,
) (midpoint []byte) {
src := rand.New(rand.NewSource(0))
r := ts.Resolution10s
for i := 0; i < 20; i++ {
var data []tspb.TimeSeriesData
for j := int64(0); j <= src.Int63n(5); j++ {
d := tspb.TimeSeriesData{
Name: "test.random.metric",
Source: "cpu01",
}
for k := int64(0); k <= src.Int63n(10); k++ {
d.Datapoints = append(d.Datapoints, tspb.TimeSeriesDatapoint{
TimestampNanos: src.Int63n(200) * r.KeyDuration(),
Value: src.Float64(),
})
}
data = append(data, d)
}
for _, d := range data {
idatas, err := d.ToInternal(r.KeyDuration(), r.SampleDuration())
if err != nil {
t.Fatal(err)
}
for _, idata := range idatas {
var value roachpb.Value
if err := value.SetProto(&idata); err != nil {
t.Fatal(err)
}
mArgs := roachpb.MergeRequest{
Span: roachpb.Span{
Key: encoding.EncodeVarintAscending(keyPrefix, idata.StartTimestampNanos),
},
Value: value,
}
if _, pErr := client.SendWrappedWith(rg1(store), nil, roachpb.Header{
RangeID: rangeID,
}, &mArgs); pErr != nil {
t.Fatal(pErr)
}
}
}
}
// Return approximate midway point (100 is midway between random timestamps in range [0,200)).
midKey := append([]byte(nil), keyPrefix...)
midKey = encoding.EncodeVarintAscending(midKey, 100*r.KeyDuration())
return keys.MakeRowSentinelKey(midKey)
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:52,代码来源:client_split_test.go
示例13: createDefaultZoneConfig
// Create the key/value pairs for the default zone config entry.
func createDefaultZoneConfig() []roachpb.KeyValue {
var ret []roachpb.KeyValue
value := roachpb.Value{}
desc := config.DefaultZoneConfig()
if err := value.SetProto(&desc); err != nil {
log.Fatalf("could not marshal %v", desc)
}
ret = append(ret, roachpb.KeyValue{
Key: MakeZoneKey(keys.RootNamespaceID),
Value: value,
})
return ret
}
开发者ID:liugangnhm,项目名称:cockroach,代码行数:14,代码来源:system.go
示例14: newInfo
func newInfo(val float64) info {
now := time.Now()
v := roachpb.Value{Timestamp: &roachpb.Timestamp{WallTime: now.UnixNano()}}
v.SetFloat(val)
return info{
Info: Info{
Value: v,
TTLStamp: now.Add(time.Millisecond).UnixNano(),
},
}
}
开发者ID:nporsche,项目名称:cockroach,代码行数:13,代码来源:info_test.go
示例15: setupMVCCScanData
// setupMVCCData writes up to numVersions values at each of numKeys
// keys. The number of versions written for each key is chosen
// randomly according to a uniform distribution. Each successive
// version is written starting at 5ns and then in 5ns increments. This
// allows scans at various times, starting at t=5ns, and continuing to
// t=5ns*(numVersions+1). A version for each key will be read on every
// such scan, but the dynamics of the scan will change depending on
// the historical timestamp. Earlier timestamps mean scans which must
// skip more historical versions; later timestamps mean scans which
// skip fewer.
//
// The creation of the rocksdb database is time consuming, especially
// for larger numbers of versions. The database is persisted between
// runs and stored in the current directory as
// "mvcc_scan_<versions>_<keys>".
func setupMVCCScanData(numVersions, numKeys int, b *testing.B) (*RocksDB, *stop.Stopper) {
loc := fmt.Sprintf("mvcc_scan_%d_%d", numVersions, numKeys)
exists := true
if _, err := os.Stat(loc); os.IsNotExist(err) {
exists = false
}
log.Infof("creating mvcc data: %s", loc)
const cacheSize = 8 << 30 // 8 GB
stopper := stop.NewStopper()
rocksdb := NewRocksDB(roachpb.Attributes{Attrs: []string{"ssd"}}, loc, cacheSize, stopper)
if err := rocksdb.Open(); err != nil {
b.Fatalf("could not create new rocksdb db instance at %s: %v", loc, err)
}
if exists {
return rocksdb, stopper
}
rng, _ := randutil.NewPseudoRand()
keys := make([]roachpb.Key, numKeys)
nvs := make([]int, numKeys)
for t := 1; t <= numVersions; t++ {
walltime := int64(5 * t)
ts := makeTS(walltime, 0)
batch := rocksdb.NewBatch()
for i := 0; i < numKeys; i++ {
if t == 1 {
keys[i] = roachpb.Key(encoding.EncodeUvarint([]byte("key-"), uint64(i)))
nvs[i] = int(rand.Int31n(int32(numVersions)) + 1)
}
// Only write values if this iteration is less than the random
// number of versions chosen for this key.
if t <= nvs[i] {
value := roachpb.Value{Bytes: randutil.RandBytes(rng, 1024)}
value.InitChecksum(keys[i])
if err := MVCCPut(batch, nil, keys[i], ts, value, nil); err != nil {
b.Fatal(err)
}
}
}
if err := batch.Commit(); err != nil {
b.Fatal(err)
}
batch.Close()
}
rocksdb.CompactRange(nil, nil)
return rocksdb, stopper
}
开发者ID:rohanahata,项目名称:cockroach,代码行数:66,代码来源:rocksdb_test.go
示例16: storeGossipUpdate
// storeGossipUpdate is the gossip callback used to keep the StorePool up to date.
func (sp *StorePool) storeGossipUpdate(_ string, content roachpb.Value) {
var storeDesc roachpb.StoreDescriptor
if err := content.GetProto(&storeDesc); err != nil {
log.Error(context.TODO(), err)
return
}
sp.mu.Lock()
defer sp.mu.Unlock()
// Does this storeDetail exist yet?
detail := sp.getStoreDetailLocked(storeDesc.StoreID)
detail.markAlive(sp.clock.Now(), &storeDesc)
sp.mu.queue.enqueue(detail)
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:15,代码来源:store_pool.go
示例17: tryMeta
func tryMeta(kv engine.MVCCKeyValue) (string, error) {
if !bytes.HasPrefix(kv.Key.Key, keys.Meta1Prefix) && !bytes.HasPrefix(kv.Key.Key, keys.Meta2Prefix) {
return "", errors.New("not a meta key")
}
value := roachpb.Value{
Timestamp: kv.Key.Timestamp,
RawBytes: kv.Value,
}
var desc roachpb.RangeDescriptor
if err := value.GetProto(&desc); err != nil {
return "", err
}
return descStr(desc), nil
}
开发者ID:csdigi,项目名称:cockroach,代码行数:14,代码来源:debug.go
示例18: PutSequence
// PutSequence writes a sequence number for the specified family.
func (rc *ResponseCache) PutSequence(e engine.Engine, family []byte, sequence int64, err error) error {
if sequence <= 0 || len(family) == 0 {
return errEmptyID
}
if !rc.shouldCacheError(err) {
return nil
}
// Write the response value to the engine.
key := keys.ResponseCacheKey(rc.rangeID, family)
var v roachpb.Value
v.SetInt(sequence)
return engine.MVCCPut(e, nil /* ms */, key, roachpb.ZeroTimestamp, v, nil /* txn */)
}
开发者ID:xujun10110,项目名称:cockroach,代码行数:15,代码来源:response_cache.go
示例19: BenchmarkMVCCMergeTimeSeries
// BenchmarkMVCCMergeTimeSeries computes performance of merging time series data.
func BenchmarkMVCCMergeTimeSeries(b *testing.B) {
ts := &roachpb.InternalTimeSeriesData{
StartTimestampNanos: 0,
SampleDurationNanos: 1000,
Samples: []*roachpb.InternalTimeSeriesSample{
{Offset: 0, Count: 1, Sum: 5.0},
},
}
var value roachpb.Value
if err := value.SetProto(ts); err != nil {
b.Fatal(err)
}
runMVCCMerge(&value, 1024, b)
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:15,代码来源:rocksdb_test.go
示例20: append
// append the given entries to the raft log. Takes the previous values of
// r.mu.lastIndex and r.mu.raftLogSize, and returns new values. We do this
// rather than modifying them directly because these modifications need to be
// atomic with the commit of the batch.
func (r *Replica) append(
ctx context.Context,
batch engine.ReadWriter,
prevLastIndex uint64,
prevRaftLogSize int64,
entries []raftpb.Entry,
) (uint64, int64, error) {
if len(entries) == 0 {
return prevLastIndex, prevRaftLogSize, nil
}
var diff enginepb.MVCCStats
var value roachpb.Value
for i := range entries {
ent := &entries[i]
key := keys.RaftLogKey(r.RangeID, ent.Index)
if err := value.SetProto(ent); err != nil {
return 0, 0, err
}
value.InitChecksum(key)
var err error
if ent.Index > prevLastIndex {
err = engine.MVCCBlindPut(ctx, batch, &diff, key, hlc.ZeroTimestamp, value, nil /* txn */)
} else {
err = engine.MVCCPut(ctx, batch, &diff, key, hlc.ZeroTimestamp, value, nil /* txn */)
}
if err != nil {
return 0, 0, err
}
}
// Delete any previously appended log entries which never committed.
lastIndex := entries[len(entries)-1].Index
for i := lastIndex + 1; i <= prevLastIndex; i++ {
err := engine.MVCCDelete(ctx, batch, &diff, keys.RaftLogKey(r.RangeID, i),
hlc.ZeroTimestamp, nil /* txn */)
if err != nil {
return 0, 0, err
}
}
if err := setLastIndex(ctx, batch, r.RangeID, lastIndex); err != nil {
return 0, 0, err
}
raftLogSize := prevRaftLogSize + diff.SysBytes
return lastIndex, raftLogSize, nil
}
开发者ID:yaojingguo,项目名称:cockroach,代码行数:52,代码来源:replica_raftstorage.go
注:本文中的github.com/cockroachdb/cockroach/roachpb.Value类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论