Shard operations
Updated at:
List, split, and merge shards by using the DataHub C++ SDK.
Overview
A topic's shard count determines its concurrent data transmission capacity. Each shard has a unique ID and can be in one of the following states:
-
Opening: The shard is initializing.
-
Active: The shard is ready for use.
Each active shard consumes server resources. Request only the number of shards you need.
List shards
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
Sample code
void ListShard()
{
try
{
const ListShardResult& lsr = client.ListShard(projectName, topicName);
std::cout<<lsr.GetShards().size()<<std::endl;
std::vector<ShardEntry> shards = lsr.GetShards();
std::vector<std::string> shardIds;
for (size_t i = 0; i < shards.size(); ++i)
{
ShardEntry shardEntry = shards[i];
shardIds.push_back(shardEntry.GetShardId());
}
}
catch(const DatahubException& e)
{
std::cerr << "List shard fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Split a shard
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
Sample code
void SplitShard()
{
std::string projectName = "";
std::string topicName = "";
try
{
const SplitShardResult& ssr = client.SplitShard(projectName, topicName, "0", "00000000000000000000000000AAAAAA");
std::cout<<ssr.GetChildShards().size()<<std::endl;
}
catch(const DatahubException& e)
{
std::cerr << "Split shardId fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Merge shards
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
Sample code
void MergeShard()
{
std::string projectName = "";
std::string topicName = "";
try
{
const MergeShardResult& msr = client.MergeShard(projectName, topicName, "0", "1");
std::cout<<msr.GetChildShard().GetShardId()<<std::endl;
std::cout<<msr.GetChildShard().GetBeginHashKey()<<std::endl;
std::cout<<msr.GetChildShard().GetEndHashKey()<<std::endl;
}
catch(const DatahubException& e)
{
std::cerr << "Merge sahrd fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Is this page helpful?