/Users/deen/code/yugabyte-db/src/yb/server/monitored_task.h
Line | Count | Source |
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 | | |
33 | | #ifndef YB_SERVER_MONITORED_TASK_H |
34 | | #define YB_SERVER_MONITORED_TASK_H |
35 | | |
36 | | #include <memory> |
37 | | #include <string> |
38 | | #include <type_traits> |
39 | | |
40 | | #include "yb/gutil/ref_counted.h" |
41 | | |
42 | | #include "yb/util/status_fwd.h" |
43 | | #include "yb/util/enums.h" |
44 | | #include "yb/util/math_util.h" |
45 | | #include "yb/util/monotime.h" |
46 | | |
47 | | namespace yb { |
48 | | namespace server { |
49 | | |
50 | | YB_DEFINE_ENUM(MonitoredTaskState, |
51 | | (kWaiting) // RPC not issued, or is waiting to be retried. |
52 | | (kRunning) // RPC has been issued. |
53 | | (kComplete) // RPC completed successfully. |
54 | | (kFailed) // RPC completed with failure. |
55 | | (kAborted) // RPC was aborted before it completed. |
56 | | (kScheduling) // RPC is being scheduled. |
57 | | ); |
58 | | |
59 | | class MonitoredTask : public std::enable_shared_from_this<MonitoredTask> { |
60 | | public: |
61 | 152k | virtual ~MonitoredTask() {} |
62 | | |
63 | | // Abort this task and return its value before it was successfully aborted. If the task entered |
64 | | // a different terminal state before we were able to abort it, return that state. |
65 | | virtual MonitoredTaskState AbortAndReturnPrevState(const Status& status) = 0; |
66 | | |
67 | | // Task State. |
68 | | virtual MonitoredTaskState state() const = 0; |
69 | | |
70 | | enum Type { |
71 | | ASYNC_CREATE_REPLICA, |
72 | | ASYNC_DELETE_REPLICA, |
73 | | ASYNC_ALTER_TABLE, |
74 | | ASYNC_TRUNCATE_TABLET, |
75 | | ASYNC_CHANGE_CONFIG, |
76 | | ASYNC_ADD_SERVER, |
77 | | ASYNC_REMOVE_SERVER, |
78 | | ASYNC_TRY_STEP_DOWN, |
79 | | ASYNC_SNAPSHOT_OP, |
80 | | ASYNC_COPARTITION_TABLE, |
81 | | ASYNC_FLUSH_TABLETS, |
82 | | ASYNC_ADD_TABLE_TO_TABLET, |
83 | | ASYNC_REMOVE_TABLE_FROM_TABLET, |
84 | | ASYNC_GET_SAFE_TIME, |
85 | | ASYNC_BACKFILL_TABLET_CHUNK, |
86 | | ASYNC_BACKFILL_DONE, |
87 | | BACKFILL_TABLE, |
88 | | ASYNC_SPLIT_TABLET, |
89 | | START_ELECTION, |
90 | | ASYNC_GET_TABLET_SPLIT_KEY, |
91 | | }; |
92 | | |
93 | | virtual Type type() const = 0; |
94 | | |
95 | | // Task Type Identifier. |
96 | | virtual std::string type_name() const = 0; |
97 | | |
98 | | // Task description. |
99 | | virtual std::string description() const = 0; |
100 | | |
101 | | // Task start time, may be !Initialized(). |
102 | | virtual MonoTime start_timestamp() const = 0; |
103 | | |
104 | | // Task completion time, may be !Initialized(). |
105 | | virtual MonoTime completion_timestamp() const = 0; |
106 | | |
107 | | // Whether task was started by the LB. |
108 | 166k | virtual bool started_by_lb() const { |
109 | 166k | return false; |
110 | 166k | } |
111 | | |
112 | | std::string ToString() const; |
113 | | |
114 | | protected: |
115 | 400k | static bool IsStateTerminal(MonitoredTaskState state) { |
116 | 400k | return state == MonitoredTaskState::kComplete || |
117 | 3.02k | state == MonitoredTaskState::kFailed || |
118 | 2.97k | state == MonitoredTaskState::kAborted; |
119 | 400k | } |
120 | | }; |
121 | | |
122 | | } // namespace server |
123 | | } // namespace yb |
124 | | |
125 | | #endif // YB_SERVER_MONITORED_TASK_H |