| 548 | } |
| 549 | |
| 550 | bool ScannerImpl::TryLockRow(const std::string& table_name, const std::string& row) const { |
| 551 | VLOG(12) << "[time] trylock wait " << table_name << " " << row; |
| 552 | |
| 553 | RowlockRequest request; |
| 554 | RowlockResponse response; |
| 555 | |
| 556 | std::shared_ptr<RowlockClient> rowlock_client; |
| 557 | |
| 558 | if (FLAGS_mock_rowlock_enable == true) { |
| 559 | rowlock_client.reset(new FakeRowlockClient()); |
| 560 | } else { |
| 561 | rowlock_client.reset(new RowlockClient()); |
| 562 | } |
| 563 | |
| 564 | request.set_table_name(table_name); |
| 565 | request.set_row(row); |
| 566 | |
| 567 | VLOG(12) << "[time] trylock " << table_name << " " << row; |
| 568 | if (!rowlock_client->TryLock(&request, &response)) { |
| 569 | LOG(ERROR) << "TryLock rpc fail, row: " << row; |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | if (response.lock_status() != kLockSucc) { |
| 574 | LOG(INFO) << "Lock row fail, row: " << request.row(); |
| 575 | return false; |
| 576 | } |
| 577 | VLOG(12) << "[time] lock success " << request.table_name() << " " << request.row(); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 581 | |
| 582 | bool ScannerImpl::CheckTransactionTypeLegalForTable(TransactionType transaction_type, |
| 583 | TransactionType table_type) { |