Skip to content

Commit e6f2dbe

Browse files
authored
[Breaking change] Bump APIs (#53)
1 parent ac48297 commit e6f2dbe

15 files changed

+72
-118
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Release Notes.
88
### Features
99

1010
* Support JDK21 build. Upgrade lombok version to 1.18.30.
11+
* Bump up the API of BanyanDB Server.
1112

1213
### Bugs
1314

src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/Group.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,32 @@ public abstract class Group extends NamedSchema<BanyandbCommon.Group> {
3838
*/
3939
abstract int shardNum();
4040

41-
@Nullable
42-
abstract IntervalRule blockInterval();
43-
4441
@Nullable
4542
abstract IntervalRule segmentInterval();
4643

4744
@Nullable
4845
abstract IntervalRule ttl();
4946

50-
public static Group create(String name, Catalog catalog, int shardNum, IntervalRule blockInterval, IntervalRule segmentInterval, IntervalRule ttl) {
47+
public static Group create(String name, Catalog catalog, int shardNum, IntervalRule segmentInterval, IntervalRule ttl) {
5148
Preconditions.checkArgument(shardNum > 0, "shardNum should more than 0");
52-
Preconditions.checkNotNull(blockInterval, "blockInterval is null");
5349
Preconditions.checkNotNull(segmentInterval, "segmentInterval is null");
5450
Preconditions.checkNotNull(ttl, "ttl is null");
55-
return new AutoValue_Group(null, name, null, catalog, shardNum, blockInterval, segmentInterval, ttl);
51+
return new AutoValue_Group(null, name, null, catalog, shardNum, segmentInterval, ttl);
5652
}
5753

58-
public static Group create(String name, Catalog catalog, int shardNum, IntervalRule blockInterval, IntervalRule segmentInterval, IntervalRule ttl, ZonedDateTime updatedAt) {
54+
public static Group create(String name, Catalog catalog, int shardNum, IntervalRule segmentInterval, IntervalRule ttl, ZonedDateTime updatedAt) {
5955
Preconditions.checkArgument(shardNum > 0, "shardNum should more than 0");
60-
Preconditions.checkNotNull(blockInterval, "blockInterval is null");
6156
Preconditions.checkNotNull(segmentInterval, "segmentInterval is null");
6257
Preconditions.checkNotNull(ttl, "ttl is null");
63-
return new AutoValue_Group(null, name, updatedAt, catalog, shardNum, blockInterval, segmentInterval, ttl);
58+
return new AutoValue_Group(null, name, updatedAt, catalog, shardNum, segmentInterval, ttl);
6459
}
6560

6661
public static Group create(String name) {
67-
return new AutoValue_Group(null, name, null, Catalog.UNSPECIFIED, 0, null, null, null);
62+
return new AutoValue_Group(null, name, null, Catalog.UNSPECIFIED, 0, null, null);
6863
}
6964

7065
public static Group create(String name, ZonedDateTime updatedAt) {
71-
return new AutoValue_Group(null, name, updatedAt, Catalog.UNSPECIFIED, 0, null, null, null);
66+
return new AutoValue_Group(null, name, updatedAt, Catalog.UNSPECIFIED, 0, null, null);
7267
}
7368

7469
@Override
@@ -80,7 +75,6 @@ public BanyandbCommon.Group serialize() {
8075
if (shardNum() > 0) {
8176
builder.setResourceOpts(BanyandbCommon.ResourceOpts.newBuilder()
8277
.setShardNum(shardNum())
83-
.setBlockInterval(blockInterval().serialize())
8478
.setSegmentInterval(segmentInterval().serialize())
8579
.setTtl(ttl().serialize())
8680
.build());
@@ -104,7 +98,6 @@ public static Group fromProtobuf(BanyandbCommon.Group group) {
10498
TimeUtils.parseTimestamp(group.getUpdatedAt()),
10599
catalog,
106100
opts == null ? 0 : opts.getShardNum(),
107-
opts == null ? null : IntervalRule.fromProtobuf(opts.getBlockInterval()),
108101
opts == null ? null : IntervalRule.fromProtobuf(opts.getSegmentInterval()),
109102
opts == null ? null : IntervalRule.fromProtobuf(opts.getTtl()));
110103
}

src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/IndexRule.java

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import javax.annotation.Nullable;
2929
import java.time.ZonedDateTime;
30+
import java.util.Objects;
3031

3132
@AutoValue
3233
public abstract class IndexRule extends NamedSchema<BanyandbDatabase.IndexRule> {
@@ -42,11 +43,6 @@ public abstract class IndexRule extends NamedSchema<BanyandbDatabase.IndexRule>
4243
*/
4344
abstract IndexType indexType();
4445

45-
/**
46-
* indexLocation indicates where to store index.
47-
*/
48-
abstract IndexLocation indexLocation();
49-
5046
/**
5147
* analyzer indicates how to analyze the value.
5248
*/
@@ -63,20 +59,18 @@ public final IndexRule withAnalyzer(Analyzer analyzer) {
6359
return toBuilder().setAnalyzer(analyzer).build();
6460
}
6561

66-
public static IndexRule create(String name, IndexType indexType, IndexLocation indexLocation) {
62+
public static IndexRule create(String name, IndexType indexType) {
6763
return new AutoValue_IndexRule.Builder().setName(name)
6864
.setTags(ImmutableList.of(name))
6965
.setIndexType(indexType)
70-
.setIndexLocation(indexLocation)
7166
.build();
7267
}
7368

7469
@VisibleForTesting
75-
static IndexRule create(String group, String name, IndexType indexType, IndexLocation indexLocation) {
70+
static IndexRule create(String group, String name, IndexType indexType) {
7671
return new AutoValue_IndexRule.Builder().setGroup(group).setName(name)
7772
.setTags(ImmutableList.of(name))
7873
.setIndexType(indexType)
79-
.setIndexLocation(indexLocation)
8074
.build();
8175
}
8276

@@ -90,8 +84,6 @@ abstract static class Builder {
9084

9185
abstract Builder setIndexType(IndexType indexType);
9286

93-
abstract Builder setIndexLocation(IndexLocation indexLocation);
94-
9587
abstract Builder setAnalyzer(Analyzer analyzer);
9688

9789
abstract Builder setUpdatedAt(ZonedDateTime updatedAt);
@@ -104,7 +96,6 @@ public BanyandbDatabase.IndexRule serialize() {
10496
final BanyandbDatabase.IndexRule.Builder b = BanyandbDatabase.IndexRule.newBuilder()
10597
.setMetadata(buildMetadata())
10698
.addAllTags(tags())
107-
.setLocation(indexLocation().location)
10899
.setType(indexType().type);
109100
Analyzer a = analyzer();
110101
if (a != null) {
@@ -118,51 +109,27 @@ public BanyandbDatabase.IndexRule serialize() {
118109

119110
public static IndexRule fromProtobuf(BanyandbDatabase.IndexRule pb) {
120111
IndexType indexType = IndexType.fromProtobuf(pb.getType());
121-
IndexLocation indexLocation = IndexLocation.fromProtobuf(pb.getLocation());
122112
Analyzer analyzer = Analyzer.fromProtobuf(pb.getAnalyzer());
123113
return new AutoValue_IndexRule.Builder()
124114
.setGroup(pb.getMetadata().getGroup())
125115
.setName(pb.getMetadata().getName())
126116
.setUpdatedAt(TimeUtils.parseTimestamp(pb.getUpdatedAt()))
127-
.setIndexLocation(indexLocation)
128117
.setIndexType(indexType)
129118
.setAnalyzer(analyzer)
130119
.setTags(ImmutableList.copyOf(pb.getTagsList())).build();
131120
}
132121

133122
@RequiredArgsConstructor
134123
public enum IndexType {
135-
TREE(BanyandbDatabase.IndexRule.Type.TYPE_TREE), INVERTED(BanyandbDatabase.IndexRule.Type.TYPE_INVERTED);
124+
INVERTED(BanyandbDatabase.IndexRule.Type.TYPE_INVERTED);
136125

137126
private final BanyandbDatabase.IndexRule.Type type;
138127

139128
private static IndexType fromProtobuf(BanyandbDatabase.IndexRule.Type type) {
140-
switch (type) {
141-
case TYPE_TREE:
142-
return TREE;
143-
case TYPE_INVERTED:
144-
return INVERTED;
145-
default:
146-
throw new IllegalArgumentException("unrecognized index type");
147-
}
148-
}
149-
}
150-
151-
@RequiredArgsConstructor
152-
public enum IndexLocation {
153-
SERIES(BanyandbDatabase.IndexRule.Location.LOCATION_SERIES), GLOBAL(BanyandbDatabase.IndexRule.Location.LOCATION_GLOBAL);
154-
155-
private final BanyandbDatabase.IndexRule.Location location;
156-
157-
private static IndexLocation fromProtobuf(BanyandbDatabase.IndexRule.Location loc) {
158-
switch (loc) {
159-
case LOCATION_GLOBAL:
160-
return GLOBAL;
161-
case LOCATION_SERIES:
162-
return SERIES;
163-
default:
164-
throw new IllegalArgumentException("unrecognized index location");
129+
if (Objects.requireNonNull(type) == BanyandbDatabase.IndexRule.Type.TYPE_INVERTED) {
130+
return INVERTED;
165131
}
132+
throw new IllegalArgumentException("unrecognized index type");
166133
}
167134
}
168135

src/main/proto/banyandb/v1/banyandb-common.proto

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ message Metadata {
3535
// group contains a set of options, like retention policy, max
3636
string group = 1;
3737
// name of the entity
38-
string name = 2 [(validate.rules).string.min_len = 1];
38+
string name = 2;
39+
// id is the unique identifier of the entity
40+
// if id is not set, the system will generate a unique id
3941
uint32 id = 3;
4042
// readonly. create_revision is the revision of last creation on this key.
4143
int64 create_revision = 4;
@@ -58,13 +60,10 @@ message IntervalRule {
5860
message ResourceOpts {
5961
// shard_num is the number of shards
6062
uint32 shard_num = 1 [(validate.rules).uint32.gt = 0];
61-
// block_interval indicates the length of a block
62-
// block_interval should be less than or equal to segment_interval
63-
IntervalRule block_interval = 2 [(validate.rules).message.required = true];
6463
// segment_interval indicates the length of a segment
65-
IntervalRule segment_interval = 3 [(validate.rules).message.required = true];;
64+
IntervalRule segment_interval = 2 [(validate.rules).message.required = true];
6665
// ttl indicates time to live, how long the data will be cached
67-
IntervalRule ttl = 4 [(validate.rules).message.required = true];
66+
IntervalRule ttl = 3 [(validate.rules).message.required = true];
6867
}
6968

7069
// Group is an internal object for Group management

src/main/proto/banyandb/v1/banyandb-database.proto

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ option java_package = "org.apache.skywalking.banyandb.database.v1";
2222
package banyandb.database.v1;
2323

2424
import "google/protobuf/timestamp.proto";
25+
import "validate/validate.proto";
2526
import "banyandb/v1/banyandb-common.proto";
2627
import "banyandb/v1/banyandb-model.proto";
2728

@@ -32,18 +33,17 @@ enum TagType {
3233
TAG_TYPE_STRING_ARRAY = 3;
3334
TAG_TYPE_INT_ARRAY = 4;
3435
TAG_TYPE_DATA_BINARY = 5;
35-
TAG_TYPE_ID = 6;
3636
}
3737

3838
message TagFamilySpec {
39-
string name = 1;
39+
string name = 1 [(validate.rules).string.min_len = 1];
4040
// tags defines accepted tags
41-
repeated TagSpec tags = 2;
41+
repeated TagSpec tags = 2 [(validate.rules).repeated.min_items = 1];
4242
}
4343

4444
message TagSpec {
45-
string name = 1;
46-
TagType type = 2;
45+
string name = 1 [(validate.rules).string.min_len = 1];
46+
TagType type = 2 [(validate.rules).enum.defined_only = true];
4747
// indexed_only indicates whether the tag is stored
4848
// True: It's indexed only, but not stored
4949
// False: it's stored and indexed
@@ -53,17 +53,17 @@ message TagSpec {
5353
// Stream intends to store streaming data, for example, traces or logs
5454
message Stream {
5555
// metadata is the identity of a trace series
56-
common.v1.Metadata metadata = 1;
56+
common.v1.Metadata metadata = 1 [(validate.rules).message.required = true];
5757
// tag_families
58-
repeated TagFamilySpec tag_families = 2;
58+
repeated TagFamilySpec tag_families = 2 [(validate.rules).repeated.min_items = 1];
5959
// entity indicates how to generate a series and shard a stream
60-
Entity entity = 3;
60+
Entity entity = 3 [(validate.rules).message.required = true];
6161
// updated_at indicates when the stream is updated
6262
google.protobuf.Timestamp updated_at = 4;
6363
}
6464

6565
message Entity {
66-
repeated string tag_names = 1;
66+
repeated string tag_names = 1 [(validate.rules).repeated.min_items = 1];
6767
}
6868

6969
enum FieldType {
@@ -87,25 +87,25 @@ enum CompressionMethod {
8787
// FieldSpec is the specification of field
8888
message FieldSpec {
8989
// name is the identity of a field
90-
string name = 1;
90+
string name = 1 [(validate.rules).string.min_len = 1];
9191
// field_type denotes the type of field value
92-
FieldType field_type = 2;
92+
FieldType field_type = 2 [(validate.rules).enum.defined_only = true];
9393
// encoding_method indicates how to encode data during writing
94-
EncodingMethod encoding_method = 3;
94+
EncodingMethod encoding_method = 3 [(validate.rules).enum.defined_only = true];
9595
// compression_method indicates how to compress data during writing
96-
CompressionMethod compression_method = 4;
96+
CompressionMethod compression_method = 4 [(validate.rules).enum.defined_only = true];
9797
}
9898

9999
// Measure intends to store data point
100100
message Measure {
101101
// metadata is the identity of a measure
102-
common.v1.Metadata metadata = 1;
102+
common.v1.Metadata metadata = 1 [(validate.rules).message.required = true];
103103
// tag_families are for filter measures
104-
repeated TagFamilySpec tag_families = 2;
104+
repeated TagFamilySpec tag_families = 2 [(validate.rules).repeated.min_items = 1];
105105
// fields denote measure values
106106
repeated FieldSpec fields = 3;
107107
// entity indicates which tags will be to generate a series and shard a measure
108-
Entity entity = 4;
108+
Entity entity = 4 [(validate.rules).message.required = true];
109109
// interval indicates how frequently to send a data point
110110
// valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".
111111
string interval = 5;
@@ -116,15 +116,16 @@ message Measure {
116116
// TopNAggregation generates offline TopN statistics for a measure's TopN approximation
117117
message TopNAggregation {
118118
// metadata is the identity of an aggregation
119-
common.v1.Metadata metadata = 1;
119+
common.v1.Metadata metadata = 1 [(validate.rules).message.required = true];
120120
// source_measure denotes the data source of this aggregation
121-
common.v1.Metadata source_measure = 2;
121+
common.v1.Metadata source_measure = 2 [(validate.rules).message.required = true];
122122
// field_name is the name of field used for ranking
123-
string field_name = 3;
123+
string field_name = 3 [(validate.rules).string.min_len = 1];
124124
// field_value_sort indicates how to sort fields
125125
// ASC: bottomN
126126
// DESC: topN
127127
// UNSPECIFIED: topN + bottomN
128+
// todo validate plugin exist bug https://github.com/bufbuild/protoc-gen-validate/issues/672
128129
model.v1.Sort field_value_sort = 4;
129130
// group_by_tag_names groups data points into statistical counters
130131
repeated string group_by_tag_names = 5;
@@ -142,28 +143,20 @@ message TopNAggregation {
142143
// IndexRule should bind to a subject through an IndexRuleBinding to generate proper indices.
143144
message IndexRule {
144145
// metadata define the rule's identity
145-
common.v1.Metadata metadata = 1;
146+
common.v1.Metadata metadata = 1 [(validate.rules).message.required = true];
146147
// tags are the combination that refers to an indexed object
147148
// If the elements in tags are more than 1, the object will generate a multi-tag index
148149
// Caveat: All tags in a multi-tag MUST have an identical IndexType
149-
repeated string tags = 2;
150+
repeated string tags = 2 [(validate.rules).repeated.min_items = 1];
150151
// Type determine the index structure under the hood
151152
enum Type {
152153
TYPE_UNSPECIFIED = 0;
153-
TYPE_TREE = 1;
154-
TYPE_INVERTED = 2;
154+
TYPE_INVERTED = 1;
155155
}
156156
// type is the IndexType of this IndexObject.
157-
Type type = 3;
158-
enum Location {
159-
LOCATION_UNSPECIFIED = 0;
160-
LOCATION_SERIES = 1;
161-
LOCATION_GLOBAL = 2;
162-
}
163-
// location indicates where to store index.
164-
Location location = 4;
157+
Type type = 3 [(validate.rules).enum.defined_only = true];
165158
// updated_at indicates when the IndexRule is updated
166-
google.protobuf.Timestamp updated_at = 5;
159+
google.protobuf.Timestamp updated_at = 4;
167160
enum Analyzer {
168161
ANALYZER_UNSPECIFIED = 0;
169162
// Keyword analyzer is a “noop” analyzer which returns the entire input string as a single token.
@@ -176,32 +169,33 @@ message IndexRule {
176169
ANALYZER_SIMPLE = 3;
177170
}
178171
// analyzer analyzes tag value to support the full-text searching for TYPE_INVERTED indices.
179-
Analyzer analyzer = 6;
172+
Analyzer analyzer = 5;
180173
}
181174

182175
// Subject defines which stream or measure would generate indices
183176
message Subject {
184177
// catalog is where the subject belongs to
178+
// todo validate plugin exist bug https://github.com/bufbuild/protoc-gen-validate/issues/672
185179
common.v1.Catalog catalog = 1;
186180
// name refers to a stream or measure in a particular catalog
187-
string name = 2;
181+
string name = 2 [(validate.rules).string.min_len = 1];
188182
}
189183

190184
// IndexRuleBinding is a bridge to connect severalIndexRules to a subject
191185
// This binding is valid between begin_at_nanoseconds and expire_at_nanoseconds, that provides flexible strategies
192186
// to control how to generate time series indices.
193187
message IndexRuleBinding {
194188
// metadata is the identity of this binding
195-
common.v1.Metadata metadata = 1;
189+
common.v1.Metadata metadata = 1 [(validate.rules).message.required = true];
196190
// rules refers to the IndexRule
197-
repeated string rules = 2;
191+
repeated string rules = 2 [(validate.rules).repeated.min_items = 1];
198192
// subject indicates the subject of binding action
199-
Subject subject = 3;
193+
Subject subject = 3 [(validate.rules).message.required = true];
200194
// begin_at_nanoseconds is the timestamp, after which the binding will be active
201-
google.protobuf.Timestamp begin_at = 4;
195+
google.protobuf.Timestamp begin_at = 4 [(validate.rules).timestamp.required = true];
202196
// expire_at_nanoseconds it the timestamp, after which the binding will be inactive
203197
// expire_at_nanoseconds must be larger than begin_at_nanoseconds
204-
google.protobuf.Timestamp expire_at = 5;
198+
google.protobuf.Timestamp expire_at = 5 [(validate.rules).timestamp.required = true];
205199
// updated_at indicates when the IndexRuleBinding is updated
206200
google.protobuf.Timestamp updated_at = 6;
207201
}

0 commit comments

Comments
 (0)