Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dingo_cli #1274

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/check_store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cd ${DINGODB_BIN}
times=0
DINGODB_HAVE_STORE_AVAILABLE=0
while [ "${DINGODB_HAVE_STORE_AVAILABLE}" -eq 0 -a ${times} -lt ${FLAGS_retry_times} ]; do
DINGODB_HAVE_STORE_AVAILABLE=$(./dingodb_client GetStoreMap |grep -c DINGODB_HAVE_STORE_AVAILABLE)
DINGODB_HAVE_STORE_AVAILABLE=$(./dingodb_cli GetStoreMap |grep -c DINGODB_HAVE_STORE_AVAILABLE)
times=`expr $times + 1`

echo "avaiable store count = ${DINGODB_HAVE_STORE_AVAILABLE}, times = ${times}, wait 2 second"
Expand All @@ -28,7 +28,7 @@ done
times=0
DINGODB_HAVE_INDEX_AVAILABLE=0
while [ "${DINGODB_HAVE_INDEX_AVAILABLE}" -eq 0 -a ${times} -lt ${FLAGS_retry_times} ]; do
DINGODB_HAVE_INDEX_AVAILABLE=$(./dingodb_client GetStoreMap |grep -c DINGODB_HAVE_INDEX_AVAILABLE)
DINGODB_HAVE_INDEX_AVAILABLE=$(./dingodb_cli GetStoreMap |grep -c DINGODB_HAVE_INDEX_AVAILABLE)
times=`expr $times + 1`

echo "avaiable index count = ${DINGODB_HAVE_INDEX_AVAILABLE}, times = ${times}, wait 2 second"
Expand All @@ -38,14 +38,14 @@ done
times=0
DINGODB_HAVE_DOCUMENT_AVAILABLE=0
while [ "${DINGODB_HAVE_DOCUMENT_AVAILABLE}" -eq 0 -a ${times} -lt ${FLAGS_retry_times} ]; do
DINGODB_HAVE_DOCUMENT_AVAILABLE=$(./dingodb_client GetStoreMap |grep -c DINGODB_HAVE_DOCUMENT_AVAILABLE)
DINGODB_HAVE_DOCUMENT_AVAILABLE=$(./dingodb_cli GetStoreMap |grep -c DINGODB_HAVE_DOCUMENT_AVAILABLE)
times=`expr $times + 1`

echo "avaiable document count = ${DINGODB_HAVE_DOCUMENT_AVAILABLE}, times = ${times}, wait 2 second"
sleep 2
done

./dingodb_client GetStoreMap
./dingodb_cli GetStoreMap

echo "dingo-store is READY"

47 changes: 41 additions & 6 deletions src/client_v2/coordinator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,18 @@ void RunRaftRemovePeer(RaftRemovePeerOption const &opt) {
DINGO_LOG(INFO) << response.DebugString();
}

void SetUpRaftTansferLeader(CLI::App &app) {
auto opt = std::make_shared<RaftTansferLeaderOption>();
void SetUpRaftTransferLeader(CLI::App &app) {
auto opt = std::make_shared<RaftTransferLeaderOption>();

auto *cmd = app.add_subcommand("RaftTansferLeader", "Raft transfer leader")->group("Coordinator Command");
auto *cmd = app.add_subcommand("RaftTransferLeader", "Raft transfer leader")->group("Coordinator Command");
cmd->add_option("--coor_addr", opt->coordinator_addr, "Coordinator servr addr, for example: 127.0.0.1:22001")
->required();
cmd->add_option("--peer", opt->peer, "Request parameter peer, for example: 127.0.0.1:22101")->required();
cmd->add_option("--index", opt->index, "Index")->expected(0, 3);

cmd->callback([opt]() { RunRaftTansferLeader(*opt); });
cmd->callback([opt]() { RunRaftTransferLeader(*opt); });
}
void RunRaftTansferLeader(RaftTansferLeaderOption const &opt) {
void RunRaftTransferLeader(RaftTransferLeaderOption const &opt) {
dingodb::pb::coordinator::RaftControlRequest request;
dingodb::pb::coordinator::RaftControlResponse response;
request.set_add_peer(opt.peer);
Expand Down Expand Up @@ -999,6 +999,41 @@ void RunGetStoreMap(GetStoreMapOption const &opt) {
auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteraction()->SendRequest("GetStoreMap", request, response);
Pretty::Show(response);

std::map<std::string, dingodb::pb::common::Store> store_map_by_type_id;
for (const auto &store : response.storemap().stores()) {
store_map_by_type_id[std::to_string(store.store_type()) + "-" + std::to_string(store.id())] = store;
}

int32_t store_count_available = 0;
int32_t index_count_available = 0;
int32_t document_count_available = 0;

for (auto const &[first, store] : store_map_by_type_id) {
if (store.state() == dingodb::pb::common::StoreState::STORE_NORMAL &&
store.store_type() == dingodb::pb::common::StoreType::NODE_TYPE_STORE) {
store_count_available++;
}
if (store.state() == dingodb::pb::common::StoreState::STORE_NORMAL &&
store.store_type() == dingodb::pb::common::StoreType::NODE_TYPE_INDEX) {
index_count_available++;
}
if (store.state() == dingodb::pb::common::StoreState::STORE_NORMAL &&
store.store_type() == dingodb::pb::common::StoreType::NODE_TYPE_DOCUMENT) {
document_count_available++;
}
}

// don't modify this log, it is used by sdk
if (store_count_available > 0) {
std::cout << "DINGODB_HAVE_STORE_AVAILABLE, store_count=" << store_count_available << "\n";
}
if (index_count_available > 0) {
std::cout << "DINGODB_HAVE_INDEX_AVAILABLE, index_count=" << index_count_available << "\n";
}
if (document_count_available > 0) {
std::cout << "DINGODB_HAVE_DOCUMENT_AVAILABLE, document_count=" << document_count_available << "\n";
}
}

void SetUpGetExecutorMap(CLI::App &app) {
Expand Down Expand Up @@ -1063,7 +1098,7 @@ void RunGetDeleteRegionMap(GetDeleteRegionMapOption const &opt) {

void SetUpAddDeleteRegionMap(CLI::App &app) {
auto opt = std::make_shared<AddDeleteRegionMapOption>();
auto *cmd = app.add_subcommand("AddDeleteRegionMap", "Add delete region map")->group("Coordinator Command");
auto *cmd = app.add_subcommand("AddDeletedRegionMap", "Add delete region map")->group("Coordinator Command");
cmd->add_option("--coor_url", opt->coor_url, "Coordinator url, default:file://./coor_list");
cmd->add_option("--is_force", opt->is_force, "Request parameter force ");
cmd->add_option("--id", opt->id, "Request parameter region id ")->required();
Expand Down
7 changes: 3 additions & 4 deletions src/client_v2/coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ struct RaftRemovePeerOption {
void SetUpRaftRemovePeer(CLI::App &app);
void RunRaftRemovePeer(RaftRemovePeerOption const &opt);

// todo
struct RaftTansferLeaderOption {
struct RaftTransferLeaderOption {
std::string coordinator_addr;
std::string peer;
int index;
};
void SetUpRaftTansferLeader(CLI::App &app);
void RunRaftTansferLeader(RaftTansferLeaderOption const &opt);
void SetUpRaftTransferLeader(CLI::App &app);
void RunRaftTransferLeader(RaftTransferLeaderOption const &opt);

struct RaftSnapshotOption {
std::string coordinator_addr;
Expand Down
50 changes: 26 additions & 24 deletions src/client_v2/kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ void RunGetRawKvIndex(GetRawKvIndexOptions const& opt) {

request.set_key(opt.key);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("GetRawKvIndex", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("GetRawKvIndex",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "GetRawKvIndex failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand Down Expand Up @@ -314,8 +314,8 @@ void RunGetRawKvRev(GetRawKvRevOptions const& opt) {
request.mutable_revision()->set_main(opt.revision);
request.mutable_revision()->set_sub(opt.sub_revision);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("GetRawKvRev", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("GetRawKvRev",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "GetRawKvRev failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand All @@ -331,7 +331,9 @@ void SetUpCoorKvRange(CLI::App& app) {
cmd->add_option("--key", opt->key, "Request parameter key")->required();
cmd->add_option("--range_end", opt->range_end, "Request parameter range_end")->default_val("");
cmd->add_option("--sub_rversion", opt->limit, "Request parameter sub_rversion")->default_val(50);
cmd->add_option("--keys_only", opt->keys_only, "Request parameter keys_only")->default_val(false)->default_str("false");
cmd->add_option("--keys_only", opt->keys_only, "Request parameter keys_only")
->default_val(false)
->default_str("false");
cmd->add_option("--count_only", opt->count_only, "Request parameter keys_count_only")
->default_val(false)
->default_str("false");
Expand All @@ -351,8 +353,8 @@ void RunCoorKvRange(CoorKvRangeOptions const& opt) {
request.set_keys_only(opt.keys_only);
request.set_count_only(opt.count_only);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("KvRange", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("KvRange", request,
response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "KvRange failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand Down Expand Up @@ -429,8 +431,8 @@ void RunCoorKvDeleteRange(CoorKvDeleteRangeOptions const& opt) {
request.set_range_end(opt.range_end);
request.set_need_prev_kv(opt.need_prev_kv);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("KvDeleteRange", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("KvDeleteRange",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "KvDeleteRange failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand All @@ -442,7 +444,7 @@ void RunCoorKvDeleteRange(CoorKvDeleteRangeOptions const& opt) {

void SetUpCoorKvCompaction(CLI::App& app) {
auto opt = std::make_shared<CoorKvCompactionOptions>();
auto* cmd = app.add_subcommand("CoorKvDeleteCompaction", "Coor kv compaction ")->group("Kv command");
auto* cmd = app.add_subcommand("CoorKvCompaction", "Coor kv compaction ")->group("Kv command");
cmd->add_option("--key", opt->key, "Request parameter key")->required();
cmd->add_option("--range_end", opt->range_end, "Request parameter range_end")->default_val("");
cmd->add_option("--revision", opt->revision, "Request parameter revision")->required();
Expand All @@ -460,8 +462,8 @@ void RunCoorKvCompaction(CoorKvCompactionOptions const& opt) {
request.set_range_end(opt.range_end);
request.set_compact_revision(opt.revision);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("KvCompaction", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("KvCompaction",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "KvCompaction failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand Down Expand Up @@ -520,8 +522,8 @@ void RunOneTimeWatch(OneTimeWatchOptions const& opt) {
for (uint32_t i = 0; i < opt.max_watch_count; i++) {
// wait 600s for event
std::cout << "SendRequest watch_count=" << i << std::endl;
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("Watch", request,
response, 600000);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest(
"Watch", request, response, 600000);
std::cout << "SendRequest status=" << status << ", watch_count=" << i << std::endl;
std::cout << response.DebugString() << std::endl;
}
Expand Down Expand Up @@ -626,8 +628,8 @@ void RunLeaseGrant(LeaseGrantOptions const& opt) {
request.set_id(opt.id);
request.set_ttl(opt.ttl);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseGrant", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseGrant",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "LeaseGrant failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand All @@ -654,8 +656,8 @@ void RunLeaseRevoke(LeaseRevokeOptions const& opt) {

request.set_id(opt.id);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseRevoke", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseRevoke",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "LeaseRevoke failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand All @@ -681,8 +683,8 @@ void RunLeaseRenew(LeaseRenewOptions const& opt) {
dingodb::pb::version::LeaseRenewResponse response;
request.set_id(opt.id);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseRenew", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseRenew",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "LeaseRenew failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand All @@ -709,8 +711,8 @@ void RunLeaseQuery(LeaseQueryOptions const& opt) {
request.set_id(opt.id);
request.set_keys(true);

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseQuery", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("LeaseQuery",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "LeaseQuery failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand All @@ -734,8 +736,8 @@ void RunListLeases(ListLeasesOptions const& opt) {
dingodb::pb::version::ListLeasesRequest request;
dingodb::pb::version::ListLeasesResponse response;

auto status =
CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("ListLeases", request, response);
auto status = CoordinatorInteraction::GetInstance().GetCoorinatorInteractionVersion()->SendRequest("ListLeases",
request, response);
if (response.has_error() && response.error().errcode() != dingodb::pb::error::Errno::OK) {
std::cout << "ListLeases failed, error: "
<< dingodb::pb::error::Errno_descriptor()->FindValueByNumber(response.error().errcode())->name() << " "
Expand Down
Loading
Loading