-
Notifications
You must be signed in to change notification settings - Fork 8.9k
[WIP]feature: Introduce Metadata-based Service Registration, Routing and Load Balancing #7887
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
base: 2.x
Are you sure you want to change the base?
Conversation
# Conflicts: # changes/en-us/2.x.md # changes/zh-cn/2.x.md # common/pom.xml # common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java # compressor/seata-compressor-zstd/src/test/java/org/apache/seata/compressor/zstd/ZstdUtilTest.java # config/seata-config-nacos/src/test/java/org/apache/seata/config/nacos/NacosConfigurationTest.java # config/seata-config-zk/src/test/java/org/apache/seata/config/zk/ZkConfigurationTest.java # console/pom.xml # console/src/main/resources/static/console-fe/package-lock.json # core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestParamWrapper.java # core/src/test/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingClientTest.java # core/src/test/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandlerTest.java # core/src/test/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandlerTest.java # core/src/test/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestFilterManagerTest.java # core/src/test/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestParamWrapperTest.java # dependencies/pom.xml # discovery/seata-discovery-etcd3/src/test/java/org/apache/seata/discovery/registry/etcd3/EtcdRegistryServiceImplTest.java # discovery/seata-discovery-namingserver/src/main/java/org/apache/seata/discovery/registry/namingserver/NamingserverRegistryServiceImpl.java # discovery/seata-discovery-namingserver/src/test/java/org/apache/seata/discovery/registry/namingserver/NamingserverRegistryServiceImplTest.java # discovery/seata-discovery-sofa/src/main/java/org/apache/seata/discovery/registry/sofa/SofaRegistryServiceImpl.java # mock-server/pom.xml # namingserver/pom.xml # rm-datasource/src/main/java/org/apache/seata/rm/datasource/util/XAUtils.java # rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/parser/JacksonUndoLogParserTest.java # rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java # rm-datasource/src/test/java/org/apache/seata/rm/datasource/xa/DataSourceProxyXATest.java # saga/seata-saga-statemachine-designer/package-lock.json # seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/java/org/apache/seata/spring/boot/autoconfigure/properties/registry/RegistryMetadataPropertiesTest.java # server/src/test/java/org/apache/seata/server/cluster/raft/RaftServerTest.java # server/src/test/java/org/apache/seata/server/controller/ClusterControllerTest.java # server/src/test/java/org/apache/seata/server/storage/raft/store/RaftVGroupMappingStoreManagerTest.java # test-suite/test-new-version/src/test/java/org/apache/seata/saga/annotation/AnnotationConflictTest.java # test-suite/test-new-version/src/test/java/org/apache/seata/saga/annotation/DualParserIntegrationTest.java # test-suite/test-new-version/src/test/java/org/apache/seata/saga/annotation/SagaTransactionalAnnotationAction.java # test-suite/test-new-version/src/test/java/org/apache/seata/saga/annotation/SagaTransactionalAnnotationActionImpl.java
# Conflicts: # common/src/test/java/org/apache/seata/common/loader/EnhancedServiceLoaderTest.java
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.
Pull request overview
This pull request introduces a comprehensive metadata-based service registration, routing, and load balancing system for Seata. The feature enables server instances to register with custom metadata and clients to perform metadata-driven instance selection through configurable routing filters and weighted load balancing.
Key changes include:
- Metadata support added to all registry implementations (Nacos, Eureka, Zookeeper, Redis, etc.)
- New routing framework with expression-based metadata filtering
- Weighted random load balancing strategy
- Extensive test coverage for new routing and expression parsing logic
Reviewed changes
Copilot reviewed 112 out of 112 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
application.example.yml, application.raft.example.yml |
Added metadata configuration fields for server registration |
config.txt, application.yml, application.properties |
Added client routing configuration examples |
RegistryMetadataProperties.java |
Enhanced to support dynamic metadata map with common fields |
RoutingProperties.java, MetadataRouterConfig.java |
New configuration classes for client-side routing |
StarterConstants.java |
Added routing prefix constant |
| Registry test files | Updated to use ServiceInstance instead of InetSocketAddress |
| Registry implementation files | Enhanced to support metadata in registration/discovery |
| Routing test files | Comprehensive test coverage for expression parsing, routers, and chains |
| Load balance tests | Enhanced to test weighted random load balancing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Ⅰ. Describe what this PR did
1. Core Capabilities and New Configuration Items
1.1. Server Side: Metadata Registration
1.2. Client Side: Metadata-Driven Instance Selection
Client instance selection is broken down into two stages: route filtering and load balancing, the process is as follows
Configuration items are as follows:
2. Expression Syntax:
2.1. Basic Format
key operator value, three parts separated by spaces: key name, operator, value2.2. Supported Operators
2.3. Expression Examples
Single expression:
version >= 2.3OR expression:
(version >= 2.3) || (env == dev)AND expression:
(version >= 2.3) && (env == prod)2.4. Expression Limitations
Limitation: A single expression does not support mixing && and ||
Solution: Use multiple || expressions in the router to implement complex logic
3. Metadata Enhancement for Each Registry
3.1. Enhancement Methods
setMeta()/getMeta()setMetadata()/getMetadata()instanceConfig.setMetadata()/instance.getMetadata()getMetadataMap()converts them to aMap<String, String>InstanceobjectInstanceobject itself contains ametadatafield,passed via JSON serialization/deserialization, which the API handles automatically
key=value\n)dataof theZNode, requiring manual serialization/deserialization3.2. To be implemented
3.3. Redis Enhancement Description
Implementation method: Manually build a hash structure to store metadata.
Core design:
Maintain the original live keys. Unchanged:
registry.redis.${cluster}_${serverAddr}(used for service discovery and heartbeat detection)Added metadata key:
registry.redis.${cluster}.meta_${serverAddr}(Hash structure, storing metadata)Backward compatibility:
When a new server registers, it creates both a liveness key and a metadata key (if metadata exists).
Existing clients only scan the liveness key and can discover new servers normally (ignoring the metadata key).
After scanning the liveness key, new clients attempt to retrieve the metadata key; if it does not exist or is empty, a ServiceInstance without metadata is created.
Technical details:
Metadata is stored in a separate hash structure, decoupled from liveness detection.
The TTL of both keys is refreshed synchronously (5 seconds) to ensure data consistency.
4. Compatibility Notes
Enabling
routingmode:seata-server without metadata configuration:
When route filtering is enabled, instances without metadata will be filtered.
When using a weighted random load balancing strategy, a default weight of
weight=1will be assigned.seata-client does not enable
routingmode: logical consistency backwards.Ⅱ. Does this pull request fix one issue?
fixes #7886
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Refer to #7550, use demo, modify the corresponding configurations for verification.
Ⅴ. Special notes for reviews