YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/master/flush_manager.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
#ifndef YB_MASTER_FLUSH_MANAGER_H
14
#define YB_MASTER_FLUSH_MANAGER_H
15
16
#include <set>
17
#include <shared_mutex>
18
#include <type_traits>
19
#include <unordered_set>
20
#include <utility>
21
22
#include <gflags/gflags_declare.h>
23
24
#include "yb/gutil/integral_types.h"
25
#include "yb/gutil/ref_counted.h"
26
27
#include "yb/master/master_admin.fwd.h"
28
#include "yb/master/master_fwd.h"
29
30
#include "yb/util/status_fwd.h"
31
#include "yb/util/enums.h"
32
#include "yb/util/locks.h"
33
34
namespace yb {
35
namespace master {
36
37
class Master;
38
class CatalogManager;
39
class TableInfo;
40
41
// Handle Flush-related operations.
42
class FlushManager {
43
 public:
44
  explicit FlushManager(Master* master, CatalogManagerIf* catalog_manager)
45
      : master_(DCHECK_NOTNULL(master)),
46
8.07k
        catalog_manager_(DCHECK_NOTNULL(catalog_manager)) {}
47
48
  // API to start a table flushing.
49
  CHECKED_STATUS FlushTables(const FlushTablesRequestPB* req,
50
                             FlushTablesResponsePB* resp);
51
52
  CHECKED_STATUS IsFlushTablesDone(const IsFlushTablesDoneRequestPB* req,
53
                                   IsFlushTablesDoneResponsePB* resp);
54
55
  void HandleFlushTabletsResponse(const FlushRequestId& flush_id,
56
                                  const TabletServerId& ts_uuid,
57
                                  const Status& status);
58
59
 private:
60
  // Start the background task to send the FlushTablets RPC to the Tablet Server.
61
  void SendFlushTabletsRequest(const TabletServerId& ts_uuid,
62
                               const scoped_refptr<TableInfo>& table,
63
                               const std::vector<TabletId>& tablet_ids,
64
                               const FlushRequestId& flush_id,
65
                               bool is_compaction);
66
67
  void DeleteCompleteFlushRequests();
68
69
  Master* master_;
70
  CatalogManagerIf* catalog_manager_;
71
72
  // Lock protecting the various in memory storage structures.
73
  typedef rw_spinlock LockType;
74
  mutable LockType lock_;
75
76
  typedef std::unordered_set<TabletServerId> TSIdSet;
77
  struct TSFlushingInfo {
78
10
    void clear() {
79
10
      ts_flushing_.clear();
80
10
      ts_succeed_.clear();
81
10
      ts_failed_.clear();
82
10
    }
83
84
    TSIdSet ts_flushing_;
85
    TSIdSet ts_succeed_;
86
    TSIdSet ts_failed_;
87
  };
88
89
  // Map of flushing requests: flush_request-id -> current per TS info.
90
  typedef std::unordered_map<FlushRequestId, TSFlushingInfo> FlushRequestMap;
91
  FlushRequestMap flush_requests_;
92
93
  DISALLOW_COPY_AND_ASSIGN(FlushManager);
94
};
95
96
} // namespace master
97
} // namespace yb
98
#endif // YB_MASTER_FLUSH_MANAGER_H