/
intent.go
51 lines (47 loc) · 1.47 KB
/
intent.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/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/engine"
)
// CollectIntentRows collects the key-value pairs for each intent provided. It
// also verifies that the ReturnIntents option is allowed.
//
// TODO(nvanbenschoten): mvccGetInternal should return the intent values directly
// when ReturnIntents is true. Since this will initially only be used for
// RangeLookups and since this is how they currently collect intent values, this
// is ok for now.
func CollectIntentRows(
ctx context.Context, batch engine.ReadWriter, cArgs CommandArgs, intents []roachpb.Intent,
) ([]roachpb.KeyValue, error) {
if len(intents) == 0 {
return nil, nil
}
res := make([]roachpb.KeyValue, 0, len(intents))
for _, intent := range intents {
val, _, err := engine.MVCCGetAsTxn(
ctx, batch, intent.Key, intent.Txn.Timestamp, intent.Txn,
)
if err != nil {
return nil, err
}
if val == nil {
// Intent is a deletion.
continue
}
res = append(res, roachpb.KeyValue{
Key: intent.Key,
Value: *val,
})
}
return res, nil
}