本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/storage/engine.MVCCPutProto函數的典型用法代碼示例。如果您正苦於以下問題:Golang MVCCPutProto函數的具體用法?Golang MVCCPutProto怎麽用?Golang MVCCPutProto使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MVCCPutProto函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCorruptedClusterID
// TestCorruptedClusterID verifies that a node fails to start when a
// store's cluster ID is empty.
func TestCorruptedClusterID(t *testing.T) {
defer leaktest.AfterTest(t)()
e := engine.NewInMem(roachpb.Attributes{}, 1<<20)
defer e.Close()
if _, err := bootstrapCluster(
storage.StoreConfig{}, []engine.Engine{e}, kv.MakeTxnMetrics(metric.TestSampleInterval),
); err != nil {
t.Fatal(err)
}
// Set the cluster ID to the empty UUID.
sIdent := roachpb.StoreIdent{
ClusterID: uuid.UUID{},
NodeID: 1,
StoreID: 1,
}
if err := engine.MVCCPutProto(context.Background(), e, nil, keys.StoreIdentKey(), hlc.ZeroTimestamp, nil, &sIdent); err != nil {
t.Fatal(err)
}
engines := []engine.Engine{e}
_, serverAddr, _, node, stopper := createTestNode(util.TestAddr, engines, nil, t)
stopper.Stop()
if err := node.start(context.Background(), serverAddr, engines, roachpb.Attributes{}, roachpb.Locality{}); !testutils.IsError(err, "unidentified store") {
t.Errorf("unexpected error %v", err)
}
}
示例2: TestRangeLookupWithOpenTransaction
// TestRangeLookupWithOpenTransaction verifies that range lookups are
// done in such a way (e.g. using inconsistent reads) that they
// proceed in the event that a write intent is extant at the meta
// index record being read.
func TestRangeLookupWithOpenTransaction(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
db := createTestClient(t, s.Stopper(), s.ServingAddr())
// Create an intent on the meta1 record by writing directly to the
// engine.
key := testutils.MakeKey(keys.Meta1Prefix, roachpb.KeyMax)
now := s.Clock().Now()
txn := roachpb.NewTransaction("txn", roachpb.Key("foobar"), 0, enginepb.SERIALIZABLE, now, 0)
if err := engine.MVCCPutProto(
context.Background(), s.(*server.TestServer).Engines()[0],
nil, key, now, txn, &roachpb.RangeDescriptor{}); err != nil {
t.Fatal(err)
}
// Now, with an intent pending, attempt (asynchronously) to read
// from an arbitrary key. This will cause the distributed sender to
// do a range lookup, which will encounter the intent. We're
// verifying here that the range lookup doesn't fail with a write
// intent error. If it did, it would go into a deadloop attempting
// to push the transaction, which in turn requires another range
// lookup, etc, ad nauseam.
if _, err := db.Get(context.TODO(), "a"); err != nil {
t.Fatal(err)
}
}
示例3: setHardState
func setHardState(
ctx context.Context, batch engine.ReadWriter, rangeID roachpb.RangeID, st raftpb.HardState,
) error {
return engine.MVCCPutProto(ctx, batch, nil,
keys.RaftHardStateKey(rangeID),
hlc.ZeroTimestamp, nil, &st)
}
示例4: Put
// Put writes an entry for the specified transaction ID.
func (sc *AbortCache) Put(
ctx context.Context,
e engine.ReadWriter,
ms *enginepb.MVCCStats,
txnID uuid.UUID,
entry *roachpb.AbortCacheEntry,
) error {
key := keys.AbortCacheKey(sc.rangeID, txnID)
return engine.MVCCPutProto(ctx, e, ms, key, hlc.ZeroTimestamp, nil /* txn */, entry)
}
示例5: TestGCQueueLastProcessedTimestamps
func TestGCQueueLastProcessedTimestamps(t *testing.T) {
defer leaktest.AfterTest(t)()
tc := testContext{}
stopper := stop.NewStopper()
defer stopper.Stop()
tc.Start(t, stopper)
// Create two last processed times both at the range start key and
// also at some mid-point key in order to simulate a merge.
// Two transactions.
lastProcessedVals := []struct {
key roachpb.Key
expGC bool
}{
{keys.QueueLastProcessedKey(roachpb.RKeyMin, "timeSeriesMaintenance"), false},
{keys.QueueLastProcessedKey(roachpb.RKeyMin, "replica consistency checker"), false},
{keys.QueueLastProcessedKey(roachpb.RKey("a"), "timeSeriesMaintenance"), true},
{keys.QueueLastProcessedKey(roachpb.RKey("b"), "replica consistency checker"), true},
}
ts := tc.Clock().Now()
for _, lpv := range lastProcessedVals {
if err := engine.MVCCPutProto(context.Background(), tc.engine, nil, lpv.key, hlc.ZeroTimestamp, nil, &ts); err != nil {
t.Fatal(err)
}
}
cfg, ok := tc.gossip.GetSystemConfig()
if !ok {
t.Fatal("config not set")
}
// Process through a scan queue.
gcQ := newGCQueue(tc.store, tc.gossip)
if err := gcQ.process(context.Background(), tc.repl, cfg); err != nil {
t.Fatal(err)
}
// Verify GC.
testutils.SucceedsSoon(t, func() error {
for _, lpv := range lastProcessedVals {
ok, err := engine.MVCCGetProto(context.Background(), tc.engine, lpv.key, hlc.ZeroTimestamp, true, nil, &ts)
if err != nil {
return err
}
if ok == lpv.expGC {
return errors.Errorf("expected GC of %s: %t; got %t", lpv.key, lpv.expGC, ok)
}
}
return nil
})
}
示例6: setGCThreshold
func setGCThreshold(
ctx context.Context,
eng engine.ReadWriter,
ms *enginepb.MVCCStats,
rangeID roachpb.RangeID,
threshold *hlc.Timestamp,
) error {
if threshold == nil {
return errors.New("cannot persist nil GCThreshold")
}
return engine.MVCCPutProto(ctx, eng, ms,
keys.RangeLastGCKey(rangeID), hlc.ZeroTimestamp, nil, threshold)
}
示例7: setTruncatedState
func setTruncatedState(
ctx context.Context,
eng engine.ReadWriter,
ms *enginepb.MVCCStats,
rangeID roachpb.RangeID,
truncState roachpb.RaftTruncatedState,
) error {
if (truncState == roachpb.RaftTruncatedState{}) {
return errors.New("cannot persist empty RaftTruncatedState")
}
return engine.MVCCPutProto(ctx, eng, ms,
keys.RaftTruncatedStateKey(rangeID), hlc.ZeroTimestamp, nil, &truncState)
}
示例8: setLease
func setLease(
ctx context.Context,
eng engine.ReadWriter,
ms *enginepb.MVCCStats,
rangeID roachpb.RangeID,
lease *roachpb.Lease,
) error {
if lease == nil {
return errors.New("cannot persist nil Lease")
}
return engine.MVCCPutProto(
ctx, eng, ms,
keys.RangeLeaseKey(rangeID),
hlc.ZeroTimestamp, nil, lease)
}
示例9: updateBootstrapInfo
func (ls *Stores) updateBootstrapInfo(bi *gossip.BootstrapInfo) error {
if bi.Timestamp.Less(ls.biLatestTS) {
return nil
}
ctx := ls.AnnotateCtx(context.TODO())
// Update the latest timestamp and set cached version.
ls.biLatestTS = bi.Timestamp
ls.latestBI = protoutil.Clone(bi).(*gossip.BootstrapInfo)
// Update all stores.
for _, s := range ls.storeMap {
if err := engine.MVCCPutProto(ctx, s.engine, nil, keys.StoreGossipKey(), hlc.ZeroTimestamp, nil, bi); err != nil {
return err
}
}
return nil
}
示例10: TestGCQueueTransactionTable
//.........這裏部分代碼省略.........
EndKey: resArgs.EndKey,
})
// We've special cased one test case. Note that the intent is still
// counted in `resolved`.
if testCases[id].failResolve {
return roachpb.NewErrorWithTxn(errors.Errorf("boom"), filterArgs.Hdr.Txn)
}
}
return nil
}
tc.StartWithStoreConfig(t, tsc)
defer tc.Stop()
tc.manualClock.Set(int64(now))
outsideKey := tc.rng.Desc().EndKey.Next().AsRawKey()
testIntents := []roachpb.Span{{Key: roachpb.Key("intent")}}
txns := map[string]roachpb.Transaction{}
for strKey, test := range testCases {
baseKey := roachpb.Key(strKey)
txnClock := hlc.NewClock(hlc.NewManualClock(int64(test.orig)).UnixNano)
txn := newTransaction("txn1", baseKey, 1, enginepb.SERIALIZABLE, txnClock)
txn.Status = test.status
txn.Intents = testIntents
if test.hb > 0 {
txn.LastHeartbeat = &hlc.Timestamp{WallTime: int64(test.hb)}
}
// Set a high Timestamp to make sure it does not matter. Only
// OrigTimestamp (and heartbeat) are used for GC decisions.
txn.Timestamp.Forward(hlc.MaxTimestamp)
txns[strKey] = *txn
for _, addrKey := range []roachpb.Key{baseKey, outsideKey} {
key := keys.TransactionKey(addrKey, txn.ID)
if err := engine.MVCCPutProto(context.Background(), tc.engine, nil, key, hlc.ZeroTimestamp, nil, txn); err != nil {
t.Fatal(err)
}
}
entry := roachpb.AbortCacheEntry{Key: txn.Key, Timestamp: txn.LastActive()}
if err := tc.rng.abortCache.Put(context.Background(), tc.engine, nil, txn.ID, &entry); err != nil {
t.Fatal(err)
}
}
// Run GC.
gcQ := newGCQueue(tc.store, tc.gossip)
cfg, ok := tc.gossip.GetSystemConfig()
if !ok {
t.Fatal("config not set")
}
if err := gcQ.process(context.Background(), tc.clock.Now(), tc.rng, cfg); err != nil {
t.Fatal(err)
}
util.SucceedsSoon(t, func() error {
for strKey, sp := range testCases {
txn := &roachpb.Transaction{}
key := keys.TransactionKey(roachpb.Key(strKey), txns[strKey].ID)
ok, err := engine.MVCCGetProto(context.Background(), tc.engine, key, hlc.ZeroTimestamp, true, nil, txn)
if err != nil {
return err
}
if expGC := (sp.newStatus == -1); expGC {
if expGC != !ok {
return fmt.Errorf("%s: expected gc: %t, but found %s\n%s", strKey, expGC, txn, roachpb.Key(strKey))
}
示例11: setReplicaDestroyedError
// setReplicaDestroyedError sets an error indicating that the replica has been
// destroyed.
func setReplicaDestroyedError(
ctx context.Context, eng engine.ReadWriter, rangeID roachpb.RangeID, err *roachpb.Error,
) error {
return engine.MVCCPutProto(ctx, eng, nil,
keys.RangeReplicaDestroyedErrorKey(rangeID), hlc.ZeroTimestamp, nil /* txn */, err)
}