Databases 6 min read

Enum-Based Sharding Algorithm in DBLE Middleware: Configuration, Comparison, and Operational Guidelines

This article explains DBLE's enum-based sharding algorithm, how it maps user-defined enum values to shard nodes, compares it with MyCat's approach, and provides development, operational, and configuration best practices, including code examples and mapping file format guidelines.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Enum-Based Sharding Algorithm in DBLE Middleware: Configuration, Comparison, and Operational Guidelines

DBLE allows users to define an enum-to-shard mapping file, which is loaded at startup to create an in‑memory lookup table; during query execution the shard index extracted from the WHERE clause is matched against this table to locate the target shard.

Compared with MyCat, DBLE uses an "enum partition algorithm" while MyCat uses "sharding enumeration", but the usage of the enum sharding algorithm is essentially the same for both middleware.

Development notes include ensuring that shard indexes are either integers (including negatives) or strings without "=" or line breaks, that enum values are unique, and that different enum values may map to the same shard. Violating these rules can cause shard strategy loading errors.

Male=0</code>
<code>Male=1

Alternatively:

123=1</code>
<code>123=2

Another example where multiple titles map to the same shard:

Mr=0</code>
<code>Mrs=1</code>
<code>Miss=1</code>
<code>Ms=1</code>
<code>123=0

Operational notes cover expansion and shrinkage of shards: adding enum values does not require data rebalancing, but increasing the number of shards for an enum value requires partial data migration; similarly, reducing enum values or shard counts requires data rebalancing and migration.

Configuration notes focus on the rule.xml file, where the following properties can be set:

<property name="defaultNode">
<property name="mapFile">
<property name="type">

The defaultNode property is optional; if the shard index is not found in the map file, DBLE will route to the node specified by this property (must be a non‑negative integer). The mapFile property points to the enum‑to‑shard mapping file, which can be specified with a relative path if located under DBLE_HOME/conf or with an absolute path otherwise. The type property must be an integer: when set to 0, enum values in the map file must be integers; otherwise they may be any string (except "=" and line breaks).

The mapping file format is one record per line in the form <enum_value>=<shard_number>. Enum values can be integers or any characters (except "=" and line breaks), shard numbers must be non‑negative integers, duplicate enum values are prohibited, and lines starting with "//" or "#" are treated as comments.

For further reading, see the DBLE sharding algorithm series, including the first article on hash sharding and the second on stringhash sharding.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

enumDBLE
Aikesheng Open Source Community
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.