This is an automated email from the ASF dual-hosted git repository.

vgalaxies pushed a commit to branch pd-store
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


The following commit(s) were added to refs/heads/pd-store by this push:
     new a199534b8 fix(pd-store): fix hstore backend api tests failure (#2463)
a199534b8 is described below

commit a199534b89bd83c3dbfb0bb89a4220d90ff298f1
Author: sheli00 <[email protected]>
AuthorDate: Fri Mar 1 17:16:12 2024 +0800

    fix(pd-store): fix hstore backend api tests failure (#2463)
---
 .../backend/store/hstore/HstoreMetrics.java        | 44 ++++++++++++++++++++++
 .../backend/store/hstore/HstoreSessions.java       |  2 +
 .../backend/store/hstore/HstoreSessionsImpl.java   |  9 +++++
 .../backend/store/hstore/HstoreStore.java          | 10 ++++-
 .../org/apache/hugegraph/api/MetricsApiTest.java   |  3 ++
 5 files changed, 66 insertions(+), 2 deletions(-)

diff --git 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreMetrics.java
 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreMetrics.java
new file mode 100644
index 000000000..c5f180887
--- /dev/null
+++ 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreMetrics.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.backend.store.hstore;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.backend.store.BackendMetrics;
+import org.apache.hugegraph.util.InsertionOrderUtil;
+
+public class HstoreMetrics implements BackendMetrics {
+
+    private final List<HstoreSessions> dbs;
+    private final HstoreSessions.Session session;
+
+    public HstoreMetrics(List<HstoreSessions> dbs,
+                         HstoreSessions.Session session) {
+        this.dbs = dbs;
+        this.session = session;
+    }
+
+    @Override
+    public Map<String, Object> metrics() {
+        Map<String, Object> results = InsertionOrderUtil.newMap();
+        // TODO(metrics): fetch more metrics from PD
+        results.put(NODES, session.getActiveStoreSize());
+        return results;
+    }
+}
diff --git 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessions.java
 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessions.java
index 883ae7bec..0abb6458b 100755
--- 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessions.java
+++ 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessions.java
@@ -202,5 +202,7 @@ public abstract class HstoreSessions extends 
BackendSessionPool {
         }
 
         public abstract void beginTx();
+
+        public abstract int getActiveStoreSize();
     }
 }
diff --git 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java
 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java
index e091bc42f..e2ddfd97c 100755
--- 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java
+++ 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java
@@ -789,5 +789,14 @@ public class HstoreSessionsImpl extends HstoreSessions {
             HstoreSessionsImpl.getDefaultPdClient()
                               .resetIdByKey(this.getGraphName());
         }
+
+        @Override
+        public int getActiveStoreSize() {
+            try {
+                return defaultPdClient.getActiveStores().size();
+            } catch (PDException ignore) {
+            }
+            return 0;
+        }
     }
 }
diff --git 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java
 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java
index e4ba81558..1127d122e 100644
--- 
a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java
+++ 
b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java
@@ -29,6 +29,7 @@ import java.util.Set;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -59,7 +60,6 @@ import org.apache.hugegraph.util.E;
 import org.apache.hugegraph.util.Log;
 import org.slf4j.Logger;
 
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 public abstract class HstoreStore extends AbstractBackendStore<Session> {
@@ -96,8 +96,14 @@ public abstract class HstoreStore extends 
AbstractBackendStore<Session> {
     }
 
     private void registerMetaHandlers() {
+        Supplier<List<HstoreSessions>> dbsGet = () -> {
+            List<HstoreSessions> dbs = new ArrayList<>();
+            dbs.add(this.sessions);
+            return dbs;
+        };
         this.registerMetaHandler("metrics", (session, meta, args) -> {
-            return ImmutableMap.of();
+            HstoreMetrics metrics = new HstoreMetrics(dbsGet.get(), session);
+            return metrics.metrics();
         });
         this.registerMetaHandler("mode", (session, meta, args) -> {
             E.checkArgument(args.length == 1,
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java
index 0ff6151e3..e93373c1a 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java
@@ -299,6 +299,9 @@ public class MetricsApiTest extends BaseApiTest {
                     }
                 }
                 break;
+            case "hstore":
+                // TODO(metrics): check metrics info
+                break;
             default:
                 Assert.fail("Unexpected backend " + backend);
                 break;

Reply via email to