本文整理匯總了Golang中github.com/cockroachdb/cockroach/keys.RaftAppliedIndexKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang RaftAppliedIndexKey函數的具體用法?Golang RaftAppliedIndexKey怎麽用?Golang RaftAppliedIndexKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RaftAppliedIndexKey函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setAppliedIndex
// setAppliedIndex persists a new applied index.
func setAppliedIndex(eng engine.Engine, raftID proto.RaftID, appliedIndex uint64) error {
return engine.MVCCPut(eng, nil, /* stats */
keys.RaftAppliedIndexKey(raftID),
proto.ZeroTimestamp,
proto.Value{Bytes: encoding.EncodeUint64(nil, appliedIndex)},
nil /* txn */)
}
示例2: setAppliedIndex
// setAppliedIndex persists a new applied index.
func setAppliedIndex(eng engine.Engine, rangeID roachpb.RangeID, appliedIndex uint64) error {
return engine.MVCCPut(eng, nil, /* stats */
keys.RaftAppliedIndexKey(rangeID),
roachpb.ZeroTimestamp,
roachpb.MakeValueFromBytes(encoding.EncodeUint64(nil, appliedIndex)),
nil /* txn */)
}
示例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: loadAppliedIndex
// loadAppliedIndex returns the Raft applied index and the lease applied index.
func loadAppliedIndex(
ctx context.Context, reader engine.Reader, rangeID roachpb.RangeID,
) (uint64, uint64, error) {
var appliedIndex uint64
v, _, err := engine.MVCCGet(ctx, reader, keys.RaftAppliedIndexKey(rangeID),
hlc.ZeroTimestamp, true, nil)
if err != nil {
return 0, 0, err
}
if v != nil {
int64AppliedIndex, err := v.GetInt()
if err != nil {
return 0, 0, err
}
appliedIndex = uint64(int64AppliedIndex)
}
// TODO(tschottdorf): code duplication.
var leaseAppliedIndex uint64
v, _, err = engine.MVCCGet(ctx, reader, keys.LeaseAppliedIndexKey(rangeID),
hlc.ZeroTimestamp, true, nil)
if err != nil {
return 0, 0, err
}
if v != nil {
int64LeaseAppliedIndex, err := v.GetInt()
if err != nil {
return 0, 0, err
}
leaseAppliedIndex = uint64(int64LeaseAppliedIndex)
}
return appliedIndex, leaseAppliedIndex, nil
}
示例5: 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 */)
}
示例6: loadAppliedIndex
// loadAppliedIndex retrieves the applied index from the supplied engine.
func (r *Range) loadAppliedIndex(eng engine.Engine) (uint64, error) {
var appliedIndex uint64
if r.isInitialized() {
appliedIndex = raftInitialLogIndex
} else {
appliedIndex = 0
}
v, _, err := engine.MVCCGet(eng, keys.RaftAppliedIndexKey(r.Desc().RaftID),
proto.ZeroTimestamp, true, nil)
if err != nil {
return 0, err
}
if v != nil {
_, appliedIndex = encoding.DecodeUint64(v.Bytes)
}
return appliedIndex, nil
}
示例7: createRangeData
// createRangeData creates sample range data in all possible areas of
// the key space. Returns a slice of the encoded keys of all created
// data.
func createRangeData(t *testing.T, r *Replica) []engine.MVCCKey {
ts0 := hlc.ZeroTimestamp
ts := hlc.Timestamp{WallTime: 1}
desc := r.Desc()
keyTSs := []struct {
key roachpb.Key
ts hlc.Timestamp
}{
{keys.AbortCacheKey(r.RangeID, testTxnID), ts0},
{keys.AbortCacheKey(r.RangeID, testTxnID2), ts0},
{keys.RangeFrozenStatusKey(r.RangeID), ts0},
{keys.RangeLastGCKey(r.RangeID), ts0},
{keys.RaftAppliedIndexKey(r.RangeID), ts0},
{keys.RaftTruncatedStateKey(r.RangeID), ts0},
{keys.LeaseAppliedIndexKey(r.RangeID), ts0},
{keys.RangeStatsKey(r.RangeID), ts0},
{keys.RaftHardStateKey(r.RangeID), ts0},
{keys.RaftLastIndexKey(r.RangeID), ts0},
{keys.RaftLogKey(r.RangeID, 1), ts0},
{keys.RaftLogKey(r.RangeID, 2), ts0},
{keys.RangeLastReplicaGCTimestampKey(r.RangeID), ts0},
{keys.RangeLastVerificationTimestampKey(r.RangeID), ts0},
{keys.RangeDescriptorKey(desc.StartKey), ts},
{keys.TransactionKey(roachpb.Key(desc.StartKey), uuid.NewV4()), ts0},
{keys.TransactionKey(roachpb.Key(desc.StartKey.Next()), uuid.NewV4()), ts0},
{keys.TransactionKey(fakePrevKey(desc.EndKey), uuid.NewV4()), ts0},
// TODO(bdarnell): KeyMin.Next() results in a key in the reserved system-local space.
// Once we have resolved https://github.com/cockroachdb/cockroach/issues/437,
// replace this with something that reliably generates the first valid key in the range.
//{r.Desc().StartKey.Next(), ts},
// The following line is similar to StartKey.Next() but adds more to the key to
// avoid falling into the system-local space.
{append(append([]byte{}, desc.StartKey...), '\x02'), ts},
{fakePrevKey(r.Desc().EndKey), ts},
}
keys := []engine.MVCCKey{}
for _, keyTS := range keyTSs {
if err := engine.MVCCPut(context.Background(), r.store.Engine(), nil, keyTS.key, keyTS.ts, roachpb.MakeValueFromString("value"), nil); err != nil {
t.Fatal(err)
}
keys = append(keys, engine.MVCCKey{Key: keyTS.key, Timestamp: keyTS.ts})
}
return keys
}
示例8: loadAppliedIndexLocked
// loadAppliedIndexLocked retrieves the applied index from the supplied engine.
// loadAppliedIndexLocked requires that the replica lock is held.
func (r *Replica) loadAppliedIndexLocked(eng engine.Engine) (uint64, error) {
var appliedIndex uint64
if r.isInitializedLocked() {
appliedIndex = raftInitialLogIndex
} else {
appliedIndex = 0
}
v, _, err := engine.MVCCGet(eng, keys.RaftAppliedIndexKey(r.RangeID),
roachpb.ZeroTimestamp, true, nil)
if err != nil {
return 0, err
}
if v != nil {
int64AppliedIndex, err := v.GetInt()
if err != nil {
return 0, err
}
appliedIndex = uint64(int64AppliedIndex)
}
return appliedIndex, nil
}
示例9: loadAppliedIndex
// loadAppliedIndex retrieves the applied index from the supplied engine.
func (r *Replica) loadAppliedIndex(eng engine.Engine) (uint64, error) {
var appliedIndex uint64
if r.isInitialized() {
appliedIndex = raftInitialLogIndex
} else {
appliedIndex = 0
}
v, _, err := engine.MVCCGet(eng, keys.RaftAppliedIndexKey(r.Desc().RangeID),
roachpb.ZeroTimestamp, true, nil)
if err != nil {
return 0, err
}
if v != nil {
var err error
_, appliedIndex, err = encoding.DecodeUint64(v.GetRawBytes())
if err != nil {
return 0, err
}
}
return appliedIndex, nil
}
示例10: loadAppliedIndex
// loadAppliedIndex retrieves the applied index from the supplied engine.
func loadAppliedIndex(eng engine.Reader, rangeID roachpb.RangeID, isInitialized bool) (uint64, error) {
var appliedIndex uint64
if isInitialized {
appliedIndex = raftInitialLogIndex
} else {
appliedIndex = 0
}
v, _, err := engine.MVCCGet(context.Background(), eng, keys.RaftAppliedIndexKey(rangeID),
roachpb.ZeroTimestamp, true, nil)
if err != nil {
return 0, err
}
if v != nil {
int64AppliedIndex, err := v.GetInt()
if err != nil {
return 0, err
}
appliedIndex = uint64(int64AppliedIndex)
}
return appliedIndex, nil
}