/Users/deen/code/yugabyte-db/src/yb/master/catalog_manager-internal.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | #ifndef YB_MASTER_CATALOG_MANAGER_INTERNAL_H |
33 | | #define YB_MASTER_CATALOG_MANAGER_INTERNAL_H |
34 | | |
35 | | #include "yb/common/wire_protocol.h" |
36 | | |
37 | | |
38 | | #include "yb/master/master_error.h" |
39 | | |
40 | | namespace yb { |
41 | | |
42 | | namespace master { |
43 | | |
44 | | inline CHECKED_STATUS SetupError(MasterErrorPB* error, |
45 | | MasterErrorPB::Code code, |
46 | 12.9k | const Status& s) { |
47 | 12.9k | StatusToPB(s, error->mutable_status()); |
48 | 12.9k | error->set_code(code); |
49 | 12.9k | return s; |
50 | 12.9k | } |
51 | | |
52 | 335 | inline CHECKED_STATUS CheckIfNoLongerLeader(const Status& s) { |
53 | | // TODO (KUDU-591): This is a bit of a hack, as right now |
54 | | // there's no way to propagate why a write to a consensus configuration has |
55 | | // failed. However, since we use Status::IllegalState()/IsAborted() to |
56 | | // indicate the situation where a write was issued on a node |
57 | | // that is no longer the leader, this suffices until we |
58 | | // distinguish this cause of write failure more explicitly. |
59 | 335 | if (s.IsIllegalState() || s.IsAborted()) { |
60 | 0 | return STATUS(ServiceUnavailable, |
61 | 0 | "Operation requested can only be executed on a leader master, but this" |
62 | 0 | " master is no longer the leader", s.ToString(), |
63 | 0 | MasterError(MasterErrorPB::NOT_THE_LEADER)); |
64 | 0 | } |
65 | | |
66 | 335 | return s; |
67 | 335 | } |
68 | | |
69 | | // If 's' indicates that the node is no longer the leader, setup |
70 | | // Service::UnavailableError as the error, set NOT_THE_LEADER as the |
71 | | // error code and return true. |
72 | | template<class RespClass> |
73 | 335 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { |
74 | 335 | auto new_status = CheckIfNoLongerLeader(s); |
75 | 335 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { |
76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); |
77 | 0 | } |
78 | | |
79 | 335 | return s; |
80 | 335 | } yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::CreateTableResponsePB>(yb::Status const&, yb::master::CreateTableResponsePB*) Line | Count | Source | 73 | 7 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { | 74 | 7 | auto new_status = CheckIfNoLongerLeader(s); | 75 | 7 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { | 76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); | 77 | 0 | } | 78 | | | 79 | 7 | return s; | 80 | 7 | } |
yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::DeleteTableResponsePB>(yb::Status const&, yb::master::DeleteTableResponsePB*) Line | Count | Source | 73 | 4 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { | 74 | 4 | auto new_status = CheckIfNoLongerLeader(s); | 75 | 4 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { | 76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); | 77 | 0 | } | 78 | | | 79 | 4 | return s; | 80 | 4 | } |
yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::AlterTableResponsePB>(yb::Status const&, yb::master::AlterTableResponsePB*) Line | Count | Source | 73 | 2 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { | 74 | 2 | auto new_status = CheckIfNoLongerLeader(s); | 75 | 2 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { | 76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); | 77 | 0 | } | 78 | | | 79 | 2 | return s; | 80 | 2 | } |
yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::CreateNamespaceResponsePB>(yb::Status const&, yb::master::CreateNamespaceResponsePB*) Line | Count | Source | 73 | 10 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { | 74 | 10 | auto new_status = CheckIfNoLongerLeader(s); | 75 | 10 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { | 76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); | 77 | 0 | } | 78 | | | 79 | 10 | return s; | 80 | 10 | } |
Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::CreateUDTypeResponsePB>(yb::Status const&, yb::master::CreateUDTypeResponsePB*) Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::DeleteUDTypeResponsePB>(yb::Status const&, yb::master::DeleteUDTypeResponsePB*) Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::DeleteNamespaceResponsePB>(yb::Status const&, yb::master::DeleteNamespaceResponsePB*) Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::CreateRoleResponsePB>(yb::Status const&, yb::master::CreateRoleResponsePB*) Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::DeleteRoleResponsePB>(yb::Status const&, yb::master::DeleteRoleResponsePB*) Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::GrantRevokeRoleResponsePB>(yb::Status const&, yb::master::GrantRevokeRoleResponsePB*) Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::GrantRevokePermissionResponsePB>(yb::Status const&, yb::master::GrantRevokePermissionResponsePB*) yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::CreateCDCStreamResponsePB>(yb::Status const&, yb::master::CreateCDCStreamResponsePB*) Line | Count | Source | 73 | 310 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { | 74 | 310 | auto new_status = CheckIfNoLongerLeader(s); | 75 | 310 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { | 76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); | 77 | 0 | } | 78 | | | 79 | 310 | return s; | 80 | 310 | } |
Unexecuted instantiation: yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::DeleteCDCStreamResponsePB>(yb::Status const&, yb::master::DeleteCDCStreamResponsePB*) yb::Status yb::master::CheckIfNoLongerLeaderAndSetupError<yb::master::SetupUniverseReplicationResponsePB>(yb::Status const&, yb::master::SetupUniverseReplicationResponsePB*) Line | Count | Source | 73 | 2 | CHECKED_STATUS CheckIfNoLongerLeaderAndSetupError(const Status& s, RespClass* resp) { | 74 | 2 | auto new_status = CheckIfNoLongerLeader(s); | 75 | 2 | if (MasterError(new_status) == MasterErrorPB::NOT_THE_LEADER) { | 76 | 0 | return SetupError(resp->mutable_error(), MasterErrorPB::NOT_THE_LEADER, new_status); | 77 | 0 | } | 78 | | | 79 | 2 | return s; | 80 | 2 | } |
|
81 | | |
82 | | } // namespace master |
83 | | } // namespace yb |
84 | | |
85 | | #endif // YB_MASTER_CATALOG_MANAGER_INTERNAL_H |