DBLE Sharding Algorithm Overview and Configuration Guide
This article explains DBLE's hash‑based sharding algorithm, detailing how logical shards are derived via modulo, mapped to physical shards through a rule.xml configuration and mapFile, compares it with MyCat, and provides development, operational, and configuration best practices along with code examples.
Author: Zhong Yue, senior DBLE user and architect with extensive experience in MySQL and large‑scale projects.
The DBLE sharding algorithm works like a hash: it first computes a modulo to obtain a logical shard number, then directly maps that number to a physical shard using a mapping table.
Configuration steps: (1) Define patternValue in rule.xml to set the number of logical shards; (2) At startup DBLE reads the user‑provided mapFile to build the logical‑to‑physical mapping; (3) During runtime, the shard index extracted from the WHERE clause is modulo‑ed to get the logical shard; (4) The logical shard is looked up in the mapping table to obtain the physical shard.
Comparison with MyCat shows both middleware use range‑based modulo sharding with no functional difference.
Development notes: the shard index must be an integer or an integer‑formatted string (negative values are allowed); maximum physical shard configuration is set per logical shard in mapFile ; minimum physical shard configuration can assign the same physical shard to all logical shards.
Data distribution: shard index determines placement, not INSERT order; if the shard index is sequential (e.g., transaction IDs), data tends to be evenly distributed, though range queries may be affected.
Operational notes: for scaling, pre‑allocate extra shards and keep patternValue unchanged to avoid data rebalancing; changing patternValue requires rebalancing.
Configuration details: rule.xml can include properties patternValue , mapFile , and defaultNode . The mapFile format is <min>-<max>=<node> , one record per line, comments allowed with // or # . DBLE does not deduplicate or validate range ordering, so manual checks are necessary.
Example code snippets:
0=0 1=1 SELECT ... WHERE shard_key BETWEEN 1 AND 100Links to the DBLE sharding series articles (hash, stringhash, enum, numberrange) and a community meetup announcement are provided.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.