YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/restoration_state.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/restoration_state.h"
15
16
#include "yb/master/catalog_entity_info.h"
17
#include "yb/master/master_backup.pb.h"
18
#include "yb/master/snapshot_coordinator_context.h"
19
#include "yb/master/snapshot_state.h"
20
21
#include "yb/tserver/tserver_error.h"
22
23
#include "yb/util/result.h"
24
25
namespace yb {
26
namespace master {
27
28
namespace {
29
30
std::string MakeRestorationStateLogPrefix(
31
0
    const TxnSnapshotRestorationId& restoration_id, SnapshotState* snapshot) {
32
0
  if (snapshot->schedule_id()) {
33
0
    return Format("Restoration[$0/$1/$2]: ",
34
0
                  restoration_id, snapshot->id(), snapshot->schedule_id());
35
0
  }
36
0
  return Format("Restoration[$0/$1]: ", restoration_id, snapshot->id());
37
0
}
38
39
} // namespace
40
41
RestorationState::RestorationState(
42
    SnapshotCoordinatorContext* context, const TxnSnapshotRestorationId& restoration_id,
43
    SnapshotState* snapshot)
44
    : StateWithTablets(context, SysSnapshotEntryPB::RESTORING,
45
                       MakeRestorationStateLogPrefix(restoration_id, snapshot)),
46
      restoration_id_(restoration_id), snapshot_id_(snapshot->id()),
47
0
      schedule_id_(snapshot->schedule_id()) {
48
0
  InitTabletIds(snapshot->TabletIdsInState(SysSnapshotEntryPB::COMPLETE));
49
0
}
50
51
0
CHECKED_STATUS RestorationState::ToPB(RestorationInfoPB* out) {
52
0
  out->set_id(restoration_id_.data(), restoration_id_.size());
53
0
  auto& entry = *out->mutable_entry();
54
0
  entry.set_snapshot_id(snapshot_id_.data(), snapshot_id_.size());
55
56
0
  entry.set_state(VERIFY_RESULT(AggregatedState()));
57
58
0
  if (complete_time_) {
59
0
    entry.set_complete_time_ht(complete_time_.ToUint64());
60
0
  }
61
62
0
  TabletsToPB(entry.mutable_tablet_restorations());
63
64
0
  return Status::OK();
65
0
}
66
67
0
TabletInfos RestorationState::PrepareOperations() {
68
0
  std::vector<TabletId> tablet_ids;
69
0
  DoPrepareOperations([&tablet_ids](const TabletData& data) {
70
0
    tablet_ids.push_back(data.id);
71
0
    return true;
72
0
  });
73
0
  return context().GetTabletInfos(tablet_ids);
74
0
}
75
76
0
bool RestorationState::IsTerminalFailure(const Status& status) {
77
0
  return status.IsAborted() ||
78
0
         tserver::TabletServerError(status) == tserver::TabletServerErrorPB::INVALID_SNAPSHOT;
79
0
}
80
81
} // namespace master
82
} // namespace yb