YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/master/master_service_base.h
Line
Count
Source
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
#ifndef YB_MASTER_MASTER_SERVICE_BASE_H
15
#define YB_MASTER_MASTER_SERVICE_BASE_H
16
17
#include "yb/gutil/macros.h"
18
#include "yb/util/strongly_typed_bool.h"
19
20
namespace yb {
21
class Status;
22
23
namespace rpc {
24
class RpcContext;
25
} // namespace rpc
26
27
namespace master {
28
29
class Master;
30
class CatalogManager;
31
class FlushManager;
32
class PermissionsManager;
33
class EncryptionManager;
34
35
// Tells HandleIn/HandleOnLeader to either acquire the lock briefly to check leadership (kFalse)
36
// or to hold it throughout the handler invocation (kTrue).
37
YB_STRONGLY_TYPED_BOOL(HoldCatalogLock);
38
39
// Base class for any master service with a few helpers.
40
class MasterServiceBase {
41
 public:
42
72.3k
  explicit MasterServiceBase(Master* server) : server_(server) {}
43
44
 protected:
45
  template <class ReqType, class RespType, class FnType>
46
  void HandleOnLeader(
47
      const ReqType* req,
48
      RespType* resp,
49
      rpc::RpcContext* rpc,
50
      FnType f,
51
      const char* file_name,
52
      int line_number,
53
      const char* function_name,
54
      HoldCatalogLock hold_catalog_lock);
55
56
  template <class HandlerType, class ReqType, class RespType>
57
  void HandleOnAllMasters(
58
      const ReqType* req,
59
      RespType* resp,
60
      rpc::RpcContext* rpc,
61
      Status (HandlerType::*f)(const ReqType*, RespType*),
62
      const char* file_name,
63
      int line_number,
64
      const char* function_name);
65
66
  template <class HandlerType, class ReqType, class RespType>
67
  void HandleIn(
68
      const ReqType* req,
69
      RespType* resp,
70
      rpc::RpcContext* rpc,
71
      Status (HandlerType::*f)(RespType*),
72
      const char* file_name,
73
      int line,
74
      const char* function_name,
75
      HoldCatalogLock hold_catalog_lock);
76
77
  template <class HandlerType, class ReqType, class RespType>
78
  void HandleIn(
79
      const ReqType* req,
80
      RespType* resp,
81
      rpc::RpcContext* rpc,
82
      Status (HandlerType::*f)(const ReqType*, RespType*),
83
      const char* file_name,
84
      int line_number,
85
      const char* function_name,
86
      HoldCatalogLock hold_catalog_lock);
87
88
  template <class HandlerType, class ReqType, class RespType>
89
  void HandleIn(
90
      const ReqType* req,
91
      RespType* resp,
92
      rpc::RpcContext* rpc,
93
      Status (HandlerType::*f)(const ReqType*, RespType*, rpc::RpcContext*),
94
      const char* file_name,
95
      int line_number,
96
      const char* function_name,
97
      HoldCatalogLock hold_catalog_lock);
98
99
  enterprise::CatalogManager* handler(CatalogManager*);
100
  FlushManager* handler(FlushManager*);
101
  PermissionsManager* handler(PermissionsManager*);
102
  EncryptionManager* handler(EncryptionManager*);
103
104
  Master* server_;
105
106
 private:
107
  DISALLOW_COPY_AND_ASSIGN(MasterServiceBase);
108
};
109
110
} // namespace master
111
} // namespace yb
112
113
#endif // YB_MASTER_MASTER_SERVICE_BASE_H