@@ -15,11 +15,11 @@ import (
15
15
"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
16
16
"github.com/cockroachdb/cockroach/pkg/roachpb"
17
17
"github.com/cockroachdb/cockroach/pkg/sql/catalog/bootstrap"
18
+ "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
18
19
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
19
20
"github.com/cockroachdb/cockroach/pkg/sql/catalog/fetchpb"
20
21
"github.com/cockroachdb/cockroach/pkg/sql/row"
21
22
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
22
- "github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
23
23
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
24
24
"github.com/cockroachdb/cockroach/pkg/storage"
25
25
"github.com/cockroachdb/cockroach/pkg/testutils"
@@ -74,7 +74,17 @@ func TestRowFetcherMVCCMetadata(t *testing.T) {
74
74
defer log .Scope (t ).Close (t )
75
75
76
76
ctx := context .Background ()
77
- srv , db , kvDB := serverutils .StartServer (t , base.TestServerArgs {})
77
+ srv , db , kvDB := serverutils .StartServer (t , base.TestServerArgs {
78
+ Knobs : base.TestingKnobs {
79
+ Store : & kvserver.StoreTestingKnobs {
80
+ // With write buffering enabled on the KV client, we need to
81
+ // ensure that committing a write to the raft log returns only
82
+ // when it's applied to pebble (since we scan the engine
83
+ // directly in slurpUserDataKVs).
84
+ DisableCanAckBeforeApplication : true ,
85
+ },
86
+ },
87
+ })
78
88
defer srv .Stopper ().Stop (ctx )
79
89
s := srv .ApplicationLayer ()
80
90
codec := s .Codec ()
@@ -88,9 +98,13 @@ func TestRowFetcherMVCCMetadata(t *testing.T) {
88
98
FAMILY (a, b, c), FAMILY (d)
89
99
)` )
90
100
desc := desctestutils .TestingGetPublicTableDescriptor (kvDB , codec , `d` , `parent` )
101
+ // Request crdb_internal_mvcc_timestamp column in addition to all user
102
+ // columns from the table.
103
+ fetchColumnIDs := desc .PublicColumnIDs ()
104
+ fetchColumnIDs = append (fetchColumnIDs , colinfo .MVCCTimestampColumnID )
91
105
var spec fetchpb.IndexFetchSpec
92
106
if err := rowenc .InitIndexFetchSpec (
93
- & spec , codec , desc , desc .GetPrimaryIndex (), desc . PublicColumnIDs () ,
107
+ & spec , codec , desc , desc .GetPrimaryIndex (), fetchColumnIDs ,
94
108
); err != nil {
95
109
t .Fatal (err )
96
110
}
@@ -129,12 +143,13 @@ func TestRowFetcherMVCCMetadata(t *testing.T) {
129
143
break
130
144
}
131
145
row := rowWithMVCCMetadata {
132
- RowIsDeleted : rf .RowIsDeleted (),
133
- RowLastModified : eval .TimestampToDecimalDatum (rf .RowLastModified ()).String (),
146
+ RowIsDeleted : rf .RowIsDeleted (),
134
147
}
135
148
for _ , datum := range datums {
136
149
if datum == tree .DNull {
137
150
row .PrimaryKey = append (row .PrimaryKey , `NULL` )
151
+ } else if d , ok := datum .(* tree.DDecimal ); ok {
152
+ row .RowLastModified = d .String ()
138
153
} else {
139
154
row .PrimaryKey = append (row .PrimaryKey , string (* datum .(* tree.DString )))
140
155
}
@@ -151,8 +166,8 @@ func TestRowFetcherMVCCMetadata(t *testing.T) {
151
166
END;` ).Scan (& ts1 )
152
167
153
168
if actual , expected := kvsToRows (slurpUserDataKVs (t , store .TODOEngine (), codec )), []rowWithMVCCMetadata {
154
- {[]string {`1` , `a` , `a` , `a` }, false , ts1 },
155
- {[]string {`2` , `b` , `b` , `b` }, false , ts1 },
169
+ {PrimaryKey : []string {`1` , `a` , `a` , `a` }, RowIsDeleted : false , RowLastModified : ts1 },
170
+ {PrimaryKey : []string {`2` , `b` , `b` , `b` }, RowIsDeleted : false , RowLastModified : ts1 },
156
171
}; ! reflect .DeepEqual (expected , actual ) {
157
172
t .Errorf (`expected %v got %v` , expected , actual )
158
173
}
@@ -165,8 +180,8 @@ func TestRowFetcherMVCCMetadata(t *testing.T) {
165
180
END;` ).Scan (& ts2 )
166
181
167
182
if actual , expected := kvsToRows (slurpUserDataKVs (t , store .TODOEngine (), codec )), []rowWithMVCCMetadata {
168
- {[]string {`1` , `NULL` , `NULL` , `NULL` }, false , ts2 },
169
- {[]string {`2` , `b` , `b` , `NULL` }, false , ts2 },
183
+ {PrimaryKey : []string {`1` , `NULL` , `NULL` , `NULL` }, RowIsDeleted : false , RowLastModified : ts2 },
184
+ {PrimaryKey : []string {`2` , `b` , `b` , `NULL` }, RowIsDeleted : false , RowLastModified : ts2 },
170
185
}; ! reflect .DeepEqual (expected , actual ) {
171
186
t .Errorf (`expected %v got %v` , expected , actual )
172
187
}
@@ -177,8 +192,8 @@ func TestRowFetcherMVCCMetadata(t *testing.T) {
177
192
SELECT cluster_logical_timestamp();
178
193
END;` ).Scan (& ts3 )
179
194
if actual , expected := kvsToRows (slurpUserDataKVs (t , store .TODOEngine (), codec )), []rowWithMVCCMetadata {
180
- {[]string {`1` , `NULL` , `NULL` , `NULL` }, true , ts3 },
181
- {[]string {`2` , `b` , `b` , `NULL` }, false , ts2 },
195
+ {PrimaryKey : []string {`1` , `NULL` , `NULL` , `NULL` }, RowIsDeleted : true , RowLastModified : ts3 },
196
+ {PrimaryKey : []string {`2` , `b` , `b` , `NULL` }, RowIsDeleted : false , RowLastModified : ts2 },
182
197
}; ! reflect .DeepEqual (expected , actual ) {
183
198
t .Errorf (`expected %v got %v` , expected , actual )
184
199
}
0 commit comments