YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/master/async_flush_tablets_task.cc
Line
Count
Source (jump to first uncovered line)
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
#include "yb/master/async_flush_tablets_task.h"
15
16
#include "yb/common/wire_protocol.h"
17
18
#include "yb/master/flush_manager.h"
19
#include "yb/master/master.h"
20
21
#include "yb/tserver/tserver_admin.proxy.h"
22
23
namespace yb {
24
namespace master {
25
26
using std::string;
27
using tserver::TabletServerErrorPB;
28
29
////////////////////////////////////////////////////////////
30
// AsyncFlushTablets
31
////////////////////////////////////////////////////////////
32
AsyncFlushTablets::AsyncFlushTablets(Master *master,
33
                                     ThreadPool* callback_pool,
34
                                     const TabletServerId& ts_uuid,
35
                                     const scoped_refptr<TableInfo>& table,
36
                                     const vector<TabletId>& tablet_ids,
37
                                     const FlushRequestId& flush_id,
38
                                     bool is_compaction)
39
    : RetrySpecificTSRpcTask(master, callback_pool, ts_uuid, table),
40
      tablet_ids_(tablet_ids),
41
      flush_id_(flush_id),
42
30
      is_compaction_(is_compaction) {
43
30
}
44
45
60
string AsyncFlushTablets::description() const {
46
60
  return Format("$0 Flush Tablets RPC", permanent_uuid());
47
60
}
48
49
60
TabletServerId AsyncFlushTablets::permanent_uuid() const {
50
60
  return permanent_uuid_;
51
60
}
52
53
30
void AsyncFlushTablets::HandleResponse(int attempt) {
54
30
  server::UpdateClock(resp_, master_->clock());
55
56
30
  if (resp_.has_error()) {
57
0
    Status status = StatusFromPB(resp_.error().status());
58
59
    // Do not retry on a fatal error.
60
0
    switch (resp_.error().code()) {
61
0
      case TabletServerErrorPB::TABLET_NOT_FOUND:
62
0
        LOG(WARNING) << "TS " << permanent_uuid() << ": flush tablets failed because tablet "
63
0
                     << resp_.failed_tablet_id() << " was not found. "
64
0
                     << "No further retry: " << status.ToString();
65
0
        TransitionToCompleteState();
66
0
        break;
67
0
      default:
68
0
        LOG(WARNING) << "TS " << permanent_uuid() << ": flush tablets failed: "
69
0
                     << status.ToString();
70
0
    }
71
30
  } else {
72
30
    TransitionToCompleteState();
73
30
    VLOG
(1) << "TS " << permanent_uuid() << ": flush tablets complete"0
;
74
30
  }
75
76
30
  if (state() == server::MonitoredTaskState::kComplete) {
77
    // TODO: this class should not know CatalogManager API,
78
    //       remove circular dependency between classes.
79
30
    master_->flush_manager()->HandleFlushTabletsResponse(
80
30
        flush_id_, permanent_uuid_,
81
30
        resp_.has_error() ? 
StatusFromPB(resp_.error().status())0
: Status::OK());
82
30
  } else {
83
0
    VLOG(1) << "FlushTablets task is not completed";
84
0
  }
85
30
}
86
87
30
bool AsyncFlushTablets::SendRequest(int attempt) {
88
30
  tserver::FlushTabletsRequestPB req;
89
30
  req.set_dest_uuid(permanent_uuid_);
90
30
  req.set_propagated_hybrid_time(master_->clock()->Now().ToUint64());
91
30
  req.set_operation(is_compaction_ ? 
tserver::FlushTabletsRequestPB::COMPACT0
92
30
                                   : tserver::FlushTabletsRequestPB::FLUSH);
93
94
43
  for (const TabletId& id : tablet_ids_) {
95
43
    req.add_tablet_ids(id);
96
43
  }
97
98
30
  ts_admin_proxy_->FlushTabletsAsync(req, &resp_, &rpc_, BindRpcCallback());
99
30
  VLOG(1) << "Send flush tablets request to " << permanent_uuid_
100
0
          << " (attempt " << attempt << "):\n"
101
0
          << req.DebugString();
102
30
  return true;
103
30
}
104
105
} // namespace master
106
} // namespace yb