YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/client/table_handle.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/client/table_handle.h"
15
16
#include "yb/client/client.h"
17
#include "yb/client/error.h"
18
#include "yb/client/schema.h"
19
#include "yb/client/session.h"
20
#include "yb/client/table.h"
21
#include "yb/client/table_creator.h"
22
#include "yb/client/yb_op.h"
23
24
#include "yb/common/partition.h"
25
#include "yb/common/ql_type.h"
26
#include "yb/common/schema.h"
27
28
#include "yb/master/master_client.pb.h"
29
30
#include "yb/util/format.h"
31
#include "yb/util/result.h"
32
#include "yb/util/status_format.h"
33
34
using namespace std::literals; // NOLINT
35
36
namespace yb {
37
namespace client {
38
39
Status TableHandle::Create(const YBTableName& table_name,
40
                           int num_tablets,
41
                           YBClient* client,
42
                           YBSchemaBuilder* builder,
43
8
                           IndexInfoPB* index_info) {
44
8
  YBSchema schema;
45
8
  RETURN_NOT_OK(builder->Build(&schema));
46
8
  return Create(table_name, num_tablets, schema, client, index_info);
47
8
}
48
49
Status TableHandle::Create(const YBTableName& table_name,
50
                           int num_tablets,
51
                           const YBSchema& schema,
52
                           YBClient* client,
53
49
                           IndexInfoPB* index_info) {
54
49
  std::unique_ptr<YBTableCreator> table_creator(client->NewTableCreator());
55
49
  table_creator->table_name(table_name)
56
49
      .schema(&schema)
57
49
      .num_tablets(num_tablets);
58
59
  // Setup Index properties.
60
49
  if (index_info) {
61
0
    table_creator->indexed_table_id(index_info->indexed_table_id())
62
0
        .is_local_index(index_info->is_local())
63
0
        .is_unique_index(index_info->is_unique())
64
0
        .mutable_index_info()->CopyFrom(*index_info);
65
0
  }
66
67
49
  RETURN_NOT_OK(table_creator->Create());
68
49
  return Open(table_name, client);
69
49
}
70
71
393
Status TableHandle::Open(const YBTableName& table_name, YBClient* client) {
72
393
  RETURN_NOT_OK(client->OpenTable(table_name, &table_));
73
74
393
  client_ = client;
75
393
  auto schema = table_->schema();
76
1.74k
  for (size_t i = 0; i < schema.num_columns(); ++i) {
77
1.34k
    yb::ColumnId col_id = yb::ColumnId(schema.ColumnId(i));
78
1.34k
    column_ids_.emplace(schema.Column(i).name(), col_id);
79
1.34k
    column_types_.emplace(col_id, schema.Column(i).type());
80
1.34k
  }
81
82
393
  return Status::OK();
83
393
}
84
85
0
Status TableHandle::Reopen() {
86
0
  return Open(name(), client_);
87
0
}
88
89
191
const YBTableName& TableHandle::name() const {
90
191
  return table_->name();
91
191
}
92
93
2.95M
const YBSchema& TableHandle::schema() const {
94
2.95M
  return table_->schema();
95
2.95M
}
96
97
22
std::vector<std::string> TableHandle::AllColumnNames() const {
98
22
  std::vector<std::string> result;
99
22
  result.reserve(table_->schema().columns().size());
100
72
  for (const auto& column : table_->schema().columns()) {
101
72
    result.push_back(column.name());
102
72
  }
103
22
  return result;
104
22
}
105
106
namespace {
107
108
template<class T>
109
1.67M
auto SetupRequest(const T& op, const YBSchema& schema) {
110
1.67M
  auto* req = op->mutable_request();
111
1.67M
  req->set_client(YQL_CLIENT_CQL);
112
1.67M
  req->set_request_id(0);
113
1.67M
  req->set_query_id(reinterpret_cast<int64_t>(op.get()));
114
1.67M
  req->set_schema_version(schema.version());
115
1.67M
  req->set_is_compatible_with_previous_version(schema.is_compatible_with_previous_version());
116
1.67M
  return req;
117
1.67M
}
table_handle.cc:_ZN2yb6client12_GLOBAL__N_112SetupRequestINSt3__110shared_ptrINS0_11YBqlWriteOpEEEEEDaRKT_RKNS0_8YBSchemaE
Line
Count
Source
109
1.67M
auto SetupRequest(const T& op, const YBSchema& schema) {
110
1.67M
  auto* req = op->mutable_request();
111
1.67M
  req->set_client(YQL_CLIENT_CQL);
112
1.67M
  req->set_request_id(0);
113
1.67M
  req->set_query_id(reinterpret_cast<int64_t>(op.get()));
114
1.67M
  req->set_schema_version(schema.version());
115
1.67M
  req->set_is_compatible_with_previous_version(schema.is_compatible_with_previous_version());
116
1.67M
  return req;
117
1.67M
}
table_handle.cc:_ZN2yb6client12_GLOBAL__N_112SetupRequestINSt3__110shared_ptrINS0_10YBqlReadOpEEEEEDaRKT_RKNS0_8YBSchemaE
Line
Count
Source
109
620
auto SetupRequest(const T& op, const YBSchema& schema) {
110
620
  auto* req = op->mutable_request();
111
620
  req->set_client(YQL_CLIENT_CQL);
112
620
  req->set_request_id(0);
113
620
  req->set_query_id(reinterpret_cast<int64_t>(op.get()));
114
620
  req->set_schema_version(schema.version());
115
620
  req->set_is_compatible_with_previous_version(schema.is_compatible_with_previous_version());
116
620
  return req;
117
620
}
118
119
} // namespace
120
121
1.67M
std::shared_ptr<YBqlWriteOp> TableHandle::NewWriteOp(QLWriteRequestPB::QLStmtType type) const {
122
1.67M
  auto op = std::make_shared<YBqlWriteOp>(table_);
123
1.67M
  auto* req = SetupRequest(op, table_->schema());
124
1.67M
  req->set_type(type);
125
1.67M
  return op;
126
1.67M
}
127
128
620
std::shared_ptr<YBqlReadOp> TableHandle::NewReadOp() const {
129
620
  std::shared_ptr<YBqlReadOp> op(table_->NewQLRead());
130
620
  SetupRequest(op, table_->schema());
131
620
  return op;
132
620
}
133
134
3.24M
QLValuePB* TableHandle::PrepareColumn(QLWriteRequestPB* req, const string& column_name) const {
135
3.24M
  return QLPrepareColumn(req, ColumnId(column_name));
136
3.24M
}
137
138
#define TABLE_HANDLE_TYPE_DEFINITIONS_IMPL(name, lname, type) \
139
void TableHandle::PP_CAT3(Add, name, ColumnValue)( \
140
3.24M
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
3.24M
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
3.24M
} \
_ZNK2yb6client11TableHandle18AddInt8ColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEa
Line
Count
Source
140
1.62k
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
1.62k
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
1.62k
} \
_ZNK2yb6client11TableHandle19AddInt16ColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEs
Line
Count
Source
140
1.62k
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
1.62k
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
1.62k
} \
_ZNK2yb6client11TableHandle19AddInt32ColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEi
Line
Count
Source
140
1.50M
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
1.50M
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
1.50M
} \
_ZNK2yb6client11TableHandle19AddInt64ColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEx
Line
Count
Source
140
171k
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
171k
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
171k
} \
_ZNK2yb6client11TableHandle20AddStringColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEESC_
Line
Count
Source
140
1.48M
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
1.48M
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
1.48M
} \
_ZNK2yb6client11TableHandle20AddBinaryColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEESC_
Line
Count
Source
140
1.62k
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
1.62k
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
1.62k
} \
_ZNK2yb6client11TableHandle18AddBoolColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEb
Line
Count
Source
140
86.4k
    QLWriteRequestPB* req, const std::string &column_name, type value) const { \
141
86.4k
  PrepareColumn(req, column_name)->PP_CAT3(set_, lname, _value)(value); \
142
86.4k
} \
Unexecuted instantiation: _ZNK2yb6client11TableHandle19AddFloatColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEf
Unexecuted instantiation: _ZNK2yb6client11TableHandle20AddDoubleColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEd
Unexecuted instantiation: _ZNK2yb6client11TableHandle19AddJsonbColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle23AddTimestampColumnValueEPNS_16QLWriteRequestPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEx
143
\
144
void TableHandle::PP_CAT3(Set, name, Condition)( \
145
    QLConditionPB* const condition, const string& column_name, const QLOperator op, \
146
1
    type value) const { \
147
1
  PrepareCondition(condition, column_name, op)->PP_CAT3(set_, lname, _value)(value); \
148
1
} \
Unexecuted instantiation: _ZNK2yb6client11TableHandle16SetInt8ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEa
Unexecuted instantiation: _ZNK2yb6client11TableHandle17SetInt16ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEs
_ZNK2yb6client11TableHandle17SetInt32ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEi
Line
Count
Source
146
1
    type value) const { \
147
1
  PrepareCondition(condition, column_name, op)->PP_CAT3(set_, lname, _value)(value); \
148
1
} \
Unexecuted instantiation: _ZNK2yb6client11TableHandle17SetInt64ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEx
Unexecuted instantiation: _ZNK2yb6client11TableHandle18SetStringConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle18SetBinaryConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle16SetBoolConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEb
Unexecuted instantiation: _ZNK2yb6client11TableHandle17SetFloatConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEf
Unexecuted instantiation: _ZNK2yb6client11TableHandle18SetDoubleConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEd
Unexecuted instantiation: _ZNK2yb6client11TableHandle17SetJsonbConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle21SetTimestampConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEx
149
\
150
void TableHandle::PP_CAT3(Add, name, Condition)( \
151
    QLConditionPB* const condition, const string& column_name, const QLOperator op, \
152
0
    type value) const { \
153
0
  PP_CAT3(Set, name, Condition)( \
154
0
    condition->add_operands()->mutable_condition(), column_name, op, value); \
155
0
} \
Unexecuted instantiation: _ZNK2yb6client11TableHandle16AddInt8ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEa
Unexecuted instantiation: _ZNK2yb6client11TableHandle17AddInt16ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEs
Unexecuted instantiation: _ZNK2yb6client11TableHandle17AddInt32ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEi
Unexecuted instantiation: _ZNK2yb6client11TableHandle17AddInt64ConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEx
Unexecuted instantiation: _ZNK2yb6client11TableHandle18AddStringConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle18AddBinaryConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle16AddBoolConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEb
Unexecuted instantiation: _ZNK2yb6client11TableHandle17AddFloatConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEf
Unexecuted instantiation: _ZNK2yb6client11TableHandle18AddDoubleConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEd
Unexecuted instantiation: _ZNK2yb6client11TableHandle17AddJsonbConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorESC_
Unexecuted instantiation: _ZNK2yb6client11TableHandle21AddTimestampConditionEPNS_13QLConditionPBERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS_10QLOperatorEx
156
157
#define TABLE_HANDLE_TYPE_DEFINITIONS(i, data, entry) TABLE_HANDLE_TYPE_DEFINITIONS_IMPL entry
158
159
BOOST_PP_SEQ_FOR_EACH(TABLE_HANDLE_TYPE_DEFINITIONS, ~, QL_PROTOCOL_TYPES);
160
161
0
void TableHandle::SetColumn(QLColumnValuePB* column_value, const string& column_name) const {
162
0
  column_value->set_column_id(ColumnId(column_name));
163
0
}
164
165
QLValuePB* TableHandle::PrepareCondition(
166
1
    QLConditionPB* const condition, const string& column_name, const QLOperator op) const {
167
1
  return QLPrepareCondition(condition, ColumnId(column_name), op);
168
1
}
169
170
0
void TableHandle::AddCondition(QLConditionPB* const condition, const QLOperator op) const {
171
0
  condition->add_operands()->mutable_condition()->set_op(op);
172
0
}
173
174
557
void TableHandle::AddColumns(const std::vector<std::string>& columns, QLReadRequestPB* req) const {
175
557
  QLRSRowDescPB* rsrow_desc = req->mutable_rsrow_desc();
176
1.24k
  for (const auto& column : columns) {
177
1.24k
    auto id = ColumnId(column);
178
1.24k
    req->add_selected_exprs()->set_column_id(id);
179
1.24k
    req->mutable_column_refs()->add_ids(id);
180
181
1.24k
    QLRSColDescPB* rscol_desc = rsrow_desc->add_rscol_descs();
182
1.24k
    rscol_desc->set_name(column);
183
1.24k
    ColumnType(column)->ToQLTypePB(rscol_desc->mutable_ql_type());
184
1.24k
  }
185
557
}
186
187
191
TableIteratorOptions::TableIteratorOptions() {}
188
189
191
TableIterator::TableIterator() : table_(nullptr) {}
190
191
#define REPORT_AND_RETURN_IF_NOT_OK(expr) \
192
1.38k
  do { \
193
1.38k
    auto&& status = (expr); \
194
1.38k
    if (!status.ok()) { HandleError(MoveStatus(status)); return; } \
195
1.38k
  } while (false) \
196
197
#define REPORT_AND_RETURN_FALSE_IF_NOT_OK(expr) \
198
  do { \
199
    auto&& status = (expr); \
200
    if (!status.ok()) { HandleError(MoveStatus(status)); return false; } \
201
  } while (false) \
202
203
TableIterator::TableIterator(const TableHandle* table, const TableIteratorOptions& options)
204
191
    : table_(table), error_handler_(options.error_handler) {
205
191
  auto client = table->client();
206
207
191
  session_ = client->NewSession();
208
209
191
  google::protobuf::RepeatedPtrField<master::TabletLocationsPB> tablets;
210
191
  REPORT_AND_RETURN_IF_NOT_OK(client->GetTablets(
211
191
      table->name(), /* max_tablets = */ 0, &tablets, /* partition_list_version =*/nullptr));
212
191
  if (tablets.size() == 0) {
213
0
    table_ = nullptr;
214
0
    return;
215
0
  }
216
191
  ops_.reserve(tablets.size());
217
191
  partition_key_ends_.reserve(tablets.size());
218
219
251
  for (const auto& tablet : tablets) {
220
251
    if (!options.tablet.empty() && options.tablet != tablet.tablet_id()) {
221
0
      continue;
222
0
    }
223
251
    auto op = table->NewReadOp();
224
251
    auto req = op->mutable_request();
225
251
    op->set_yb_consistency_level(options.consistency);
226
227
251
    const auto& key_start = tablet.partition().partition_key_start();
228
251
    if (!key_start.empty()) {
229
60
      req->set_hash_code(PartitionSchema::DecodeMultiColumnHashValue(key_start));
230
60
    }
231
232
251
    if (options.filter) {
233
0
      options.filter(*table_, req->mutable_where_expr()->mutable_condition());
234
251
    } else {
235
251
      req->set_return_paging_state(true);
236
251
      req->set_limit(128);
237
251
    }
238
251
    if (options.read_time) {
239
6
      op->SetReadTime(options.read_time);
240
6
    }
241
251
    table_->AddColumns(*options.columns, req);
242
251
    ops_.push_back(std::move(op));
243
251
    partition_key_ends_.push_back(tablet.partition().partition_key_end());
244
251
  }
245
246
191
  if (ExecuteOps()) {
247
191
    Move();
248
191
  }
249
191
}
250
251
191
bool TableIterator::ExecuteOps() {
252
191
  constexpr size_t kMaxConcurrentOps = 5;
253
191
  const size_t new_executed_ops = std::min(ops_.size(), executed_ops_ + kMaxConcurrentOps);
254
442
  for (size_t i = executed_ops_; i != new_executed_ops; ++i) {
255
251
    session_->Apply(ops_[i]);
256
251
  }
257
258
191
  if (!IsFlushStatusOkOrHandleErrors(session_->FlushAndGetOpsErrors())) {
259
0
    return false;
260
0
  }
261
262
442
  for (size_t i = executed_ops_; i != new_executed_ops; ++i) {
263
251
    const auto& op = ops_[i];
264
251
    if (QLResponsePB::YQL_STATUS_OK != op->response().status()) {
265
0
      HandleError(STATUS_FORMAT(RuntimeError, "Error for $0: $1", *op, op->response()));
266
0
    }
267
251
  }
268
269
191
  executed_ops_ = new_executed_ops;
270
191
  return true;
271
191
}
272
273
123k
bool TableIterator::Equals(const TableIterator& rhs) const {
274
123k
  return table_ == rhs.table_;
275
123k
}
276
277
122k
TableIterator& TableIterator::operator++() {
278
122k
  ++row_index_;
279
122k
  Move();
280
122k
  return *this;
281
122k
}
282
283
122k
const QLRow& TableIterator::operator*() const {
284
122k
  return current_block_->rows()[row_index_];
285
122k
}
286
287
123k
void TableIterator::Move() {
288
124k
  while (!current_block_ || row_index_ == current_block_->rows().size()) {
289
1.38k
    if (current_block_) {
290
1.19k
      if (paging_state_) {
291
940
        auto& op = ops_[ops_index_];
292
940
        *op->mutable_request()->mutable_paging_state() = *paging_state_;
293
940
        session_->Apply(op);
294
940
        if (!IsFlushStatusOkOrHandleErrors(session_->FlushAndGetOpsErrors())) {
295
0
          return;
296
0
        }
297
940
        if (QLResponsePB::YQL_STATUS_OK != op->response().status()) {
298
0
          HandleError(STATUS_FORMAT(RuntimeError, "Error for $0: $1", *op, op->response()));
299
0
        }
300
251
      } else {
301
251
        ++ops_index_;
302
251
        if (ops_index_ >= executed_ops_ && executed_ops_ < ops_.size()) {
303
0
          if (!ExecuteOps()) {
304
            // Error occurred. exit out early.
305
0
            return;
306
0
          }
307
1.38k
        }
308
251
      }
309
1.19k
    }
310
1.38k
    if (ops_index_ == ops_.size()) {
311
191
      table_ = nullptr;
312
191
      return;
313
191
    }
314
1.19k
    auto& op = *ops_[ops_index_];
315
1.19k
    auto next_block = op.MakeRowBlock();
316
1.19k
    REPORT_AND_RETURN_IF_NOT_OK(next_block);
317
1.19k
    current_block_ = std::move(*next_block);
318
1.00k
    paging_state_ = op.response().has_paging_state() ? &op.response().paging_state() : nullptr;
319
1.19k
    if (ops_index_ < partition_key_ends_.size() - 1 && paging_state_ &&
320
687
        paging_state_->next_partition_key() >= partition_key_ends_[ops_index_]) {
321
60
      paging_state_ = nullptr;
322
60
    }
323
1.19k
    row_index_ = 0;
324
325
0
    VLOG(4) << "New block: " << yb::ToString(current_block_->rows())
326
0
            << ", paging: " << yb::ToString(paging_state_);
327
1.19k
  }
328
123k
}
329
330
1.13k
bool TableIterator::IsFlushStatusOkOrHandleErrors(FlushStatus flush_status) {
331
1.13k
  if (flush_status.status.ok()) {
332
1.13k
    return true;
333
1.13k
  }
334
0
  HandleError(flush_status.status);
335
0
  if (!error_handler_) {
336
0
    for (const auto& error : flush_status.errors) {
337
0
      LOG(ERROR) << "Failed operation: " << error->failed_op().ToString()
338
0
                 << ", status: " << error->status();
339
0
    }
340
0
  }
341
0
  return false;
342
0
}
343
344
0
void TableIterator::HandleError(const Status& status) {
345
0
  if (error_handler_) {
346
0
    error_handler_(status);
347
0
  } else {
348
0
    LOG(FATAL) << "Failed: " << status;
349
0
  }
350
  // Makes this iterator == end().
351
0
  table_ = nullptr;
352
0
}
353
354
template <>
355
void FilterBetweenImpl<int32_t>::operator()(
356
0
    const TableHandle& table, QLConditionPB* condition) const {
357
0
  condition->set_op(QL_OP_AND);
358
0
  table.AddInt32Condition(
359
0
      condition, column_, lower_inclusive_ ? QL_OP_GREATER_THAN_EQUAL : QL_OP_GREATER_THAN,
360
0
      lower_bound_);
361
0
  table.AddInt32Condition(
362
0
      condition, column_, upper_inclusive_ ? QL_OP_LESS_THAN_EQUAL : QL_OP_LESS_THAN, upper_bound_);
363
0
}
364
365
template <>
366
void FilterBetweenImpl<std::string>::operator()(
367
0
    const TableHandle& table, QLConditionPB* condition) const {
368
0
  condition->set_op(QL_OP_AND);
369
0
  table.AddStringCondition(
370
0
      condition, column_, lower_inclusive_ ? QL_OP_GREATER_THAN_EQUAL : QL_OP_GREATER_THAN,
371
0
      lower_bound_);
372
0
  table.AddStringCondition(
373
0
      condition, column_, upper_inclusive_ ? QL_OP_LESS_THAN_EQUAL : QL_OP_LESS_THAN, upper_bound_);
374
0
}
375
376
0
void FilterGreater::operator()(const TableHandle& table, QLConditionPB* condition) const {
377
0
  table.SetInt32Condition(
378
0
      condition, column_, inclusive_ ? QL_OP_GREATER_THAN_EQUAL : QL_OP_GREATER_THAN, bound_);
379
0
}
380
381
0
void FilterLess::operator()(const TableHandle& table, QLConditionPB* condition) const {
382
0
  table.SetInt32Condition(
383
0
      condition, column_, inclusive_ ? QL_OP_LESS_THAN_EQUAL : QL_OP_LESS_THAN, bound_);
384
0
}
385
386
template <>
387
void FilterEqualImpl<std::string>::operator()(
388
0
    const TableHandle& table, QLConditionPB* condition) const {
389
0
  table.SetBinaryCondition(condition, column_, QL_OP_EQUAL, t_);
390
0
}
391
392
} // namespace client
393
} // namespace yb