Shard operations
Shard operations
DataHub provides two modes for managing shards: shard horizontal scaling and split and merge. The applicable scenarios are as follows:
Shard horizontal scaling does not support merging shards; split and merge does.
To consume a topic using the Kafka protocol, enable shard horizontal scaling.
After shard horizontal scaling is enabled, the key range feature is unavailable. The
BeginHashKeyandEndHashKeyvalues are identical across all shards, so writes based on aHashKeyorPartitionKeyare not supported. Implement custom hash modulo routing at the application layer, and account for changes to the target shard for writes caused by scaling out.
Shard horizontal scaling mode
DataHub supports horizontal scaling for topic shards. Enable shard scaling mode when creating a topic to use this feature.
Step 1
Enable shard scaling using the toggle at the bottom of the New Topic dialog box.
Step 2
Click the edit icon to modify the shard count.
On the topic details page, the current shard count is displayed above the Shard list tab. Click the edit icon next to it to change the count.
Step 3
View the shards after horizontal scaling. The Shard list shows that the shard count has increased, and all shards are in the ACTIVE state.
Split and merge shards
DataHub lets you scale the number of shards in a topic up or down using the SplitShard and MergeShard operations.
Use cases
DataHub supports elastic scaling. Adjust the shard count based on real-time traffic to handle sudden traffic growth or save resources. For example, during the Double 11 shopping festival, data traffic for most topics surges, and the usual shard count may be insufficient. Use the SplitShard operation to split some shards from one into two and then from two into four. The number of shards can be increased to a maximum of 256, supporting throughput of 1,280 MB/s under current flow control limits. After the festival, traffic decreases and excess shards consume unnecessary quota. Use the MergeShard operation to merge every two shards into one until the shard count is appropriate.
Shard properties
The ListShard API returns information about all shards in a topic. Each shard has the following properties, as shown in this example:
{
"ShardId": "string",
"State": "string",
"ClosedTime": uint64,
"BeginHashKey": "string",
"EndHashKey": "string",
"ParentShardIds": [string,string,],
"LeftShardId": "string",
"RightShardId": "string"
}SplitShard
Specify a 128-bit hash key and a shard ID—either through the SDK or the console. The SplitShard operation splits the specified shard into two child shards and returns their IDs and key ranges. The original (parent) shard then enters the CLOSED state.
For example, starting with this shard:
ShardId:0 Status:ACTIVE BeginHashKey:00000000000000000000000000000000
EndHashKey:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFTo split it using the SDK:
String shardId = "0";
SplitShardRequest req = new SplitShardRequest(projectName, topicName, shardId, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
SplitShardResult resp = client.splitShard(req);After the split, you have three shards:
ShardId:0 Status:CLOSED BeginHashKey:00000000000000000000000000000000
EndHashKey:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
ShardId:1 Status:ACTIVE BeginHashKey:00000000000000000000000000000000
EndHashKey:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ShardId:2 Status:ACTIVE BeginHashKey:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
EndHashKey:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMergeShard
Specify two adjacent shard IDs—either through the SDK or the console. The MergeShard operation combines the two shards into a single new shard and returns its ID and key range. Both parent shards then enter the CLOSED state.
For example, starting with these two shards:
ShardId:0 Status:ACTIVE BeginHashKey:00000000000000000000000000000000
EndHashKey:7FFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF
ShardId:1 Status:ACTIVE BeginHashKey:7FFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF
EndHashKey:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFTo merge them using the SDK:
String shardId = "0";
String adjacentShardId = "1";
MergeShardRequest req = new MergeShardRequest(projectName, topicName, shardId, adjacentShardId);
MergeShardResult resp = client.mergeShard(req);After the merge, you have three shards:
ShardId:0 Status:CLOSED BeginHashKey:00000000000000000000000000000000
EndHashKey:7FFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF
ShardId:1 Status:CLOSED BeginHashKey:7FFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF
EndHashKey:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
ShardId:2 Status:ACTIVE BeginHashKey:00000000000000000000000000000000
EndHashKey:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUsage notes
After a split or merge, the parent shards enter the CLOSED state.
CLOSED: The shard no longer accepts writes, and another split or merge operation cannot be performed on it. Existing data remains readable by consumers.
After the topic's
lifecycleperiod expires, theCLOSEDshard is reclaimed. If a connector is configured, its task is automatically suspended once it finishes replicating data from theCLOSEDshard, and the task is automatically deleted after the shard is reclaimed.
After a split or merge, new shards must reach the ACTIVE state before they can be used normally. This usually takes no more than 5 seconds.