-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathcmd_delete.go
51 lines (44 loc) · 1.76 KB
/
cmd_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2014 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package batcheval
import (
"context"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval/result"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage"
)
func init() {
RegisterReadWriteCommand(roachpb.Delete, DefaultDeclareIsolatedKeys, Delete)
}
// Delete deletes the key and value specified by key.
func Delete(
ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error) {
args := cArgs.Args.(*roachpb.DeleteRequest)
h := cArgs.Header
var err error
if args.ReturnKey {
reply := resp.(*roachpb.DeleteResponse)
reply.FoundKey, err = storage.MVCCDeleteReturningExistence(
ctx, readWriter, cArgs.Stats, args.Key, h.Timestamp, h.Txn)
if err != nil {
return result.Result{}, err
}
} else {
err = storage.MVCCDelete(ctx, readWriter, cArgs.Stats, args.Key, h.Timestamp, h.Txn)
}
// NB: even if MVCC returns an error, it may still have written an intent
// into the batch. This allows callers to consume errors like WriteTooOld
// without re-evaluating the batch. This behavior isn't particularly
// desirable, but while it remains, we need to assume that an intent could
// have been written even when an error is returned. This is harmless if the
// error is not consumed by the caller because the result will be discarded.
return result.FromAcquiredLocks(h.Txn, args.Key), err
}