YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/abstract_tablet.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/tablet/abstract_tablet.h"
15
16
#include "yb/common/ql_resultset.h"
17
#include "yb/common/ql_value.h"
18
#include "yb/common/schema.h"
19
20
#include "yb/docdb/cql_operation.h"
21
#include "yb/docdb/pgsql_operation.h"
22
23
#include "yb/tablet/read_result.h"
24
25
#include "yb/util/trace.h"
26
27
namespace yb {
28
namespace tablet {
29
30
Result<HybridTime> AbstractTablet::SafeTime(RequireLease require_lease,
31
                                            HybridTime min_allowed,
32
5.15M
                                            CoarseTimePoint deadline) const {
33
5.15M
  return DoGetSafeTime(require_lease, min_allowed, deadline);
34
5.15M
}
35
36
Status AbstractTablet::HandleQLReadRequest(CoarseTimePoint deadline,
37
                                           const ReadHybridTime& read_time,
38
                                           const QLReadRequestPB& ql_read_request,
39
                                           const TransactionOperationContext& txn_op_context,
40
3.93M
                                           QLReadRequestResult* result) {
41
42
  // TODO(Robert): verify that all key column values are provided
43
3.93M
  docdb::QLReadOperation doc_op(ql_read_request, txn_op_context);
44
45
  // Form a schema of columns that are referenced by this query.
46
3.93M
  const SchemaPtr schema = GetSchema();
47
3.93M
  Schema projection;
48
3.93M
  const QLReferencedColumnsPB& column_pbs = ql_read_request.column_refs();
49
3.93M
  vector<ColumnId> column_refs;
50
427
  for (int32_t id : column_pbs.static_ids()) {
51
427
    column_refs.emplace_back(id);
52
427
  }
53
13.2M
  for (int32_t id : column_pbs.ids()) {
54
13.2M
    column_refs.emplace_back(id);
55
13.2M
  }
56
3.93M
  RETURN_NOT_OK(schema->CreateProjectionByIdsIgnoreMissing(column_refs, &projection));
57
58
3.93M
  const QLRSRowDesc rsrow_desc(ql_read_request.rsrow_desc());
59
3.93M
  QLResultSet resultset(&rsrow_desc, &result->rows_data);
60
3.93M
  TRACE("Start Execute");
61
3.93M
  const Status s = doc_op.Execute(
62
3.93M
      QLStorage(), deadline, read_time, *schema, projection, &resultset, &result->restart_read_ht);
63
3.93M
  TRACE("Done Execute");
64
3.93M
  if (!s.ok()) {
65
2
    if (s.IsQLError()) {
66
2
      result->response.set_status(QLResponsePB::YQL_STATUS_USAGE_ERROR);
67
0
    } else {
68
0
      result->response.set_status(QLResponsePB::YQL_STATUS_RUNTIME_ERROR);
69
0
    }
70
2
    result->response.set_error_message(s.message().cdata(), s.message().size());
71
2
    return Status::OK();
72
2
  }
73
3.93M
  result->response.Swap(&doc_op.response());
74
75
3.93M
  RETURN_NOT_OK(CreatePagingStateForRead(
76
3.93M
      ql_read_request, resultset.rsrow_count(), &result->response));
77
78
3.93M
  result->response.set_status(QLResponsePB::YQL_STATUS_OK);
79
3.93M
  return Status::OK();
80
3.93M
}
81
82
Status AbstractTablet::HandlePgsqlReadRequest(CoarseTimePoint deadline,
83
                                              const ReadHybridTime& read_time,
84
                                              bool is_explicit_request_read_time,
85
                                              const PgsqlReadRequestPB& pgsql_read_request,
86
                                              const TransactionOperationContext& txn_op_context,
87
                                              PgsqlReadRequestResult* result,
88
1.50M
                                              size_t* num_rows_read) {
89
90
1.50M
  docdb::PgsqlReadOperation doc_op(pgsql_read_request, txn_op_context);
91
92
  // Form a schema of columns that are referenced by this query.
93
1.50M
  const SchemaPtr schema = GetSchema(pgsql_read_request.table_id());
94
1.50M
  const SchemaPtr index_schema = pgsql_read_request.has_index_request()
95
1.34M
      ? GetSchema(pgsql_read_request.index_request().table_id()) : nullptr;
96
97
1.50M
  TRACE("Start Execute");
98
1.50M
  auto fetched_rows = doc_op.Execute(
99
1.50M
      QLStorage(), deadline, read_time, is_explicit_request_read_time, *schema, index_schema.get(),
100
1.50M
      &result->rows_data, &result->restart_read_ht);
101
1.50M
  TRACE("Done Execute");
102
1.50M
  if (!fetched_rows.ok()) {
103
0
    result->response.set_status(PgsqlResponsePB::PGSQL_STATUS_RUNTIME_ERROR);
104
0
    const auto& s = fetched_rows.status();
105
0
    result->response.set_error_message(s.message().cdata(), s.message().size());
106
0
    return Status::OK();
107
0
  }
108
1.50M
  result->response.Swap(&doc_op.response());
109
110
1.50M
  if (num_rows_read) {
111
1.49M
    *num_rows_read = *fetched_rows;
112
1.49M
  }
113
114
1.50M
  RETURN_NOT_OK(CreatePagingStateForRead(
115
1.50M
      pgsql_read_request, *fetched_rows, &result->response));
116
117
  // TODO(neil) The clients' request should indicate what encoding method should be used. When
118
  // multi-shard is used to process more complicated queries, proxy-server might prefer a different
119
  // encoding. For now, we'll call PgsqlSerialize() without checking encoding method.
120
1.50M
  result->response.set_status(PgsqlResponsePB::PGSQL_STATUS_OK);
121
122
  // Serializing data for PgGate API.
123
1.77k
  CHECK(!pgsql_read_request.has_rsrow_desc()) << "Row description is not needed";
124
1.50M
  TRACE("Done Handle");
125
126
1.50M
  return Status::OK();
127
1.50M
}
128
129
}  // namespace tablet
130
}  // namespace yb