From e1698a583f296da3f0f3f3d66c1cf3e8ae5f4041 Mon Sep 17 00:00:00 2001 From: Wan Kai Date: Wed, 20 Nov 2024 11:29:50 +0800 Subject: [PATCH] BanyanDB: Support update the Group settings when OAP starting. (#12780) --- docs/en/changes/changes.md | 1 + .../plugin/banyandb/MetadataRegistry.java | 72 ++++++++++++++----- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index 644e780b5007..04c9cff8b2e9 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -21,6 +21,7 @@ * Polish mesh data dispatcher: don't generate Instance/Endpoint metrics if they are empty. * Adapt the new metadata standardization in Istio 1.24. * Bump up netty to 4.1.115, grpc to 1.68.1, boringssl to 2.0.69. +* BanyanDB: Support update the Group settings when OAP starting. #### UI diff --git a/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/MetadataRegistry.java b/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/MetadataRegistry.java index 77e8b1263ad6..f921aa847db4 100644 --- a/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/MetadataRegistry.java +++ b/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/MetadataRegistry.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -93,6 +94,8 @@ public enum MetadataRegistry { INSTANCE; private static final ObjectMapper MAPPER = new ObjectMapper(); + // BanyanDB group setting aligned with the OAP settings + private static final Set GROUP_ALIGNED = new HashSet<>(); private final Map registry = new HashMap<>(); private Map specificGroupSettings = new HashMap<>(); @@ -609,6 +612,16 @@ private List extractTagFamilySpec(List tagMetadataLi return tagFamilySpecs; } + /** + * Check if the group settings need to be updated + */ + private boolean checkGroupUpdate(BanyanDBClient client) throws BanyanDBException { + Group g = client.findGroup(this.group); + return g.getResourceOpts().getShardNum() != this.shard + || g.getResourceOpts().getSegmentInterval().getNum() != this.segmentIntervalDays + || g.getResourceOpts().getTtl().getNum() != this.ttlDays; + } + public boolean checkResourceExistence(BanyanDBClient client) throws BanyanDBException { ResourceExist resourceExist; Group.Builder gBuilder @@ -631,36 +644,57 @@ public boolean checkResourceExistence(BanyanDBClient client) throws BanyanDBExce switch (kind) { case STREAM: resourceExist = client.existStream(this.group, this.name()); - if (!resourceExist.hasGroup()) { - try { - Group g = client.define(gBuilder.setCatalog(Catalog.CATALOG_STREAM).build()); - if (g != null) { - log.info("group {} created", g.getMetadata().getName()); + gBuilder.setCatalog(Catalog.CATALOG_STREAM).build(); + if (!GROUP_ALIGNED.contains(this.group)) { + // create the group if not exist + if (!resourceExist.hasGroup()) { + try { + Group g = client.define(gBuilder.build()); + if (g != null) { + log.info("group {} created", g.getMetadata().getName()); + } + } catch (BanyanDBException ex) { + if (ex.getStatus().equals(Status.Code.ALREADY_EXISTS)) { + log.info("group {} already created by another OAP node", this.group); + } else { + throw ex; + } } - } catch (BanyanDBException ex) { - if (ex.getStatus().equals(Status.Code.ALREADY_EXISTS)) { - log.info("group {} already created by another OAP node", this.group); - } else { - throw ex; + } else { + // update the group if necessary + if (this.checkGroupUpdate(client)) { + client.update(gBuilder.build()); + log.info("group {} updated", this.group); } } + // mark the group as aligned + GROUP_ALIGNED.add(this.group); } return resourceExist.hasResource(); case MEASURE: resourceExist = client.existMeasure(this.group, this.name()); - try { + gBuilder.setCatalog(Catalog.CATALOG_MEASURE).build(); + if (!GROUP_ALIGNED.contains(this.group)) { if (!resourceExist.hasGroup()) { - Group g = client.define(gBuilder.setCatalog(Catalog.CATALOG_MEASURE).build()); - if (g != null) { - log.info("group {} created", g.getMetadata().getName()); + try { + Group g = client.define(gBuilder.build()); + if (g != null) { + log.info("group {} created", g.getMetadata().getName()); + } + } catch (BanyanDBException ex) { + if (ex.getStatus().equals(Status.Code.ALREADY_EXISTS)) { + log.info("group {} already created by another OAP node", this.group); + } else { + throw ex; + } } - } - } catch (BanyanDBException ex) { - if (ex.getStatus().equals(Status.Code.ALREADY_EXISTS)) { - log.info("group {} already created by another OAP node", this.group); } else { - throw ex; + if (this.checkGroupUpdate(client)) { + client.update(gBuilder.build()); + log.info("group {} updated", this.group); + } } + GROUP_ALIGNED.add(this.group); } return resourceExist.hasResource(); default: