YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/cql/cqlserver/cql_statement.h
Line
Count
Source
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//
15
// This class defines a CQL statement. A CQL statement extends from a SQL statement to handle query
16
// ID and caching prepared statements in a list.
17
//--------------------------------------------------------------------------------------------------
18
19
#ifndef YB_YQL_CQL_CQLSERVER_CQL_STATEMENT_H_
20
#define YB_YQL_CQL_CQLSERVER_CQL_STATEMENT_H_
21
22
#include <list>
23
24
#include "yb/yql/cql/ql/statement.h"
25
#include "yb/yql/cql/ql/util/cql_message.h"
26
27
namespace yb {
28
namespace cqlserver {
29
30
class CQLStatement;
31
32
// A map of CQL query id to the prepared statement for caching the prepared statments. Shared_ptr
33
// is used so that a prepared statement can be aged out and removed from the cache without deleting
34
// it when it is being executed by another client in another thread.
35
using CQLStatementMap = std::unordered_map<ql::CQLMessage::QueryId, std::shared_ptr<CQLStatement>>;
36
37
// A LRU list of CQL statements and position in the list.
38
using CQLStatementList = std::list<std::shared_ptr<CQLStatement>>;
39
using CQLStatementListPos = CQLStatementList::iterator;
40
41
// A CQL statement that is prepared and cached.
42
class CQLStatement : public ql::Statement {
43
 public:
44
  CQLStatement(const std::string& keyspace, const std::string& query, CQLStatementListPos pos);
45
  ~CQLStatement();
46
47
  // Return the query id.
48
2.58k
  ql::CQLMessage::QueryId query_id() const { return GetQueryId(keyspace_, text_); }
49
50
  // Get/set position of the statement in the LRU.
51
4.77M
  CQLStatementListPos pos() const { return pos_; }
52
2.19k
  void set_pos(CQLStatementListPos pos) const { pos_ = pos; }
53
54
  // Return the query id of a statement.
55
  static ql::CQLMessage::QueryId GetQueryId(const std::string& keyspace, const std::string& query);
56
57
 private:
58
  // Position of the statement in the LRU.
59
  mutable CQLStatementListPos pos_;
60
};
61
62
}  // namespace cqlserver
63
}  // namespace yb
64
65
#endif  // YB_YQL_CQL_CQLSERVER_CQL_STATEMENT_H_