本文整理汇总了Golang中github.com/cockroachdb/cockroach/roachpb.Value类的典型用法代码示例。如果您正苦于以下问题:Golang Value类的具体用法?Golang Value怎么用?Golang Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
}
示例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 */)
}
示例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)
}
示例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)
}
示例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 */)
}
示例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 */)
}
示例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)
}
示例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 */)
}
示例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
}
示例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(),
}
}
示例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)
}
示例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
}
示例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(),
},
}
}
示例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
}