/Users/deen/code/yugabyte-db/src/yb/master/tasks_tracker.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_TASKS_TRACKER_H  | 
15  |  | #define YB_MASTER_TASKS_TRACKER_H  | 
16  |  |  | 
17  |  | #include <vector>  | 
18  |  |  | 
19  |  | #include <boost/circular_buffer.hpp>  | 
20  |  |  | 
21  |  | #include "yb/server/monitored_task.h"  | 
22  |  | #include "yb/util/locks.h"  | 
23  |  |  | 
24  |  | DECLARE_int32(tasks_tracker_num_tasks);  | 
25  |  | DECLARE_int32(tasks_tracker_keep_time_multiplier);  | 
26  |  | DECLARE_int32(tasks_tracker_num_long_term_tasks);  | 
27  |  | DECLARE_int32(long_term_tasks_tracker_keep_time_multiplier);  | 
28  |  | DECLARE_int32(catalog_manager_bg_task_wait_ms);  | 
29  |  |  | 
30  |  | namespace yb { | 
31  |  | namespace master { | 
32  |  |  | 
33  |  | YB_STRONGLY_TYPED_BOOL(IsUserInitiated);  | 
34  |  |  | 
35  |  | class TasksTracker : public RefCountedThreadSafe<TasksTracker> { | 
36  |  |  public:  | 
37  |  |   explicit TasksTracker(IsUserInitiated user_initiated = IsUserInitiated::kFalse);  | 
38  | 183  |   ~TasksTracker() = default;  | 
39  |  |  | 
40  |  |   std::string ToString();  | 
41  |  |  | 
42  |  |   // Reset tasks list.  | 
43  |  |   void Reset();  | 
44  |  |  | 
45  |  |   // Add task to the tracking list.  | 
46  |  |   void AddTask(std::shared_ptr<server::MonitoredTask> task);  | 
47  |  |  | 
48  |  |   // Cleanup old tasks that are older than a specific time.  | 
49  |  |   void CleanupOldTasks();  | 
50  |  |  | 
51  |  |   // Retrieve most recent tasks for displaying in master UI.  | 
52  |  |   std::vector<std::shared_ptr<server::MonitoredTask>> GetTasks();  | 
53  |  |  | 
54  |  |  private:  | 
55  |  |   const IsUserInitiated user_initiated_;  | 
56  |  |   // Lock protecting the buffer.  | 
57  |  |   mutable rw_spinlock lock_;  | 
58  |  |   // List of most recent tasks.  | 
59  |  |   boost::circular_buffer<std::shared_ptr<server::MonitoredTask>> tasks_;  | 
60  |  | };  | 
61  |  |  | 
62  |  | } // namespace master  | 
63  |  | } // namespace yb  | 
64  |  | #endif // YB_MASTER_TASKS_TRACKER_H  |