Skip to content

Commit e4152ff

Browse files
committed
*: use buf to format the proto files
Signed-off-by: lance6716 <lance6716@gmail.com>
1 parent 1447c9d commit e4152ff

File tree

18 files changed

+1840
-1723
lines changed

18 files changed

+1840
-1723
lines changed

.github/workflows/unit-test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ name: "Unit Test"
33
on: [ push,pull_request ]
44

55
jobs:
6+
proto-format:
7+
name: Check proto format
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v2
12+
- name: Check format
13+
run: make proto-fmt-check
14+
615
go:
716
name: Test go generation
817
runs-on: ubuntu-latest

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all go rust c++
1+
.PHONY: all dependence check proto-fmt proto-fmt-check go rust c++
22

33
CURDIR := $(shell pwd)
44

@@ -13,6 +13,12 @@ dependence:
1313
check: dependence
1414
./scripts/check.sh
1515

16+
proto-fmt:
17+
./scripts/proto_format.sh --write
18+
19+
proto-fmt-check:
20+
./scripts/proto_format.sh --check
21+
1622
go: dependence check
1723
./scripts/generate-go.sh
1824
GO111MODULE=on go mod tidy

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ TiDB protobuf files
88

99
We use `protoc` 3.5.1, to download: [protobuf/releases/tag/v3.5.1](https://github.com/google/protobuf/releases/tag/v3.5.1)
1010

11+
## Proto formatting
12+
13+
To avoid IDE-induced diffs, we use `buf format` to keep `.proto` files consistently formatted.
14+
15+
- Check formatting (also runs as part of `make check`): `make proto-fmt-check`
16+
- Format in-place: `make proto-fmt`
17+
1118
## Generate the Go and Rust codes
1219

1320
```sh

include/rustproto.proto

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
syntax = "proto2";
22

3-
import "google/protobuf/descriptor.proto";
4-
53
// see https://github.com/gogo/protobuf/blob/master/gogoproto/gogo.proto
64
// for the original idea
75

86
package rustproto;
97

8+
import "google/protobuf/descriptor.proto";
9+
1010
extend google.protobuf.FileOptions {
11-
// When true, oneof field is generated public
12-
optional bool expose_oneof_all = 17001;
13-
// When true all fields are public, and not accessors generated
14-
optional bool expose_fields_all = 17003;
15-
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
16-
optional bool generate_accessors_all = 17004;
17-
// Use `bytes::Bytes` for `bytes` fields
18-
optional bool carllerche_bytes_for_bytes_all = 17011;
19-
// Use `bytes::Bytes` for `string` fields
20-
optional bool carllerche_bytes_for_string_all = 17012;
21-
// When true, will only generate codes that works with lite runtime.
22-
optional bool lite_runtime_all = 17035;
11+
// When true, oneof field is generated public
12+
optional bool expose_oneof_all = 17001;
13+
// When true all fields are public, and not accessors generated
14+
optional bool expose_fields_all = 17003;
15+
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
16+
optional bool generate_accessors_all = 17004;
17+
// Use `bytes::Bytes` for `bytes` fields
18+
optional bool carllerche_bytes_for_bytes_all = 17011;
19+
// Use `bytes::Bytes` for `string` fields
20+
optional bool carllerche_bytes_for_string_all = 17012;
21+
// When true, will only generate codes that works with lite runtime.
22+
optional bool lite_runtime_all = 17035;
2323
}
2424

2525
extend google.protobuf.MessageOptions {
26-
// When true, oneof field is generated public
27-
optional bool expose_oneof = 17001;
28-
// When true all fields are public, and not accessors generated
29-
optional bool expose_fields = 17003;
30-
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
31-
optional bool generate_accessors = 17004;
32-
// Use `bytes::Bytes` for `bytes` fields
33-
optional bool carllerche_bytes_for_bytes = 17011;
34-
// Use `bytes::Bytes` for `string` fields
35-
optional bool carllerche_bytes_for_string = 17012;
26+
// When true, oneof field is generated public
27+
optional bool expose_oneof = 17001;
28+
// When true all fields are public, and not accessors generated
29+
optional bool expose_fields = 17003;
30+
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
31+
optional bool generate_accessors = 17004;
32+
// Use `bytes::Bytes` for `bytes` fields
33+
optional bool carllerche_bytes_for_bytes = 17011;
34+
// Use `bytes::Bytes` for `string` fields
35+
optional bool carllerche_bytes_for_string = 17012;
3636
}
3737

3838
extend google.protobuf.FieldOptions {
39-
// When true all fields are public, and not accessors generated
40-
optional bool expose_fields_field = 17003;
41-
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
42-
optional bool generate_accessors_field = 17004;
43-
// Use `bytes::Bytes` for `bytes` fields
44-
optional bool carllerche_bytes_for_bytes_field = 17011;
45-
// Use `bytes::Bytes` for `string` fields
46-
optional bool carllerche_bytes_for_string_field = 17012;
47-
}
39+
// When true all fields are public, and not accessors generated
40+
optional bool expose_fields_field = 17003;
41+
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
42+
optional bool generate_accessors_field = 17004;
43+
// Use `bytes::Bytes` for `bytes` fields
44+
optional bool carllerche_bytes_for_bytes_field = 17011;
45+
// Use `bytes::Bytes` for `string` fields
46+
optional bool carllerche_bytes_for_string_field = 17012;
47+
}

proto/analyze.proto

Lines changed: 89 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,175 +2,173 @@ syntax = "proto2";
22

33
package tipb;
44

5-
option java_multiple_files = true;
6-
option java_package = "com.pingcap.tidb.tipb";
7-
8-
import "schema.proto";
9-
105
import "gogoproto/gogo.proto";
116
import "rustproto.proto";
7+
import "schema.proto";
128

9+
option java_multiple_files = true;
10+
option java_package = "com.pingcap.tidb.tipb";
11+
option (gogoproto.goproto_sizecache_all) = false;
12+
option (gogoproto.goproto_unkeyed_all) = false;
13+
option (gogoproto.goproto_unrecognized_all) = false;
1314
option (gogoproto.marshaler_all) = true;
1415
option (gogoproto.sizer_all) = true;
1516
option (gogoproto.unmarshaler_all) = true;
16-
option (gogoproto.goproto_unkeyed_all) = false;
17-
option (gogoproto.goproto_unrecognized_all) = false;
18-
option (gogoproto.goproto_sizecache_all) = false;
1917
option (rustproto.lite_runtime_all) = true;
2018

2119
enum AnalyzeType {
22-
TypeIndex = 0;
23-
TypeColumn = 1;
24-
TypeCommonHandle = 2;
25-
TypeSampleIndex = 3;
26-
TypeMixed = 4;
27-
TypeFullSampling = 5;
20+
TypeIndex = 0;
21+
TypeColumn = 1;
22+
TypeCommonHandle = 2;
23+
TypeSampleIndex = 3;
24+
TypeMixed = 4;
25+
TypeFullSampling = 5;
2826
}
2927

3028
message AnalyzeReq {
31-
optional AnalyzeType tp = 1 [(gogoproto.nullable) = false];
32-
// Deprecated. Start Ts has been moved to coprocessor.Request.
33-
optional uint64 start_ts_fallback = 2;
34-
optional uint64 flags = 3 [(gogoproto.nullable) = false];
35-
optional int64 time_zone_offset = 4 [(gogoproto.nullable) = false];
36-
optional AnalyzeIndexReq idx_req = 5;
37-
optional AnalyzeColumnsReq col_req = 6;
29+
optional AnalyzeType tp = 1 [(gogoproto.nullable) = false];
30+
// Deprecated. Start Ts has been moved to coprocessor.Request.
31+
optional uint64 start_ts_fallback = 2;
32+
optional uint64 flags = 3 [(gogoproto.nullable) = false];
33+
optional int64 time_zone_offset = 4 [(gogoproto.nullable) = false];
34+
optional AnalyzeIndexReq idx_req = 5;
35+
optional AnalyzeColumnsReq col_req = 6;
3836
}
3937

4038
message AnalyzeIndexReq {
41-
// bucket_size is the max histograms bucket size.
42-
optional int64 bucket_size = 1 [(gogoproto.nullable) = false];
39+
// bucket_size is the max histograms bucket size.
40+
optional int64 bucket_size = 1 [(gogoproto.nullable) = false];
4341

44-
// num_columns is the number of columns in the index.
45-
optional int32 num_columns = 2 [(gogoproto.nullable) = false];
42+
// num_columns is the number of columns in the index.
43+
optional int32 num_columns = 2 [(gogoproto.nullable) = false];
4644

47-
optional int32 cmsketch_depth = 3;
45+
optional int32 cmsketch_depth = 3;
4846

49-
optional int32 cmsketch_width = 4;
47+
optional int32 cmsketch_width = 4;
5048

51-
optional int64 sample_size = 5 [(gogoproto.nullable) = false];
49+
optional int64 sample_size = 5 [(gogoproto.nullable) = false];
5250

53-
optional int64 sketch_size = 6 [(gogoproto.nullable) = false];
51+
optional int64 sketch_size = 6 [(gogoproto.nullable) = false];
5452

55-
optional int32 top_n_size = 7;
53+
optional int32 top_n_size = 7;
5654

57-
optional int32 version = 8;
55+
optional int32 version = 8;
5856
}
5957

6058
message AnalyzeColumnsReq {
61-
// bucket_size is the max histograms bucket size, we need this because when primary key is handle,
62-
// the histogram will be directly built.
63-
optional int64 bucket_size = 1 [(gogoproto.nullable) = false];
59+
// bucket_size is the max histograms bucket size, we need this because when primary key is handle,
60+
// the histogram will be directly built.
61+
optional int64 bucket_size = 1 [(gogoproto.nullable) = false];
6462

65-
// sample_size is the max number of samples that will be collected.
66-
optional int64 sample_size = 2 [(gogoproto.nullable) = false];
63+
// sample_size is the max number of samples that will be collected.
64+
optional int64 sample_size = 2 [(gogoproto.nullable) = false];
6765

68-
// sketch_size is the max sketch size.
69-
optional int64 sketch_size = 3 [(gogoproto.nullable) = false];
66+
// sketch_size is the max sketch size.
67+
optional int64 sketch_size = 3 [(gogoproto.nullable) = false];
7068

71-
// columns_info is the info of all the columns that needs to be analyzed.
72-
repeated ColumnInfo columns_info = 4;
69+
// columns_info is the info of all the columns that needs to be analyzed.
70+
repeated ColumnInfo columns_info = 4;
7371

74-
optional int32 cmsketch_depth = 5;
72+
optional int32 cmsketch_depth = 5;
7573

76-
optional int32 cmsketch_width = 6;
74+
optional int32 cmsketch_width = 6;
7775

78-
repeated int64 primary_column_ids = 7;
76+
repeated int64 primary_column_ids = 7;
7977

80-
optional int32 version = 8;
78+
optional int32 version = 8;
8179

82-
repeated int64 primary_prefix_column_ids = 9;
80+
repeated int64 primary_prefix_column_ids = 9;
8381

84-
repeated AnalyzeColumnGroup column_groups = 10;
85-
// sample_rate is the sampling rate that how many samples will collected.
86-
// There must be one non-zero value in sample_rate and sample_size.
87-
optional double sample_rate = 11;
82+
repeated AnalyzeColumnGroup column_groups = 10;
83+
// sample_rate is the sampling rate that how many samples will collected.
84+
// There must be one non-zero value in sample_rate and sample_size.
85+
optional double sample_rate = 11;
8886
}
8987

9088
message AnalyzeMixedResp {
91-
optional AnalyzeColumnsResp columns_resp = 1;
89+
optional AnalyzeColumnsResp columns_resp = 1;
9290

93-
optional AnalyzeIndexResp index_resp = 2;
91+
optional AnalyzeIndexResp index_resp = 2;
9492
}
9593

9694
message AnalyzeColumnGroup {
97-
repeated int64 column_offsets = 1;
98-
repeated int64 prefix_lengths = 2;
95+
repeated int64 column_offsets = 1;
96+
repeated int64 prefix_lengths = 2;
9997
}
10098

10199
message AnalyzeColumnsResp {
102-
// collectors is the sample collectors for columns.
103-
repeated SampleCollector collectors = 1;
100+
// collectors is the sample collectors for columns.
101+
repeated SampleCollector collectors = 1;
104102

105-
// pk_hist is the histogram for primary key when it is the handle.
106-
optional Histogram pk_hist = 2;
103+
// pk_hist is the histogram for primary key when it is the handle.
104+
optional Histogram pk_hist = 2;
107105

108-
optional RowSampleCollector row_collector = 3;
106+
optional RowSampleCollector row_collector = 3;
109107
}
110108

111109
message AnalyzeIndexResp {
112-
optional Histogram hist = 1;
113-
optional CMSketch cms = 2;
114-
optional SampleCollector collector = 3;
110+
optional Histogram hist = 1;
111+
optional CMSketch cms = 2;
112+
optional SampleCollector collector = 3;
115113
}
116114

117115
// Bucket is an element of histogram.
118116
message Bucket {
119-
optional int64 count = 1 [(gogoproto.nullable) = false];
120-
optional bytes lower_bound = 2;
121-
optional bytes upper_bound = 3;
122-
optional int64 repeats = 4 [(gogoproto.nullable) = false];
123-
optional int64 ndv = 5;
117+
optional int64 count = 1 [(gogoproto.nullable) = false];
118+
optional bytes lower_bound = 2;
119+
optional bytes upper_bound = 3;
120+
optional int64 repeats = 4 [(gogoproto.nullable) = false];
121+
optional int64 ndv = 5;
124122
}
125123

126124
message Histogram {
127-
// ndv is the number of distinct values.
128-
optional int64 ndv = 1 [(gogoproto.nullable) = false];
125+
// ndv is the number of distinct values.
126+
optional int64 ndv = 1 [(gogoproto.nullable) = false];
129127

130-
// buckets represents all the buckets.
131-
repeated Bucket buckets = 2;
128+
// buckets represents all the buckets.
129+
repeated Bucket buckets = 2;
132130
}
133131

134132
// FMSketch is used to count distinct values for columns.
135133
message FMSketch {
136-
optional uint64 mask = 1 [(gogoproto.nullable) = false];
137-
repeated uint64 hashset = 2;
134+
optional uint64 mask = 1 [(gogoproto.nullable) = false];
135+
repeated uint64 hashset = 2;
138136
}
139137

140138
// SampleCollector is used for collect samples and calculate the count and ndv of an column.
141139
message SampleCollector {
142-
repeated bytes samples = 1;
143-
optional int64 null_count = 2 [(gogoproto.nullable) = false];
144-
optional int64 count = 3 [(gogoproto.nullable) = false];
145-
optional FMSketch fm_sketch = 4;
146-
optional CMSketch cm_sketch = 5;
147-
optional int64 total_size = 6;
140+
repeated bytes samples = 1;
141+
optional int64 null_count = 2 [(gogoproto.nullable) = false];
142+
optional int64 count = 3 [(gogoproto.nullable) = false];
143+
optional FMSketch fm_sketch = 4;
144+
optional CMSketch cm_sketch = 5;
145+
optional int64 total_size = 6;
148146
}
149147

150148
message RowSampleCollector {
151-
repeated RowSample samples = 1;
152-
repeated int64 null_counts = 2 [(gogoproto.nullable) = false];
153-
optional int64 count = 3 [(gogoproto.nullable) = false];
154-
repeated FMSketch fm_sketch = 4;
155-
repeated int64 total_size = 5;
149+
repeated RowSample samples = 1;
150+
repeated int64 null_counts = 2 [(gogoproto.nullable) = false];
151+
optional int64 count = 3 [(gogoproto.nullable) = false];
152+
repeated FMSketch fm_sketch = 4;
153+
repeated int64 total_size = 5;
156154
}
157155

158156
message RowSample {
159-
repeated bytes row = 1;
160-
optional int64 weight = 2 [(gogoproto.nullable) = false];
157+
repeated bytes row = 1;
158+
optional int64 weight = 2 [(gogoproto.nullable) = false];
161159
}
162160

163161
message CMSketchRow {
164-
repeated uint32 counters = 1;
162+
repeated uint32 counters = 1;
165163
}
166164

167165
message CMSketchTopN {
168-
optional bytes data = 1;
169-
optional uint64 count = 2 [(gogoproto.nullable) = false];
166+
optional bytes data = 1;
167+
optional uint64 count = 2 [(gogoproto.nullable) = false];
170168
}
171169

172170
message CMSketch {
173-
repeated CMSketchRow rows = 1;
174-
repeated CMSketchTopN top_n = 2;
175-
optional uint64 default_value = 3 [(gogoproto.nullable) = false];
171+
repeated CMSketchRow rows = 1;
172+
repeated CMSketchTopN top_n = 2;
173+
optional uint64 default_value = 3 [(gogoproto.nullable) = false];
176174
}

0 commit comments

Comments
 (0)