feat: implement Phase 2 & Phase 3 roadmap features + update docs#2
Merged
Conversation
- README: full rewrite covering all Phase 2 & 3 features - @ShardBy AOP usage examples (3 modes) - Micrometer metrics table with metric names and tags - Read/write splitting config + code examples - Dynamic shard management Actuator endpoint - Cross-shard query optimization (affinity + paged) - Online shard migration (3-phase flow + Actuator) - CDC integration (Debezium + Kafka examples) - Full configuration reference - Updated module table and architecture diagram - Updated roadmap (v1.0/v2.0/v3.0 all released) - CHANGELOG: add v2.0.0 and v3.0.0 entries with detailed changes https://claude.ai/code/session_01PDnu78vAKJV5L32Ae3qGno
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Tổng quan
Implement toàn bộ Phase 2 (v2.0) và Phase 3 (v3.0) theo roadmap đã được approve. 49 files changed, 3.3k+ insertions.
Phase 2 — v2.0
2.1 @ShardBy AOP (
sharding-aop— module mới)ShardByAspectintercept methods annotated@ShardBy, tự động set/clearShardContext@ShardBy("accountId")), entity-field (fromEntity=true)HIGHEST_PRECEDENCE + 10— trước@TransactionalShardingAopAutoConfiguration(@ConditionalOnClass(Aspect.class))@ShardBy: xóaElementType.PARAMETER(incompatible với Spring AOP CGLIB proxies)2.2 Micrometer Metrics (
sharding-metrics— module mới)MeteredShardRouter: countersharding.routing.count{shard, strategy}+ timersharding.routing.latencyMeteredShardJdbcTemplate: timersharding.query.latency{shard, operation}+ countersharding.errors{shard, exception}ShardActuatorMetrics:MeterBindergaugesharding.shard.countsetMetricRegistry()ShardingMetricsAutoConfiguration(@ConditionalOnBean(MeterRegistry.class))ShardJdbcTemplate.executeWithShardKey:private→protected2.3 Read/Write Splitting (
sharding-readwrite— module mới)ReadWriteRoutingDataSource: route đến replica khi@Transactional(readOnly=true)hoặcShardContext.isReadOnly(); round-robin load balanceReplicaAwareShardContextTaskDecorator: propagatereadOnlyflag sang@AsyncthreadsShardContext: thêmREAD_ONLY ThreadLocal(backward-compatible)Shardrecord: thêmreadReplicaDataSources+ factoryShard.withReplicas()ShardingReadWriteAutoConfiguration(sharding.read-write-splitting.enabled=true)2.4 Dynamic Shard Management
ConsistentHashShardRouter:List<Shard>→AtomicReference+ReentrantReadWriteLock; incremental ring mutationShardRouterinterface: thêmdefault addShard(Shard)/removeShard(int)ShardManagementService: runtime add/remove/list/override với HikariCP lifecycleShardManagementEndpoint: Actuator/actuator/shards(GET/POST/DELETE)ShardingManagementAutoConfiguration(sharding.management.enabled=true)Phase 3 — v3.0
3.1 Cross-Shard Query Optimization (
sharding-jdbcmở rộng)queryShards(List<Integer> shardIndices, ...): shard affinity — query subset thay vì tất cả shardsqueryAllShardsPaged(sql, rowMapper, comparator, pageSize, pageNumber, args): LIMIT push-down xuống từng shard, merge + sort + paginate3.2 Online Shard Migration (
sharding-migration— module mới)PENDING → DOUBLE_WRITING → BACKFILLING → READY_TO_CUTOVER → COMPLETED/ROLLED_BACKShardMigrationService: start, runBackfill (batched upsert), cutover (add router overrides), rollbackShardMigrationAspect: double-write interceptor cho@ShardBy-annotated write methodsShardMigrationProgressTracker: thread-safe rows copied + progress %ShardMigrationActuatorEndpoint:/actuator/shard-migrationShardingMigrationAutoConfiguration(sharding.migration.enabled=true)3.3 CDC Integration (
sharding-cdc— module mới)ShardChangeEventrecord +ShardChangeEventListenerinterfaceDebeziumShardChangeProducer: embedded Debezium →ShardChangeEventKafkaShardChangeProducer: Kafka consumer (Debezium Kafka Connect topics) →ShardChangeEventShardMigrationConsistencyChecker: phát hiện double-write gapsShardCacheInvalidator: base class cho cache eviction on write eventsShardingCdcAutoConfiguration(sharding.cdc.enabled=true)Docs
Build changes
pom.xml: 5 modules mớisharding-autoconfigure/pom.xml: optional deps cho tất cả feature modulessharding-spring-boot-starter/pom.xml: optional depsAutoConfiguration.imports: 6 entries mớiTest plan
mvn test -pl sharding-core— unit tests cho ConsistentHashShardRouter (mutable), ShardContext (READ_ONLY flag), Shard recordmvn test -pl sharding-aop— ShardByAspect integration tests (3 extraction modes, @transactional ordering)mvn test -pl sharding-metrics— MeteredShardRouter, SimpleMeterRegistry assertionsmvn test -pl sharding-readwrite— ReadWriteRoutingDataSource routing logicmvn test -pl sharding-migration— ShardMigrationService state transitionsmvn test -pl example-app— Testcontainers integration tests (existing suite)