Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2453aad
init repo
JisoLya Jul 9, 2025
986dfef
feat(store):integrate hg-store-common(depend on server module for now)
JisoLya Jul 10, 2025
7a3e8fc
refactor grpc module
Jul 18, 2025
0de2817
refactor rocksDB module
Jul 19, 2025
928b322
add struct module
JisoLya Jul 20, 2025
7552576
refactor hg-pd-grpc module
JisoLya Jul 20, 2025
0c9e10d
fix: add missing method
JisoLya Jul 26, 2025
2eb063d
fix: add missing proto file
JisoLya Jul 28, 2025
cdbc74c
fix: add missing proto file
JisoLya Jul 30, 2025
13b04ee
fix: update maven dependency
JisoLya Jul 30, 2025
751ccd9
fix: update store module maven dependency
JisoLya Jul 30, 2025
4763b29
fix: add dependency
JisoLya Jul 31, 2025
1cc50e0
update: some method need to be fixed
JisoLya Jul 31, 2025
b359131
update: add todo tag
JisoLya Aug 3, 2025
edec16d
refactor: update part of node module
JisoLya Aug 13, 2025
68aae40
fix: add missing field in store-grpc
JisoLya Aug 13, 2025
788ba35
refactor: update listener folder
JisoLya Aug 13, 2025
971aa9c
refactor: update scan folder
JisoLya Aug 13, 2025
1ed5691
refactor: update metrics folder
JisoLya Aug 13, 2025
ad4a466
refactor: update util folder
JisoLya Aug 13, 2025
7e5d052
refactor: update util folder
JisoLya Aug 13, 2025
44a8a25
refactor: update Config,shutdown hook,Application & introduce task fo…
JisoLya Aug 14, 2025
7aa48ae
refactor: reformat code
JisoLya Aug 14, 2025
98256ce
fix: fix some conflict
JisoLya Aug 14, 2025
4558d8f
fix: add missing method in struct module
JisoLya Aug 14, 2025
0995400
refactor: integrate client module
JisoLya Aug 27, 2025
fce73e2
refactor: integrate cli module
JisoLya Aug 28, 2025
05d1769
this commit is used to resolve local conflict
JisoLya Aug 28, 2025
0be7aad
update: add tag
JisoLya Sep 8, 2025
0b4ea56
refactor: add missing method in store-client
JisoLya Sep 10, 2025
625c154
fix: fix conflict in store-client
JisoLya Sep 10, 2025
18b64ac
fix: fix conflict in store-client
JisoLya Sep 10, 2025
336a61a
fix: fix conflict in store-client
JisoLya Sep 10, 2025
ddd6e25
fix: fix conflict in store-client
JisoLya Sep 11, 2025
50550aa
fix(store): add null pointer check
JisoLya Sep 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
73 changes: 73 additions & 0 deletions hugegraph-pd/hg-pd-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hugegraph</artifactId>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>hg-pd-cli</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hg-pd-common</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>jraft-core</artifactId>
<version>1.3.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hg-store-client</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hg-pd-client</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.pd.cli;

import org.apache.hugegraph.pd.cli.cmd.ChangeRaft;
import org.apache.hugegraph.pd.cli.cmd.CheckPeers;
import org.apache.hugegraph.pd.cli.cmd.Command;
import org.apache.hugegraph.pd.cli.cmd.Config;
import org.apache.hugegraph.pd.cli.cmd.Parameter;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CliApplication {

public static void main(String[] args) {
try {
Parameter parameter = Command.toParameter(args);
Command command;
switch (parameter.getCmd()) {
case "config":
command = new Config(parameter.getPd());
break;
case "change_raft":
command = new ChangeRaft(parameter.getPd());
break;
case "check_peers":
command = new CheckPeers(parameter.getPd());
break;
default:
log.error("无效的指令");
return;
}
command.action(parameter.getParams());
} catch (Exception e) {
log.error("main thread error:", e);
System.exit(0);
} finally {

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.pd.cli.cmd;

import org.apache.hugegraph.pd.common.PDException;

/**
* @author zhangyingjie
* @date 2023/10/17
**/
public class ChangeRaft extends Command {

public ChangeRaft(String pd) {
super(pd);
}

@Override
public void action(String[] params) throws PDException {
pdClient.updatePdRaft(params[0]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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.pd.cli.cmd;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang3.StringUtils;
import org.apache.hugegraph.pd.client.MetaClient;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.grpc.Metapb;
import org.apache.hugegraph.pd.grpc.Metapb.Store;
import org.apache.hugegraph.pd.grpc.ShardGroups;
import org.apache.hugegraph.store.client.grpc.GrpcStoreStateClient;

import com.alipay.sofa.jraft.entity.PeerId;

import lombok.extern.slf4j.Slf4j;

/**
* @date 2023/10/17
**/
@Slf4j
public class CheckPeers extends Command {

private MetaClient metaClient;

public CheckPeers(String pd) {
super(pd);
metaClient = new MetaClient(config);
}

@Override
public void action(String[] params) throws PDException {
GrpcStoreStateClient stateClient = new GrpcStoreStateClient(config);
try {
ConcurrentHashMap<String, Map<String, String[]>> result = new ConcurrentHashMap<>();
List<Store> stores = pdClient.getActiveStores();
ShardGroups shardGroups = metaClient.getShardGroups();
stores.parallelStream().forEach(s -> {
for (Metapb.ShardGroup sg : shardGroups.getDataList()) {
String groupId = "hg_" + sg.getId();
PeerId leader = new PeerId();
result.computeIfAbsent(groupId, (key) -> new ConcurrentHashMap<>());
try {
String peers = stateClient.getPeers(s.getAddress(), sg.getId());
if (StringUtils.isEmpty(peers)){
continue;
}
Map<String, String[]> nodePeers = result.get(groupId);
nodePeers.put(s.getRaftAddress(), peers.split(","));
} catch (Exception e) {
if (e.getMessage() != null &&
(e.getMessage().contains("Fail to get leader of group") ||
e.getMessage().contains("Fail to find node"))) {
continue;
}
log.error(String.format("got %s: %s with error:", groupId, leader), e);
}
}
});
result.entrySet().parallelStream().forEach(entry -> {
String[] record = null;
String groupId = entry.getKey();
Map<String, String[]> nodePeers = entry.getValue();
for (Map.Entry<String, String[]> e : nodePeers.entrySet()) {
if (record == null) {
record = e.getValue();
continue;
}
if (!Arrays.equals(record, e.getValue())) {
log.error("group: {} ,got error peers: {}", groupId, nodePeers);
break;
}

}
});
log.info("got all node info:{}", result);
} catch (Exception e) {
log.error("check peers with error:", e);
throw e;
} finally {
stateClient.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.pd.cli.cmd;

import org.apache.hugegraph.pd.client.PDClient;
import org.apache.hugegraph.pd.client.PDConfig;
import org.apache.hugegraph.pd.common.PDException;

/**
* @author zhangyingjie
* @date 2023/10/17
**/
public abstract class Command {

protected static String error = "启动参数: 命令, pd地址, 命令参数, 参数分隔符(非必须)";
protected PDClient pdClient;
protected PDConfig config;

public Command(String pd) {
config = PDConfig.of(pd).setAuthority("store", "");
pdClient = PDClient.create(config);
}

public static Parameter toParameter(String[] args) throws PDException {
if (args.length < 3) {
throw new PDException(-1, error);
}
Parameter parameter = new Parameter();
parameter.setCmd(args[0]);
parameter.setPd(args[1]);
if (args.length == 3) {
parameter.setParams(new String[]{args[2]});
} else {
String t = args[3];
if (t != null && t.length() > 0) {
parameter.setParams(args[2].split(t));
parameter.setSeparator(t);
}
}
return parameter;
}

public abstract void action(String[] params) throws Exception;
}
Loading