This document provides comprehensive guidance for developing, testing, and contributing to HugeGraph PD.
Ensure you have the following tools installed:
| Tool | Minimum Version | Recommended | Purpose |
|---|---|---|---|
| JDK | 11 | 11 or 17 | Java runtime and compilation |
| Maven | 3.5.0 | 3.8+ | Build tool and dependency management |
| Git | 2.0+ | Latest | Version control |
| IDE | N/A | IntelliJ IDEA | Development environment |
# Check Java version java -version # Expected: openjdk version "11.0.x" or later # Check Maven version mvn -version # Expected: Apache Maven 3.5.0 or later # Check Git version git --version # Expected: git version 2.x
# Clone HugeGraph repository git clone https://github.com/apache/hugegraph.git cd hugegraph # PD module location cd hugegraph-pd
hugegraph-pd directoryRequired for Lombok support:
Build all PD modules from the hugegraph-pd directory:
cd hugegraph-pd mvn clean install -DskipTests
Output:
target/ directoryhg-pd-dist/target/hugegraph-pd-<version>.tar.gzBuild Time: 2-5 minutes (first build may take longer for dependency download)
Build individual modules:
# Build gRPC module only (regenerate proto stubs) mvn clean compile -pl hg-pd-grpc # Build core module only mvn clean install -pl hg-pd-core -am -DskipTests # Build service module only mvn clean install -pl hg-pd-service -am -DskipTests # Build distribution package only mvn clean package -pl hg-pd-dist -am -DskipTests
Maven Flags:
-pl <module>: Build specific module-am: Also build required dependencies (--also-make)-DskipTests: Skip test execution (faster builds)-Dmaven.test.skip=true: Skip test compilation and executionRemove all build artifacts:
mvn clean # This also removes: # - *.tar, *.tar.gz files # - .flattened-pom.xml (CI-friendly versioning)
Build PD from HugeGraph root directory:
cd /path/to/hugegraph # Build PD and dependencies mvn clean package -pl hugegraph-pd -am -DskipTests
PD tests are located in hg-pd-test/src/main/java/ (non-standard location):
hg-pd-test/src/main/java/org/apache/hugegraph/pd/ ├── BaseTest.java # Base test class with common setup ├── core/ # Core service tests │ ├── PartitionServiceTest.java │ ├── StoreNodeServiceTest.java │ └── ... ├── client/ # Client library tests ├── raft/ # Raft integration tests └── PDCoreSuiteTest.java # Test suite (runs all tests)
# Run all PD tests mvn test # Run all tests with coverage report mvn test jacoco:report # Coverage report: hg-pd-test/target/site/jacoco/index.html
# Core module tests mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test # Client module tests mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-client-test # Common module tests mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test # REST API tests mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-rest-test
# Run specific test class mvn -pl hugegraph-pd/hg-pd-test test -Dtest=PartitionServiceTest -DfailIfNoTests=false # Run specific test method mvn -pl hugegraph-pd/hg-pd-test test -Dtest=PartitionServiceTest#testSplitPartition -DfailIfNoTests=false
IntelliJ IDEA:
PartitionServiceTest.java)View test coverage report:
# Generate coverage report mvn test jacoco:report # Open report in browser open hg-pd-test/target/site/jacoco/index.html
Target Coverage:
What Integration Tests Cover:
Enable detailed Raft logging in conf/log4j2.xml:
<Loggers> <!-- Enable Raft debug logging --> <Logger name="com.alipay.sofa.jraft" level="DEBUG"/> <!-- Specific Raft components --> <Logger name="com.alipay.sofa.jraft.core.NodeImpl" level="DEBUG"/> <Logger name="com.alipay.sofa.jraft.storage.impl" level="DEBUG"/> </Loggers>
Raft State Inspection:
# Check Raft data directory ls -lh pd_data/raft/ # Raft logs ls -lh pd_data/raft/log/ # Raft snapshots ls -lh pd_data/raft/snapshot/
Common Raft Issues:
| Issue | Symptom | Solution |
|---|---|---|
| Split-brain | Multiple leaders | Check peers-list consistency, network partitioning |
| Leader election failure | Constant candidate state | Check network latency, increase election timeout |
| Log replication lag | Followers behind leader | Check follower disk I/O, network bandwidth |
| Snapshot transfer failure | Followers can't catch up | Check snapshot directory permissions, disk space |
HugeGraph PD follows Apache HugeGraph code style.
IDE Configuration:
Key Style Rules:
import java.util.*)All source files must include Apache License header.
Check License Headers:
mvn apache-rat:check # Output: target/rat.txt (lists files missing license headers)
Add License Header: Manually add to new files:
/* * 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. */
| Type | Convention | Example |
|---|---|---|
| Classes | PascalCase | PartitionService, StoreNodeService |
| Interfaces | PascalCase (prefix with I optional) | MetadataStore or IMetadataStore |
| Methods | camelCase | getPartition(), registerStore() |
| Variables | camelCase | storeId, partitionCount |
| Constants | UPPER_SNAKE_CASE | MAX_RETRY_COUNT, DEFAULT_TIMEOUT |
| Packages | lowercase | org.apache.hugegraph.pd.core |
Public APIs must include JavaDoc comments.
Example:
/** * Get partition by partition code. * * @param graphName the graph name * @param partitionId the partition ID * @return the partition metadata * @throws PDException if partition not found or Raft error */ public Partition getPartitionByCode(String graphName, int partitionId) throws PDException { // Implementation... }
Required for:
Use custom PDException for PD-specific errors.
Example:
if (store == null) { throw new PDException(ErrorType.STORE_NOT_FOUND, "Store not found: " + storeId); }
Exception Hierarchy:
PDException: Base exception for all PD errorsRaftException: Raft-related errors (from JRaft)GrpcException: gRPC communication errorsCreate run configuration in IntelliJ IDEA:
org.apache.hugegraph.pd.HgPdApplication (in hg-pd-service)--spring.config.location=file:./conf/application.ymlhugegraph-pd/hg-pd-dist/target/hugegraph-pd-<version>/Set breakpoints in code
Click Debug (Shift+F9)
PartitionServiceTest.java)Debug PD running on a remote server.
Start PD with Debug Port:
bin/start-hugegraph-pd.sh -j "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
Connect from IDE:
5005Increase log verbosity for troubleshooting.
Edit conf/log4j2.xml:
<Loggers> <!-- Enable DEBUG logging for PD --> <Logger name="org.apache.hugegraph.pd" level="DEBUG"/> <!-- Enable DEBUG for specific package --> <Logger name="org.apache.hugegraph.pd.core.PartitionService" level="DEBUG"/> </Loggers>
View Logs:
# Real-time log monitoring tail -f logs/hugegraph-pd.log # Search logs grep "ERROR" logs/hugegraph-pd.log grep "PartitionService" logs/hugegraph-pd.log
Use JVM profiling tools to identify performance bottlenecks.
Async-profiler (recommended):
# Download async-profiler wget https://github.com/jvm-profiling-tools/async-profiler/releases/download/v2.9/async-profiler-2.9-linux-x64.tar.gz tar -xzf async-profiler-2.9-linux-x64.tar.gz # Profile running PD process ./profiler.sh -d 60 -f /tmp/pd-profile.svg <PD_PID> # View flamegraph open /tmp/pd-profile.svg
JProfiler:
Fork Repository:
Clone Your Fork:
git clone https://github.com/YOUR_USERNAME/hugegraph.git cd hugegraph
Create Feature Branch:
git checkout -b feature/your-feature-name
Make Changes:
Run Tests:
mvn test -pl hugegraph-pd/hg-pd-test -am
Check Code Style:
mvn apache-rat:check
Commit Changes:
git add . git commit -m "feat(pd): add new feature description"
Commit Message Format:
<type>(<scope>): <subject> <body> <footer>
Types: feat, fix, docs, style, refactor, test, chore
Example:
feat(pd): add partition auto-splitting - Implement partition split threshold detection - Add split operation via Raft proposal - Update partition metadata after split Closes #123
Push to Fork:
git push origin feature/your-feature-name
Create Pull Request:
PR Title Format:
[PD] Brief description of changes
PR Description Template:
## What changes were proposed in this pull request? <!-- Describe the changes in detail --> ## Why are the changes needed? <!-- Explain the motivation and context --> ## How was this patch tested? <!-- Describe the testing process --> ## Related Issues <!-- Link to related issues: Closes #123 -->
Before Submitting:
mvn apache-rat:check)Automated Checks:
Reviewer Feedback:
Approval:
Merge:
# Quick build (no tests) mvn clean install -DskipTests -pl hugegraph-pd -am # Run specific test mvn test -pl hugegraph-pd/hg-pd-test -am -Dtest=PartitionServiceTest # Generate coverage report mvn test jacoco:report -pl hugegraph-pd/hg-pd-test -am # Check license headers mvn apache-rat:check -pl hugegraph-pd # Package distribution mvn clean package -DskipTests -pl hugegraph-pd/hg-pd-dist -am # Clean all build artifacts mvn clean -pl hugegraph-pd
This guide covers:
For questions or assistance, reach out to the HugeGraph community via mailing list or GitHub issues.
Happy coding!