Skip to content

Commit 73553cb

Browse files
authored
Adopt the status field which is changed to the string type (#77)
1 parent f7cb84b commit 73553cb

File tree

11 files changed

+162
-9
lines changed

11 files changed

+162
-9
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ Changes by Version
33
Release Notes.
44

55
0.8.0
6+
------------------
67

78
### Features
89

910
* Bump up the API to support the index mode of Measure.
1011
* Bump up the API to support the new property.
12+
* Bump up the API to adopt the status field which is changed to the string type due to the compatibility issue.
13+
* Bump up the API to support getting the API version.
1114

1215
0.7.0
1316
------------------

src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
3535
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Group;
3636
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Metadata;
37+
import org.apache.skywalking.banyandb.common.v1.ServiceGrpc;
3738
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.TopNAggregation;
3839
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Measure;
3940
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Stream;
4041
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.IndexRule;
4142
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.IndexRuleBinding;
4243
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Subject;
44+
import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
4345
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty;
4446
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.Property;
4547
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyRequest.Strategy;
@@ -75,6 +77,8 @@
7577
import java.util.concurrent.TimeUnit;
7678
import java.util.concurrent.locks.ReentrantLock;
7779
import java.util.stream.Collectors;
80+
81+
import org.apache.skywalking.banyandb.v1.client.util.StatusUtil;
7882
import org.apache.skywalking.banyandb.v1.client.util.TimeUtils;
7983

8084
import static com.google.common.base.Preconditions.checkNotNull;
@@ -227,7 +231,10 @@ public CompletableFuture<Void> write(StreamWrite streamWrite) {
227231

228232
@Override
229233
public void onNext(BanyandbStream.WriteResponse writeResponse) {
230-
switch (writeResponse.getStatus()) {
234+
BanyandbModel.Status status = StatusUtil.convertStringToStatus(writeResponse.getStatus());
235+
switch (status) {
236+
case STATUS_SUCCEED:
237+
break;
231238
case STATUS_INVALID_TIMESTAMP:
232239
responseException = new InvalidArgumentException(
233240
"Invalid timestamp: " + streamWrite.getTimestamp(), null, Status.Code.INVALID_ARGUMENT, false);
@@ -250,11 +257,10 @@ public void onNext(BanyandbStream.WriteResponse writeResponse) {
250257
responseException = new InvalidArgumentException(
251258
"Expired revision: " + metadata.getModRevision(), null, Status.Code.INVALID_ARGUMENT, true);
252259
break;
253-
case STATUS_INTERNAL_ERROR:
260+
default:
254261
responseException = new InternalException(
255-
"Internal error occurs in server", null, Status.Code.INTERNAL, true);
262+
String.format("Internal error (%s) occurs in server", writeResponse.getStatus()), null, Status.Code.INTERNAL, true);
256263
break;
257-
default:
258264
}
259265
}
260266

@@ -1064,6 +1070,20 @@ public MetadataCache.EntityMetadata updateMeasureMetadataCacheFromSever(String g
10641070
return this.metadataCache.updateMeasureFromSever(group, name);
10651071
}
10661072

1073+
/**
1074+
* Get the API version of the server
1075+
*
1076+
* @return the API version of the server
1077+
* @throws BanyanDBException if the server is not reachable
1078+
*/
1079+
public BanyandbCommon.APIVersion getAPIVersion() throws BanyanDBException {
1080+
ServiceGrpc.ServiceBlockingStub stub = ServiceGrpc.newBlockingStub(this.channel);
1081+
return HandleExceptionsWith.callAndTranslateApiException(() -> {
1082+
BanyandbCommon.GetAPIVersionResponse resp = stub.getAPIVersion(BanyandbCommon.GetAPIVersionRequest.getDefaultInstance());
1083+
return resp.getVersion();
1084+
});
1085+
}
1086+
10671087
@Override
10681088
public void close() throws IOException {
10691089
connectionEstablishLock.lock();

src/main/java/org/apache/skywalking/banyandb/v1/client/MeasureBulkWriteProcessor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
2525
import org.apache.skywalking.banyandb.measure.v1.BanyandbMeasure;
2626
import org.apache.skywalking.banyandb.measure.v1.MeasureServiceGrpc;
27+
import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
2728
import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
29+
import org.apache.skywalking.banyandb.v1.client.util.StatusUtil;
2830

2931
import javax.annotation.concurrent.ThreadSafe;
3032

@@ -69,7 +71,10 @@ protected StreamObserver<BanyandbMeasure.WriteRequest> buildStreamObserver(Measu
6971

7072
@Override
7173
public void onNext(BanyandbMeasure.WriteResponse writeResponse) {
72-
switch (writeResponse.getStatus()) {
74+
BanyandbModel.Status status = StatusUtil.convertStringToStatus(writeResponse.getStatus());
75+
switch (status) {
76+
case STATUS_SUCCEED:
77+
break;
7378
case STATUS_EXPIRED_SCHEMA:
7479
BanyandbCommon.Metadata metadata = writeResponse.getMetadata();
7580
String schemaKey = metadata.getGroup() + "." + metadata.getName();
@@ -84,6 +89,7 @@ public void onNext(BanyandbMeasure.WriteResponse writeResponse) {
8489
}
8590
break;
8691
default:
92+
log.warn("Write measure failed with status: {}", status);
8793
}
8894
}
8995

src/main/java/org/apache/skywalking/banyandb/v1/client/StreamBulkWriteProcessor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import lombok.extern.slf4j.Slf4j;
2424

2525
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
26+
import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
2627
import org.apache.skywalking.banyandb.stream.v1.StreamServiceGrpc;
2728
import org.apache.skywalking.banyandb.stream.v1.BanyandbStream;
2829
import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
30+
import org.apache.skywalking.banyandb.v1.client.util.StatusUtil;
2931

3032
import javax.annotation.concurrent.ThreadSafe;
3133

@@ -70,7 +72,10 @@ protected StreamObserver<BanyandbStream.WriteRequest> buildStreamObserver(Stream
7072

7173
@Override
7274
public void onNext(BanyandbStream.WriteResponse writeResponse) {
73-
switch (writeResponse.getStatus()) {
75+
BanyandbModel.Status status = StatusUtil.convertStringToStatus(writeResponse.getStatus());
76+
switch (status) {
77+
case STATUS_SUCCEED:
78+
break;
7479
case STATUS_EXPIRED_SCHEMA:
7580
BanyandbCommon.Metadata metadata = writeResponse.getMetadata();
7681
String schemaKey = metadata.getGroup() + "." + metadata.getName();
@@ -85,6 +90,7 @@ public void onNext(BanyandbStream.WriteResponse writeResponse) {
8590
}
8691
break;
8792
default:
93+
log.warn("Write stream failed with status: {}", status);
8894
}
8995
}
9096

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.banyandb.v1.client.util;
20+
21+
import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
22+
23+
/**
24+
* Status is a utility class for converting between strings and Status enums.
25+
*/
26+
public class StatusUtil {
27+
28+
/**
29+
* Convert a Status enum to a string.
30+
*
31+
* @param statusString the string to convert
32+
* @return the Status enum
33+
*/
34+
public static BanyandbModel.Status convertStringToStatus(String statusString) {
35+
try {
36+
return BanyandbModel.Status.valueOf(statusString);
37+
} catch (IllegalArgumentException e) {
38+
// Return a specific enum value for unknown strings
39+
return BanyandbModel.Status.STATUS_UNSPECIFIED;
40+
}
41+
}
42+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,29 @@ message Tag {
115115
// value is the value of the tag.
116116
string value = 2;
117117
}
118+
119+
120+
// APIVersion is the version of the API
121+
message APIVersion {
122+
// version is the version of the API
123+
string version = 1;
124+
// revision is the commit hash of the API
125+
string revision = 2;
126+
}
127+
128+
// GetAPIVersionRequest is the request for GetAPIVersion
129+
message GetAPIVersionRequest {
130+
// empty
131+
}
132+
133+
// GetAPIVersionResponse is the response for GetAPIVersion
134+
message GetAPIVersionResponse {
135+
// version is the version of the API
136+
APIVersion version = 1;
137+
}
138+
139+
// Service is the service for the API
140+
service Service {
141+
// GetAPIVersion returns the version of the API
142+
rpc GetAPIVersion(GetAPIVersionRequest) returns (GetAPIVersionResponse);
143+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ message WriteResponse {
169169
// the message_id from request.
170170
uint64 message_id = 1 [(validate.rules).uint64.gt = 0];
171171
// status indicates the request processing result
172-
model.v1.Status status = 2 [(validate.rules).enum.defined_only = true];
172+
string status = 2;
173173
// the metadata from request when request fails
174174
common.v1.Metadata metadata = 3;
175175
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,5 @@ enum Status {
216216
STATUS_NOT_FOUND = 3;
217217
STATUS_EXPIRED_SCHEMA = 4;
218218
STATUS_INTERNAL_ERROR = 5;
219+
STATUS_DISK_FULL = 6;
219220
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ message WriteResponse {
102102
// the message_id from request.
103103
uint64 message_id = 1 [(validate.rules).uint64.gt = 0];
104104
// status indicates the request processing result
105-
model.v1.Status status = 2 [(validate.rules).enum.defined_only = true];
105+
string status = 2;
106106
// the metadata from request when request fails
107107
common.v1.Metadata metadata = 3;
108108
}

src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class BanyanDBClientTestCI {
3232
private static final String REGISTRY = "ghcr.io";
3333
private static final String IMAGE_NAME = "apache/skywalking-banyandb";
34-
private static final String TAG = "1d4ddc3d42103dc3364ad729403c4154690be195";
34+
private static final String TAG = "362d68ed79c532e6d61dd6674cce38090caa0da7";
3535

3636
private static final String IMAGE = REGISTRY + "/" + IMAGE_NAME + ":" + TAG;
3737

0 commit comments

Comments
 (0)