MCPcopy Create free account
hub / github.com/baidu/tera / UpdateTable

Method UpdateTable

src/sdk/client_impl.cc:282–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282bool ClientImpl::UpdateTable(const TableDescriptor& desc, ErrorCode* err) {
283 if (!IsTableExist(desc.TableName(), err)) {
284 LOG(ERROR) << "table not exist: " << desc.TableName();
285 return false;
286 }
287
288 master::MasterClient master_client(cluster_->MasterAddr());
289
290 UpdateTableRequest request;
291 UpdateTableResponse response;
292 request.set_sequence_id(g_sequence_id++);
293 request.set_table_name(desc.TableName());
294 request.set_user_token(
295 GetUserToken(client_options_.user_identity, client_options_.user_passcode));
296
297 access_builder_->BuildRequest(&request);
298
299 TableSchema* schema = request.mutable_schema();
300 TableDescToSchema(desc, schema);
301
302 ErrorCode err2;
303 TableDescriptor* old_desc = GetTableDescriptor(desc.TableName(), &err2);
304 if (old_desc == NULL) {
305 return false;
306 }
307 TableSchema old_schema;
308 TableDescToSchema(*old_desc, &old_schema);
309 delete old_desc;
310
311 // if try to update lg, need to disable table
312 bool is_update_lg = IsSchemaLgDiff(*schema, old_schema);
313 bool is_update_cf = IsSchemaCfDiff(*schema, old_schema);
314
315 // compatible for old-master which no support for online-schema-update
316 if (!FLAGS_tera_online_schema_update_enabled && IsTableEnabled(desc.TableName(), err) &&
317 (is_update_lg || is_update_cf)) {
318 err->SetFailed(ErrorCode::kBadParam,
319 "disable this table if you want to update (Lg | Cf) property(ies)");
320 return false;
321 }
322
323 string reason;
324 if (master_client.UpdateTable(&request, &response)) {
325 if (CheckReturnValue(response.status(), reason, err)) {
326 return true;
327 }
328 LOG(ERROR) << reason << "| status: " << StatusCodeToString(response.status());
329 } else {
330 reason = "rpc fail to update table:" + desc.TableName();
331 LOG(ERROR) << reason;
332 err->SetFailed(ErrorCode::kSystem, reason);
333 }
334 return false;
335}
336
337bool ClientImpl::UpdateCheck(const std::string& table_name, bool* done, ErrorCode* err) {
338 master::MasterClient master_client(cluster_->MasterAddr());

Callers 1

UpdateOpFunction · 0.45

Calls 9

TableDescToSchemaFunction · 0.85
IsSchemaLgDiffFunction · 0.85
IsSchemaCfDiffFunction · 0.85
StatusCodeToStringFunction · 0.85
MasterAddrMethod · 0.80
BuildRequestMethod · 0.80
SetFailedMethod · 0.80
TableNameMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected