1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license.
3
4#pragma once
5
6#include <atomic>
7#include <cstdint>
8
9namespace FASTER {
10namespace core {
11
12/// Used by FASTER to track status, during recovery action.
13
14enum class PageRecoveryStatus {
15 NotStarted = 0,
16 IssuedRead,
17 ReadDone,
18 IssuedFlush,
19 FlushDone
20};
21
22class RecoveryStatus {
23 public:
24 RecoveryStatus(uint32_t start_page_, uint32_t end_page_)
25 : start_page{ start_page_ }
26 , end_page{ end_page_ }
27 , page_status_{ nullptr } {
28 assert(end_page >= start_page);
29 uint32_t buffer_size = end_page - start_page;
30 page_status_ = new std::atomic<PageRecoveryStatus>[buffer_size];
31 std::memset(page_status_, 0, sizeof(std::atomic<PageRecoveryStatus>) * buffer_size);
32 }
33
34 ~RecoveryStatus() {
35 delete page_status_;
36 }
37
38 const std::atomic<PageRecoveryStatus>& page_status(uint32_t page) const {
39 assert(page >= start_page);
40 assert(page < end_page);
41 return page_status_[page - start_page];
42 }
43 std::atomic<PageRecoveryStatus>& page_status(uint32_t page) {
44 assert(page >= start_page);
45 assert(page < end_page);
46 return page_status_[page - start_page];
47 }
48
49 uint32_t start_page;
50 uint32_t end_page;
51
52 private:
53 std::atomic<PageRecoveryStatus>* page_status_;
54};
55
56}
57} // namespace FASTER::core
58