forked from dingodb/dingo-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinator_client_function_incr.cc
140 lines (114 loc) · 5.52 KB
/
coordinator_client_function_incr.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (c) 2023 dingodb.com, Inc. All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
// See the License for the specific language governing permissions and
// limitations under the License.
#include <memory>
#include "common/logging.h"
#include "coordinator/coordinator_interaction.h"
#include "coordinator_client_function.h"
DEFINE_int64(incr_start_id, 1, "Start id of auto_increment.");
DEFINE_bool(force, true, "Force set auto increment.");
DEFINE_int32(generate_count, 10000, "Generate auto increment id count.");
DEFINE_int32(auto_increment_increment, 1, "SQL var auto_increment_increment.");
DEFINE_int32(auto_increment_offset, 1, "SQL var auto_increment_offset.");
DECLARE_bool(log_each_request);
DECLARE_string(id);
// usage example:
// ./dingodb_client -method=GetCoordinatorMap
// ./dingodb_client -id=888 -method=CreateAutoIncrement
// ./dingodb_client -id=888 -method=GetAutoIncrement
// ./dingodb_client -id=888 -generate_count=10000 -method=GenerateAutoIncrement
// ./dingodb_client -id=888 -incr_start_id=110000 -method=UpdateAutoIncrement
// ./dingodb_client -id=888 -method=DeleteAutoIncrement
void SendGetAutoIncrements(std::shared_ptr<dingodb::CoordinatorInteraction> coordinator_interaction) {
dingodb::pb::meta::GetAutoIncrementsRequest request;
dingodb::pb::meta::GetAutoIncrementsResponse response;
auto status = coordinator_interaction->SendRequest("GetAutoIncrements", request, response);
DINGO_LOG(INFO) << "SendRequest status=" << status;
DINGO_LOG(INFO) << response.DebugString();
}
void SendGetAutoIncrement(std::shared_ptr<dingodb::CoordinatorInteraction> coordinator_interaction) {
dingodb::pb::meta::GetAutoIncrementRequest request;
dingodb::pb::meta::GetAutoIncrementResponse response;
auto* table_id = request.mutable_table_id();
table_id->set_entity_type(dingodb::pb::meta::EntityType::ENTITY_TYPE_TABLE);
if (FLAGS_id.empty()) {
DINGO_LOG(WARNING) << "id is empty";
return;
}
table_id->set_entity_id(std::stol(FLAGS_id));
auto status = coordinator_interaction->SendRequest("GetAutoIncrement", request, response);
DINGO_LOG(INFO) << "SendRequest status=" << status;
DINGO_LOG(INFO) << response.DebugString();
}
void SendCreateAutoIncrement(std::shared_ptr<dingodb::CoordinatorInteraction> coordinator_interaction) {
dingodb::pb::meta::CreateAutoIncrementRequest request;
dingodb::pb::meta::CreateAutoIncrementResponse response;
auto* table_id = request.mutable_table_id();
table_id->set_entity_type(dingodb::pb::meta::EntityType::ENTITY_TYPE_TABLE);
if (FLAGS_id.empty()) {
DINGO_LOG(WARNING) << "id is empty";
return;
}
table_id->set_entity_id(std::stol(FLAGS_id));
request.set_start_id(FLAGS_incr_start_id);
auto status = coordinator_interaction->SendRequest("CreateAutoIncrement", request, response);
DINGO_LOG(INFO) << "SendRequest status=" << status;
DINGO_LOG(INFO) << response.DebugString();
}
void SendUpdateAutoIncrement(std::shared_ptr<dingodb::CoordinatorInteraction> coordinator_interaction) {
dingodb::pb::meta::UpdateAutoIncrementRequest request;
dingodb::pb::meta::UpdateAutoIncrementResponse response;
auto* table_id = request.mutable_table_id();
table_id->set_entity_type(dingodb::pb::meta::EntityType::ENTITY_TYPE_TABLE);
if (FLAGS_id.empty()) {
DINGO_LOG(WARNING) << "id is empty";
return;
}
table_id->set_entity_id(std::stol(FLAGS_id));
request.set_start_id(FLAGS_incr_start_id);
request.set_force(FLAGS_force);
auto status = coordinator_interaction->SendRequest("UpdateAutoIncrement", request, response);
DINGO_LOG(INFO) << "SendRequest status=" << status;
DINGO_LOG(INFO) << response.DebugString();
}
void SendGenerateAutoIncrement(std::shared_ptr<dingodb::CoordinatorInteraction> coordinator_interaction) {
dingodb::pb::meta::GenerateAutoIncrementRequest request;
dingodb::pb::meta::GenerateAutoIncrementResponse response;
auto* table_id = request.mutable_table_id();
table_id->set_entity_type(dingodb::pb::meta::EntityType::ENTITY_TYPE_TABLE);
if (FLAGS_id.empty()) {
DINGO_LOG(WARNING) << "id is empty";
return;
}
table_id->set_entity_id(std::stol(FLAGS_id));
request.set_count(FLAGS_generate_count);
request.set_auto_increment_increment(FLAGS_auto_increment_increment);
request.set_auto_increment_offset(FLAGS_auto_increment_offset);
auto status = coordinator_interaction->SendRequest("GenerateAutoIncrement", request, response);
DINGO_LOG(INFO) << "SendRequest status=" << status;
DINGO_LOG(INFO) << response.DebugString();
}
void SendDeleteAutoIncrement(std::shared_ptr<dingodb::CoordinatorInteraction> coordinator_interaction) {
dingodb::pb::meta::DeleteAutoIncrementRequest request;
dingodb::pb::meta::DeleteAutoIncrementResponse response;
auto* table_id = request.mutable_table_id();
table_id->set_entity_type(dingodb::pb::meta::EntityType::ENTITY_TYPE_TABLE);
if (FLAGS_id.empty()) {
DINGO_LOG(WARNING) << "id is empty";
return;
}
table_id->set_entity_id(std::stol(FLAGS_id));
auto status = coordinator_interaction->SendRequest("DeleteAutoIncrement", request, response);
DINGO_LOG(INFO) << "SendRequest status=" << status;
DINGO_LOG(INFO) << response.DebugString();
}