ob_table_execute_processor.cpp 20.6 KB
Newer Older
X
xj0 已提交
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
/**
 * Copyright (c) 2021 OceanBase
 * OceanBase CE is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#define USING_LOG_PREFIX SERVER
#include "ob_table_execute_processor.h"
#include "ob_table_rpc_processor_util.h"
#include "observer/ob_service.h"
#include "storage/ob_partition_service.h"
#include "ob_table_end_trans_cb.h"
#include "sql/optimizer/ob_table_location.h"  // ObTableLocation
#include "lib/stat/ob_session_stat.h"

using namespace oceanbase::observer;
using namespace oceanbase::common;
using namespace oceanbase::table;
using namespace oceanbase::share;
using namespace oceanbase::sql;

int ObTableRpcProcessorUtil::negate_htable_timestamp(table::ObITableEntity &entity)
{
  int ret = OB_SUCCESS;
  // negative the value of T
  ObObj T_val;
  int64_t val = 0;
  if (3 == entity.get_rowkey_size()) {
    if (OB_FAIL(entity.get_rowkey_value(2, T_val))) {
      LOG_WARN("failed to get T from entity", K(ret), K(entity));
    } else if (OB_FAIL(T_val.get_int(val))) {
      LOG_WARN("invalid obj type for T", K(ret), K(T_val));
    } else {
      T_val.set_int(-val);
      if (OB_FAIL(entity.set_rowkey_value(2, T_val))) {
        LOG_WARN("failed to negate T value", K(ret));
      } else {
        LOG_DEBUG("[yzfdebug] nenative T value", K(ret), K(T_val));
      }
    }
  }
  return ret;
}

////////////////////////////////////////////////////////////////
ObTableApiExecuteP::ObTableApiExecuteP(const ObGlobalContext &gctx)
    :ObTableRpcProcessor(gctx),
     allocator_(ObModIds::TABLE_PROC),
     get_ctx_(allocator_),
     need_rollback_trans_(false),
     query_timeout_ts_(0)
{
}

int ObTableApiExecuteP::deserialize()
{
  // we should set entity before deserialize
  arg_.table_operation_.set_entity(request_entity_);
  result_.set_entity(result_entity_);
  int ret = ParentType::deserialize();
X
xj0 已提交
67 68 69 70
  if (OB_SUCC(ret) && ObTableEntityType::ET_HKV == arg_.entity_type_) {
    // @note modify the timestamp to be negative
    ret = ObTableRpcProcessorUtil::negate_htable_timestamp(request_entity_);
  }
X
xj0 已提交
71 72 73 74 75 76
  return ret;
}

int ObTableApiExecuteP::check_arg()
{
  int ret = OB_SUCCESS;
X
xj0 已提交
77 78
  if (!(arg_.consistency_level_ == ObTableConsistencyLevel::STRONG ||
      arg_.consistency_level_ == ObTableConsistencyLevel::EVENTUAL)) {
X
xj0 已提交
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
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("some options not supported yet", K(ret),
             "consistency_level", arg_.consistency_level_,
             "operation_type", arg_.table_operation_.type());
  }
  return ret;
}

int ObTableApiExecuteP::check_arg2() const
{
  int ret = OB_SUCCESS;
  if (arg_.returning_rowkey_
      || arg_.returning_affected_entity_) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("some options not supported yet", K(ret),
             "returning_rowkey", arg_.returning_rowkey_,
             "returning_affected_entity", arg_.returning_affected_entity_,
             "operation_type", arg_.table_operation_.type());
  }
  return ret;
}

int ObTableApiExecuteP::process()
{
  int ret = OB_SUCCESS;
  ret = ParentType::process();
  int tmp_ret = revert_get_ctx();
  if (OB_SUCCESS != tmp_ret) {
    LOG_WARN("fail to revert get ctx", K(tmp_ret));
  }
  return ret;
}

int ObTableApiExecuteP::try_process()
{
  int ret = OB_SUCCESS;
115 116
  uint64_t table_id = arg_.table_id_;
  bool is_index_supported = true;
X
xj0 已提交
117
  const ObTableOperation &table_operation = arg_.table_operation_;
118 119 120 121 122 123 124 125 126 127
  if (ObTableOperationType::GET != table_operation.type()) {
    if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
      LOG_WARN("failed to get table id", K(ret));
    } else if (OB_FAIL(check_table_index_supported(table_id, is_index_supported))) {
      LOG_WARN("fail to check index supported", K(ret), K(table_id));
    }
  }
  
  if (OB_FAIL(ret)) {
    // do nothing
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  } else if (OB_UNLIKELY(!is_index_supported)) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("index type is not supported by table api", K(ret));
  } else {
    switch (table_operation.type()) {
      case ObTableOperationType::INSERT:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_INSERT;
        ret = process_insert();
        break;
      case ObTableOperationType::GET:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_GET;
        ret = process_get();
        break;
      case ObTableOperationType::DEL:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_DELETE;
        ret = process_del();
        break;
      case ObTableOperationType::UPDATE:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_UPDATE;
        ret = process_update();
        break;
      case ObTableOperationType::INSERT_OR_UPDATE:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_INSERT_OR_UPDATE;
        ret = process_insert_or_update();
        break;
      case ObTableOperationType::REPLACE:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_REPLACE;
        ret = process_replace();
        break;
      case ObTableOperationType::INCREMENT:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_INCREMENT;
        ret = process_increment();
        break;
      case ObTableOperationType::APPEND:
        stat_event_type_ = ObTableProccessType::TABLE_API_SINGLE_APPEND;
        // for both increment and append
        ret = process_increment();
        break;
      default:
        ret = OB_INVALID_ARGUMENT;
        LOG_WARN("invalid table operation type", K(ret), K(table_operation));
        break;
    }
    audit_row_count_ = 1;
X
xj0 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
  }

#ifndef NDEBUG
  // debug mode
  LOG_INFO("[TABLE] execute operation", K(ret), K_(arg), K_(result), "timeout", rpc_pkt_->get_timeout(), K_(retry_count));
#else
  // release mode
  LOG_TRACE("[TABLE] execute operation", K(ret), K_(arg), K_(result),
            "timeout", rpc_pkt_->get_timeout(), "receive_ts", get_receive_timestamp(), K_(retry_count));
#endif
  return ret;
}

int ObTableApiExecuteP::revert_get_ctx()
{
  int ret = OB_SUCCESS;
  if (ObTableOperationType::GET == arg_.table_operation_.type()) {
    if (NULL != get_ctx_.scan_result_) {
      part_service_->revert_scan_iter(get_ctx_.scan_result_);
      get_ctx_.scan_result_ = NULL;
    }
    if (query_timeout_ts_ <= 0) {
      // for robust purpose
      query_timeout_ts_ = ObTimeUtility::current_time() + 1000000;
    }
    if (OB_FAIL(end_trans(need_rollback_trans_, req_, query_timeout_ts_))) {
      LOG_WARN("failed to end trans", K(ret));
    }
  }
  return ret;
}

void ObTableApiExecuteP::audit_on_finish()
{
  audit_record_.consistency_level_ = ObTableConsistencyLevel::STRONG == arg_.consistency_level_ ?
      ObConsistencyLevel::STRONG : ObConsistencyLevel::WEAK;
  audit_record_.return_rows_ = arg_.returning_affected_rows_ ? 1 : 0;
  audit_record_.table_scan_ = false;
  audit_record_.affected_rows_ = result_.get_affected_rows();
  audit_record_.try_cnt_ = retry_count_ + 1;
}

uint64_t ObTableApiExecuteP::get_request_checksum()
{
  uint64_t checksum = 0;
  checksum = ob_crc64(checksum, arg_.table_name_.ptr(), arg_.table_name_.length());
  checksum = ob_crc64(checksum, &arg_.consistency_level_, sizeof(arg_.consistency_level_));
  checksum = ob_crc64(checksum, &arg_.returning_rowkey_, sizeof(arg_.returning_rowkey_));
  checksum = ob_crc64(checksum, &arg_.returning_affected_entity_, sizeof(arg_.returning_affected_entity_));
  checksum = ob_crc64(checksum, &arg_.returning_affected_rows_, sizeof(arg_.returning_affected_rows_));
  checksum = ob_crc64(checksum, &arg_.binlog_row_image_type_, sizeof(arg_.binlog_row_image_type_));
  const uint64_t op_checksum = arg_.table_operation_.get_checksum();
  checksum = ob_crc64(checksum, &op_checksum, sizeof(op_checksum));
  return checksum;
}

int ObTableApiExecuteP::response(const int retcode)
{
  int ret = OB_SUCCESS;
  if (!need_retry_in_queue_ && !did_async_end_trans()) {
X
xj0 已提交
232 233 234 235 236 237 238
    if (OB_SUCC(ret) && ObTableEntityType::ET_HKV == arg_.entity_type_) {
      // @note modify the value of timestamp to be positive
      ret = ObTableRpcProcessorUtil::negate_htable_timestamp(result_entity_);
    }
    if (OB_SUCC(ret)) {
      ret = ObRpcProcessor::response(retcode);
    }
X
xj0 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
  }
  return ret;
}

void ObTableApiExecuteP::reset_ctx()
{
  (void)revert_get_ctx();
  get_ctx_.reset_dml();
  ObTableApiProcessorBase::reset_ctx();
  need_rollback_trans_ = false;
  need_retry_in_queue_ = false;
}

int ObTableApiExecuteP::get_partition_id(uint64_t table_id, const ObRowkey &rowkey, uint64_t &partition_id)
{
  int ret = OB_SUCCESS;
  partition_id = arg_.partition_id_;
  if (OB_INVALID_ID == partition_id) {
    ObSEArray<ObRowkey, 1> rowkeys;
    ObSEArray<int64_t, 1> part_ids;
    ObSEArray<sql::RowkeyArray, 1> rowkeys_per_part;
    if (OB_FAIL(rowkeys.push_back(rowkey))) {
      LOG_WARN("failed to push back", K(ret));
    } else if (OB_FAIL(get_partition_by_rowkey(table_id, rowkeys, part_ids, rowkeys_per_part))) {
      LOG_WARN("failed to get partition", K(ret), K(table_id), K(rowkeys));
    } else if (1 != part_ids.count()) {
      ret = OB_ERR_UNEXPECTED;
      LOG_ERROR("should have one partition", K(ret));
    } else {
      partition_id = part_ids.at(0);
    }
  }
  return ret;
}

////////////////////////////////////////////////////////////////
// get
int ObTableApiExecuteP::process_get()
{
  int ret = OB_SUCCESS;
  need_rollback_trans_ = false;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
281
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
282 283 284 285
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_);
  const bool is_readonly = true;
X
xj0 已提交
286
  const ObTableConsistencyLevel consistency_level = arg_.consistency_level_;
X
xj0 已提交
287 288 289 290 291 292 293 294 295
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(check_arg2())) {
  } else if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
X
xj0 已提交
296
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_SELECT, consistency_level, table_id, part_ids, get_timeout_ts()))) {
X
xj0 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    LOG_WARN("failed to start readonly transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_get(get_ctx_, arg_.table_operation_, result_))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to execute get", K(ret), K(table_id));
    }
  } else {}
  // end trans in after_process()
  need_rollback_trans_ = (OB_SUCCESS != ret);
  return ret;
}

////////////////////////////////////////////////////////////////
// insert_or_update
ObTableAPITransCb *ObTableApiExecuteP::new_callback(rpc::ObRequest *req)
{
  ObTableExecuteEndTransCb *cb = OB_NEW(ObTableExecuteEndTransCb, ObModIds::TABLE_PROC, req, arg_.table_operation_.type());
  if (NULL != cb) {
    // @todo optimize to avoid this copy
    int ret = OB_SUCCESS;
    if (OB_FAIL(cb->assign_execute_result(result_))) {
      LOG_WARN("failed to assign result", K(ret));
      cb->~ObTableExecuteEndTransCb();
      cb = NULL;
    } else {
      LOG_DEBUG("yzfdebug copy result", K_(result));
    }
  }
  return cb;
}

int ObTableApiExecuteP::process_insert_or_update()
{
  int ret = OB_SUCCESS;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
331
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_);

  const bool is_readonly = false;
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(check_arg2())) {
  } else if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_INSERT, table_id, part_ids, get_timeout_ts()))) {
    LOG_WARN("failed to start transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_insert_or_update(get_ctx_, arg_.table_operation_, result_))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to insert_or_update", K(ret), K(table_id));
    }
  }
  int tmp_ret = ret;
  if (OB_FAIL(end_trans(OB_SUCCESS != ret, req_, get_timeout_ts()))) {
    LOG_WARN("failed to end trans", K(ret));
  }
  ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
  return ret;
}

int ObTableApiExecuteP::process_del()
{
  int ret = OB_SUCCESS;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
365
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_);
  const bool is_readonly = false;
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(check_arg2())) {
  } else if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_DELETE, table_id, part_ids, get_timeout_ts()))) {
    LOG_WARN("failed to start transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_delete(get_ctx_, arg_.table_operation_, result_))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to delete", K(ret), K(table_id));
    }
  }
  int tmp_ret = ret;
  if (OB_FAIL(end_trans(OB_SUCCESS != ret, req_, get_timeout_ts()))) {
    LOG_WARN("failed to end trans", K(ret));
  }
  ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
  return ret;
}

int ObTableApiExecuteP::process_replace()
{
  int ret = OB_SUCCESS;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
398
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_);
  const bool is_readonly = false;
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(check_arg2())) {
  } else if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_REPLACE, table_id, part_ids, get_timeout_ts()))) {
    LOG_WARN("failed to start transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_replace(get_ctx_, arg_.table_operation_, result_))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to replace", K(ret), K(table_id));
    }
  }
  int tmp_ret = ret;
  if (OB_FAIL(end_trans(OB_SUCCESS != ret, req_, get_timeout_ts()))) {
    LOG_WARN("failed to end trans", K(ret));
  }
  ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
  return ret;
}

int ObTableApiExecuteP::process_insert()
{
  int ret = OB_SUCCESS;
  ObNewRowIterator *duplicate_row_iter = nullptr;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
432
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_);

  const bool is_readonly = false;
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(check_arg2())) {
  } else if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_INSERT, table_id, part_ids, get_timeout_ts()))) {
    LOG_WARN("failed to start transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_insert(get_ctx_,
      arg_.table_operation_, result_, duplicate_row_iter))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to insert", K(ret), K(table_id));
    }
  }
  int tmp_ret = ret;
  const bool did_rollback = (OB_SUCCESS != ret || OB_SUCCESS != result_.get_errno());
  if (OB_FAIL(end_trans(did_rollback, req_, get_timeout_ts()))) {
    LOG_WARN("failed to end trans", K(ret));
  }
  ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
  return ret;
}

int ObTableApiExecuteP::process_update()
{
  int ret = OB_SUCCESS;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
468
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_);
  const bool is_readonly = false;
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(check_arg2())) {
  } else if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_UPDATE, table_id, part_ids, get_timeout_ts()))) {
    LOG_WARN("failed to start transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_update(get_ctx_, arg_.table_operation_, nullptr, result_))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to update", K(ret), K(table_id));
    }
  }
  int tmp_ret = ret;
  if (OB_FAIL(end_trans(OB_SUCCESS != ret, req_, get_timeout_ts()))) {
    LOG_WARN("failed to end trans", K(ret));
  }
  ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
  return ret;
}

int ObTableApiExecuteP::process_increment()
{
  int ret = OB_SUCCESS;
  uint64_t &table_id = get_ctx_.param_table_id();
O
obdev 已提交
501
  get_ctx_.init_param(get_timeout_ts(), this->get_trans_desc(), &allocator_,
X
xj0 已提交
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
                      arg_.returning_affected_rows_,
                      arg_.entity_type_,
                      arg_.binlog_row_image_type_,
                      arg_.returning_affected_entity_,
                      arg_.returning_rowkey_);
  const bool is_readonly = false;
  ObRowkey rowkey = const_cast<ObITableEntity&>(arg_.table_operation_.entity()).get_rowkey();
  ObSEArray<int64_t, 1> part_ids;
  if (OB_FAIL(get_table_id(arg_.table_name_, arg_.table_id_, table_id))) {
    LOG_WARN("failed to get table id", K(ret), K(table_id));
  } else if (OB_FAIL(get_partition_id(table_id, rowkey, get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to get partition id", K(ret));
  } else if (OB_FAIL(part_ids.push_back(get_ctx_.param_partition_id()))) {
    LOG_WARN("failed to push back", K(ret));
  } else if (OB_FAIL(start_trans(is_readonly, sql::stmt::T_UPDATE, table_id, part_ids, get_timeout_ts()))) {
    LOG_WARN("failed to start transaction", K(ret));
  } else if (OB_FAIL(table_service_->execute_increment(get_ctx_, arg_.table_operation_, result_))) {
    if (OB_TRY_LOCK_ROW_CONFLICT != ret) {
      LOG_WARN("failed to update", K(ret), K(table_id));
    }
  }
  int tmp_ret = ret;
  if (OB_FAIL(end_trans(OB_SUCCESS != ret, req_, get_timeout_ts()))) {
    LOG_WARN("failed to end trans", K(ret));
  }
  ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
  return ret;
}