Skip to content

Commit

Permalink
fix(pd-store): fix hstore backend api tests failure (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheli00 authored Mar 1, 2024
1 parent 044fd09 commit a199534
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,7 @@ public void setGraphName(String graphName) {
}

public abstract void beginTx();

public abstract int getActiveStoreSize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -789,5 +789,14 @@ public void truncate() throws Exception {
HstoreSessionsImpl.getDefaultPdClient()
.resetIdByKey(this.getGraphName());
}

@Override
public int getActiveStoreSize() {
try {
return defaultPdClient.getActiveStores().size();
} catch (PDException ignore) {
}
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -59,7 +60,6 @@
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> {
Expand Down Expand Up @@ -96,8 +96,14 @@ public HstoreStore(final BackendStoreProvider provider,
}

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ public void testMetricsBackend() {
}
}
break;
case "hstore":
// TODO(metrics): check metrics info
break;
default:
Assert.fail("Unexpected backend " + backend);
break;
Expand Down

0 comments on commit a199534

Please sign in to comment.