-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pd): integrate pd-core
into hugegraph
#2478
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3dd06f2
chore(pd-store-dev): integrate `pd-grpc`, `pd-common`, `pd-client` in…
VGalaxies 894bf98
Merge branch 'master' into pd-store-dev
VGalaxies ffe5625
git add hugegraph-pd/hg-pd-core/
VGalaxies 24ad274
adjust hugegraph-pd/pom.xml
VGalaxies d40b270
format hg-pd-core
VGalaxies cc156bf
add deps for hg-pd-test
VGalaxies b7c9b68
fix comment
VGalaxies f71141c
Merge branch 'master' into intro-pd-core
VGalaxies c1ca5bf
fix: arbitrary file access during archive extraction
VGalaxies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
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-pd</artifactId> | ||
<version>${revision}</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>hg-pd-core</artifactId> | ||
|
||
<properties> | ||
<jetcd-version>0.5.10</jetcd-version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>jraft-core</artifactId> | ||
<!-- TODO: use open source version & adopt the code later --> | ||
<version>1.3.13</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.rocksdb</groupId> | ||
<artifactId>rocksdbjni</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rocksdb</groupId> | ||
<artifactId>rocksdbjni</artifactId> | ||
<version>6.29.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.hugegraph</groupId> | ||
<artifactId>hg-pd-grpc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>5.3.20</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.hugegraph</groupId> | ||
<artifactId>hg-pd-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot</artifactId> | ||
<version>2.5.14</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.12.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.9</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
137 changes: 137 additions & 0 deletions
137
hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.hugegraph.pd.common.PDException; | ||
import org.apache.hugegraph.pd.config.PDConfig; | ||
import org.apache.hugegraph.pd.grpc.Metapb; | ||
import org.apache.hugegraph.pd.meta.ConfigMetaStore; | ||
import org.apache.hugegraph.pd.meta.MetadataFactory; | ||
import org.apache.hugegraph.pd.raft.RaftEngine; | ||
import org.apache.hugegraph.pd.raft.RaftStateListener; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class ConfigService implements RaftStateListener { | ||
|
||
private final ConfigMetaStore meta; | ||
private PDConfig pdConfig; | ||
|
||
public ConfigService(PDConfig config) { | ||
this.pdConfig = config; | ||
config.setConfigService(this); | ||
meta = MetadataFactory.newConfigMeta(config); | ||
} | ||
|
||
public Metapb.PDConfig getPDConfig(long version) throws PDException { | ||
return this.meta.getPdConfig(version); | ||
} | ||
|
||
public Metapb.PDConfig getPDConfig() throws PDException { | ||
return this.meta.getPdConfig(0); | ||
} | ||
|
||
public Metapb.PDConfig setPDConfig(Metapb.PDConfig mConfig) throws PDException { | ||
Metapb.PDConfig oldCfg = getPDConfig(); | ||
Metapb.PDConfig.Builder builder = oldCfg.toBuilder().mergeFrom(mConfig) | ||
.setVersion(oldCfg.getVersion() + 1) | ||
.setTimestamp(System.currentTimeMillis()); | ||
mConfig = this.meta.setPdConfig(builder.build()); | ||
log.info("PDConfig has been modified, new PDConfig is {}", mConfig); | ||
updatePDConfig(mConfig); | ||
return mConfig; | ||
} | ||
|
||
public List<Metapb.GraphSpace> getGraphSpace(String graphSpaceName) throws PDException { | ||
return this.meta.getGraphSpace(graphSpaceName); | ||
} | ||
|
||
public Metapb.GraphSpace setGraphSpace(Metapb.GraphSpace graphSpace) throws PDException { | ||
return this.meta.setGraphSpace(graphSpace.toBuilder() | ||
.setTimestamp(System.currentTimeMillis()) | ||
.build()); | ||
} | ||
|
||
/** | ||
* 从存储中读取配置项,并覆盖全局的PDConfig对象 | ||
* | ||
* @return | ||
*/ | ||
public PDConfig loadConfig() { | ||
try { | ||
Metapb.PDConfig mConfig = this.meta.getPdConfig(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer to also keep name pdConfig |
||
if (mConfig == null) { | ||
mConfig = Metapb.PDConfig.newBuilder() | ||
.setPartitionCount(pdConfig.getInitialPartitionCount()) | ||
.setShardCount(pdConfig.getPartition().getShardCount()) | ||
.setVersion(1) | ||
.setTimestamp(System.currentTimeMillis()) | ||
.setMaxShardsPerStore( | ||
pdConfig.getPartition().getMaxShardsPerStore()) | ||
.build(); | ||
} | ||
if (RaftEngine.getInstance().isLeader()) { | ||
this.meta.setPdConfig(mConfig); | ||
} | ||
pdConfig = updatePDConfig(mConfig); | ||
} catch (Exception e) { | ||
log.error("ConfigService loadConfig exception {}", e); | ||
} | ||
return pdConfig; | ||
} | ||
|
||
public synchronized PDConfig updatePDConfig(Metapb.PDConfig mConfig) { | ||
log.info("update pd config: mConfig:{}", mConfig); | ||
pdConfig.getPartition().setShardCount(mConfig.getShardCount()); | ||
pdConfig.getPartition().setTotalCount(mConfig.getPartitionCount()); | ||
pdConfig.getPartition().setMaxShardsPerStore(mConfig.getMaxShardsPerStore()); | ||
return pdConfig; | ||
} | ||
|
||
public synchronized PDConfig setPartitionCount(int count) { | ||
Metapb.PDConfig mConfig = null; | ||
try { | ||
mConfig = getPDConfig(); | ||
mConfig = mConfig.toBuilder().setPartitionCount(count).build(); | ||
setPDConfig(mConfig); | ||
} catch (PDException e) { | ||
log.error("ConfigService exception {}", e); | ||
e.printStackTrace(); | ||
} | ||
return pdConfig; | ||
} | ||
|
||
/** | ||
* meta store中的数量 | ||
* 由于可能会受分区分裂/合并的影响,原始的partition count不推荐使用 | ||
* | ||
* @return partition count of cluster | ||
* @throws PDException when io error | ||
*/ | ||
public int getPartitionCount() throws PDException { | ||
return getPDConfig().getPartitionCount(); | ||
} | ||
|
||
@Override | ||
public void onRaftLeaderChanged() { | ||
loadConfig(); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/IdService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.hugegraph.pd.common.PDException; | ||
import org.apache.hugegraph.pd.config.PDConfig; | ||
import org.apache.hugegraph.pd.meta.IdMetaStore; | ||
import org.apache.hugegraph.pd.meta.MetadataFactory; | ||
|
||
public class IdService { | ||
|
||
private final IdMetaStore meta; | ||
private PDConfig pdConfig; | ||
|
||
public IdService(PDConfig config) { | ||
this.pdConfig = config; | ||
meta = MetadataFactory.newHugeServerMeta(config); | ||
} | ||
|
||
public PDConfig getPdConfig() { | ||
return pdConfig; | ||
} | ||
|
||
public void setPdConfig(PDConfig pdConfig) { | ||
this.pdConfig = pdConfig; | ||
} | ||
|
||
public long getId(String key, int delta) throws PDException { | ||
return meta.getId(key, delta); | ||
} | ||
|
||
public void resetId(String key) throws PDException { | ||
meta.resetId(key); | ||
} | ||
|
||
/** | ||
* 获取自增循环不重复id, 达到上限后从0开始自增.自动跳过正在使用的cid | ||
* | ||
* @param key | ||
* @param max | ||
* @return | ||
* @throws PDException | ||
*/ | ||
public long getCId(String key, long max) throws PDException { | ||
return meta.getCId(key, max); | ||
} | ||
|
||
public long getCId(String key, String name, long max) throws PDException { | ||
return meta.getCId(key, name, max); | ||
} | ||
|
||
/** | ||
* 删除一个自增循环id | ||
* | ||
* @param key | ||
* @param cid | ||
* @return | ||
* @throws PDException | ||
*/ | ||
public long delCId(String key, long cid) throws PDException { | ||
return meta.delCId(key, cid); | ||
} | ||
|
||
public long delCIdDelay(String key, String name, long cid) throws PDException { | ||
return meta.delCIdDelay(key, name, cid); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be translated