Skip to content

Commit ca5c8b2

Browse files
authored
BanyanDB: Add support for compatibility checks based on API version (#12959)
1 parent d12c6b5 commit ca5c8b2

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

docs/en/changes/changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
source tar from the website and publish them to your private maven repository.
1414
* [Breaking Change] Remove H2 as storage option permanently. BanyanDB 0.8(OAP 10.2 required) is easy, stable and
1515
production-ready. Don't need H2 as default storage anymore.
16+
* [Breaking Change] Bump up BanyanDB server version to 0.8.0. This version is not compatible with the previous
17+
versions. Please upgrade the BanyanDB server to 0.8.0 before upgrading OAP to 10.2.0.
1618

1719
#### OAP Server
1820

@@ -58,6 +60,7 @@
5860
* Added `maxLabelCount` parameter in the `labelCount` function of OAL to limit the number of labels can be counted.
5961
* Adapt the new Browser API(`/browser/perfData/webVitals`, `/browser/perfData/resources`) protocol.
6062
* Add Circuit Breaking mechanism.
63+
* BanyanDB: Add support for compatibility checks based on the BanyanDB server's API version.
6164

6265
#### UI
6366

docs/en/setup/backend/storages/banyandb.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ bydb.version=x.y
1414
bydb.api.version=x.y
1515
```
1616

17+
If the BanyanDB server API version is not compatible with the OAP server, the OAP server will not start, and the following error message will be displayed:
18+
```shell
19+
... ERROR [] - ... Incompatible BanyanDB server API version: 0.x. But accepted versions: 0.y
20+
org.apache.skywalking.oap.server.library.module.ModuleStartException: Incompatible BanyanDB server API version...
21+
```
22+
1723
### Configuration
1824

1925
```yaml

oap-server-bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<httpcore.version>4.4.13</httpcore.version>
7373
<httpasyncclient.version>4.1.5</httpasyncclient.version>
7474
<commons-compress.version>1.21</commons-compress.version>
75-
<banyandb-java-client.version>0.8.0-rc1</banyandb-java-client.version>
75+
<banyandb-java-client.version>0.8.0-rc2</banyandb-java-client.version>
7676
<kafka-clients.version>3.4.0</kafka-clients.version>
7777
<spring-kafka-test.version>2.4.6.RELEASE</spring-kafka-test.version>
7878
<consul.client.version>1.5.3</consul.client.version>

oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBStorageClient.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,22 @@
1919
package org.apache.skywalking.oap.server.storage.plugin.banyandb;
2020

2121
import io.grpc.Status;
22+
import io.grpc.StatusRuntimeException;
23+
import java.io.IOException;
24+
import java.util.Arrays;
25+
import java.util.Collections;
26+
import java.util.List;
27+
import lombok.extern.slf4j.Slf4j;
28+
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
29+
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Group;
2230
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase;
31+
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Measure;
32+
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Stream;
33+
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.TopNAggregation;
2334
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty;
35+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyRequest.Strategy;
36+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.DeleteResponse;
37+
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.Property;
2438
import org.apache.skywalking.banyandb.v1.client.BanyanDBClient;
2539
import org.apache.skywalking.banyandb.v1.client.MeasureBulkWriteProcessor;
2640
import org.apache.skywalking.banyandb.v1.client.MeasureQuery;
@@ -33,29 +47,20 @@
3347
import org.apache.skywalking.banyandb.v1.client.StreamWrite;
3448
import org.apache.skywalking.banyandb.v1.client.TopNQuery;
3549
import org.apache.skywalking.banyandb.v1.client.TopNQueryResponse;
36-
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Group;
37-
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.TopNAggregation;
38-
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Measure;
39-
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase.Stream;
40-
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.Property;
41-
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.ApplyRequest.Strategy;
42-
import org.apache.skywalking.banyandb.property.v1.BanyandbProperty.DeleteResponse;
4350
import org.apache.skywalking.banyandb.v1.client.grpc.exception.AlreadyExistsException;
4451
import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
4552
import org.apache.skywalking.oap.server.library.client.Client;
4653
import org.apache.skywalking.oap.server.library.client.healthcheck.DelegatedHealthChecker;
4754
import org.apache.skywalking.oap.server.library.client.healthcheck.HealthCheckable;
4855
import org.apache.skywalking.oap.server.library.util.HealthChecker;
4956

50-
import java.io.IOException;
51-
import java.util.Collections;
52-
import java.util.List;
53-
5457
/**
5558
* BanyanDBStorageClient is a simple wrapper for the underlying {@link BanyanDBClient},
5659
* which implement {@link Client} and {@link HealthCheckable}.
5760
*/
61+
@Slf4j
5862
public class BanyanDBStorageClient implements Client, HealthCheckable {
63+
private static final String[] COMPATIBLE_SERVER_API_VERSIONS = {"0.8"};
5964
final BanyanDBClient client;
6065
private final DelegatedHealthChecker healthChecker = new DelegatedHealthChecker();
6166
private final int flushTimeout;
@@ -70,6 +75,29 @@ public BanyanDBStorageClient(BanyanDBStorageConfig config) {
7075
@Override
7176
public void connect() throws Exception {
7277
this.client.connect();
78+
BanyandbCommon.APIVersion apiVersion;
79+
try {
80+
apiVersion = this.client.getAPIVersion();
81+
} catch (BanyanDBException e) {
82+
final Throwable cause = e.getCause();
83+
if (cause instanceof StatusRuntimeException) {
84+
final Status status = ((StatusRuntimeException) cause).getStatus();
85+
if (Status.Code.UNIMPLEMENTED.equals(status.getCode())) {
86+
log.error("fail to get BanyanDB API version, server version < 0.8 is not supported.");
87+
}
88+
}
89+
throw e;
90+
}
91+
final boolean isCompatible = Arrays.stream(COMPATIBLE_SERVER_API_VERSIONS)
92+
.anyMatch(v -> v.equals(apiVersion.getVersion()));
93+
final String revision = apiVersion.getRevision();
94+
log.info("BanyanDB server API version: {}, revision: {}", apiVersion.getVersion(), revision);
95+
if (!isCompatible) {
96+
throw new IllegalStateException(
97+
"Incompatible BanyanDB server API version: " + apiVersion.getVersion() + ". But accepted versions: "
98+
+ String.join(", ", COMPATIBLE_SERVER_API_VERSIONS));
99+
}
100+
73101
}
74102

75103
@Override
@@ -79,10 +107,10 @@ public void shutdown() throws IOException {
79107

80108
public List<Property> listProperties(String group, String name) throws IOException {
81109
try {
82-
BanyandbProperty.QueryResponse resp = this.client.query(BanyandbProperty.QueryRequest.newBuilder()
83-
.addGroups(group)
84-
.setContainer(name)
85-
.build());
110+
BanyandbProperty.QueryResponse resp = this.client.query(BanyandbProperty.QueryRequest.newBuilder()
111+
.addGroups(group)
112+
.setContainer(name)
113+
.build());
86114
this.healthChecker.health();
87115
return resp.getPropertiesList();
88116
} catch (BanyanDBException ex) {
@@ -99,10 +127,10 @@ public List<Property> listProperties(String group, String name) throws IOExcepti
99127
public Property queryProperty(String group, String name, String id) throws IOException {
100128
try {
101129
BanyandbProperty.QueryResponse resp = this.client.query(BanyandbProperty.QueryRequest.newBuilder()
102-
.addGroups(group)
103-
.setContainer(name)
104-
.addIds(id)
105-
.build());
130+
.addGroups(group)
131+
.setContainer(name)
132+
.addIds(id)
133+
.build());
106134
this.healthChecker.health();
107135
if (resp.getPropertiesCount() == 0) {
108136
return null;

test/e2e-v2/script/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SW_AGENT_CLIENT_JS_COMMIT=af0565a67d382b683c1dbd94c379b7080db61449
2323
SW_AGENT_CLIENT_JS_TEST_COMMIT=4f1eb1dcdbde3ec4a38534bf01dded4ab5d2f016
2424
SW_KUBERNETES_COMMIT_SHA=6fe5e6f0d3b7686c6be0457733e825ee68cb9b35
2525
SW_ROVER_COMMIT=0ae8f12d6eb6cc9fa125c603ee57d0b21fc8c6d0
26-
SW_BANYANDB_COMMIT=8dfe616f332848f041b0f184b023d9a256eac39e
26+
SW_BANYANDB_COMMIT=362d68ed79c532e6d61dd6674cce38090caa0da7
2727
SW_AGENT_PHP_COMMIT=3192c553002707d344bd6774cfab5bc61f67a1d3
2828

2929
SW_CTL_COMMIT=67cbc89dd7b214d5791321a7ca992f940cb586ba

0 commit comments

Comments
 (0)