Hello, developers!
Sharding can be a complex task, but with MginDB, it's a breeze. Today, I'll show you how to set up sharding with MginDB in just a few minutes. Whether you're scaling up or down, MginDB handles the heavy lifting for you and manages it automatically.
Let’s get started!
Install MginDB
Install MginDB on your master server and on all your shards:
mgindb.com/documentation.html
Sharding
Sharding is a database architecture pattern that partitions data across multiple servers, enhancing the system's scalability and performance. MginDB will take care of everything automatically when you add or remove a shard and will redistribute the data without having to transfer any data manually nor changing the sharding scheme and keys.
Setting Up Sharding:
-
Configure Sharding Type:
Open
config.json
for all your servers and setSHARDING_TYPE
toMASTER
for your main server andSHARDING_TYPE
toSLAVE
for all your shard servers. Or use the CLI command:
CONFIG SET SHARDING_TYPE MASTER
CONFIG SET SHARDING_TYPE SLAVE
- Adding a Shard: To add a new server to the shard list, use the following command:
CONFIG SET SHARDS ADD serverip/domain
This command registers serverip/domain
as a new shard where data can be distributed.
- Removing a Shard: To remove an existing server from the shard list, use the command:
CONFIG SET SHARDS DEL serverip/domain
This removes serverip/domain
from the list of shards, redistributing any data it held to remaining shards.
- Activating Sharding: To activate sharding and start distributing data across the configured shards, execute:
CONFIG SET SHARDING 1
Ensure you add the necessary shards before activating sharding to distribute data evenly.
- Deactivating Sharding: To deactivate sharding and consolidate all data back to the master server, use:
CONFIG SET SHARDING 0
This command centralizes the data, ceasing its distribution among shards.
Additional Sharding Commands:
- Backup and Rollback: Data is always backed up before resharding. If an error occurs, it rolls back to the last backup, ensuring data integrity.
- Sharding Batch Size: Set the size of commands sent to shards per batch (default: 100):
CONFIG SET SHARDING_BATCH_SIZE value
Each of these commands needs to be executed on each server where MginDB is installed, either using the Web CLI (client.html
) or Server CLI (mgindb client
).
These settings play a crucial role in managing the distribution of data and the operational scale of your system, allowing for flexibility in handling workload and data management strategies.
Feel free to reach out with any questions or feedback. We're excited to see what you'll build with MginDB!
Link: mgindb.com
Documentation: mgindb.com/documentation.html
Happy coding!
Top comments (0)