| 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 | #include <string> |
| 9 | |
| 10 | #include "../core/gc_state.h" |
| 11 | #include "../core/light_epoch.h" |
| 12 | #include "../core/guid.h" |
| 13 | #include "../environment/file.h" |
| 14 | |
| 15 | namespace FASTER { |
| 16 | namespace device { |
| 17 | |
| 18 | /// A dummy (null) disk, used when you want an in-memory-only FASTER store. |
| 19 | |
| 20 | struct NullHandler { |
| 21 | }; |
| 22 | |
| 23 | class NullFile { |
| 24 | public: |
| 25 | Status Open(NullHandler* handler) { |
| 26 | return Status::Ok; |
| 27 | } |
| 28 | Status Close() { |
| 29 | return Status::Ok; |
| 30 | } |
| 31 | Status Delete() { |
| 32 | return Status::Ok; |
| 33 | } |
| 34 | void Truncate(uint64_t new_begin_offset, GcState::truncate_callback_t callback) { |
| 35 | if(callback) { |
| 36 | callback(new_begin_offset); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | Status ReadAsync(uint64_t source, void* dest, uint32_t length, |
| 41 | AsyncIOCallback callback, IAsyncContext& context) const { |
| 42 | callback(&context, Status::Ok, length); |
| 43 | return Status::Ok; |
| 44 | } |
| 45 | Status WriteAsync(const void* source, uint64_t dest, uint32_t length, |
| 46 | AsyncIOCallback callback, IAsyncContext& context) { |
| 47 | callback(&context, Status::Ok, length); |
| 48 | return Status::Ok; |
| 49 | } |
| 50 | |
| 51 | static size_t alignment() { |
| 52 | // Align null device to cache line. |
| 53 | return 64; |
| 54 | } |
| 55 | |
| 56 | void set_handler(NullHandler* handler) { |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | class NullDisk { |
| 61 | public: |
| 62 | typedef NullHandler handler_t; |
| 63 | typedef NullFile file_t; |
| 64 | typedef NullFile log_file_t; |
| 65 | |
| 66 | NullDisk(const std::string& filename, LightEpoch& epoch) { |
| 67 | } |
| 68 | |
| 69 | static uint32_t sector_size() { |
| 70 | return 64; |
| 71 | } |
| 72 | |
| 73 | /// Methods required by the (implicit) disk interface. |
| 74 | const file_t& log() const { |
| 75 | return log_; |
| 76 | } |
| 77 | file_t& log() { |
| 78 | return log_; |
| 79 | } |
| 80 | |
| 81 | std::string relative_index_checkpoint_path(const Guid& token) const { |
| 82 | assert(false); |
| 83 | return "" ; |
| 84 | } |
| 85 | std::string index_checkpoint_path(const Guid& token) const { |
| 86 | assert(false); |
| 87 | return "" ; |
| 88 | } |
| 89 | |
| 90 | std::string relative_cpr_checkpoint_path(const Guid& token) const { |
| 91 | assert(false); |
| 92 | return "" ; |
| 93 | } |
| 94 | std::string cpr_checkpoint_path(const Guid& token) const { |
| 95 | assert(false); |
| 96 | return "" ; |
| 97 | } |
| 98 | |
| 99 | void CreateIndexCheckpointDirectory(const Guid& token) { |
| 100 | assert(false); |
| 101 | } |
| 102 | void CreateCprCheckpointDirectory(const Guid& token) { |
| 103 | assert(false); |
| 104 | } |
| 105 | |
| 106 | file_t NewFile(const std::string& relative_path) { |
| 107 | assert(false); |
| 108 | return file_t{}; |
| 109 | } |
| 110 | |
| 111 | handler_t& handler() { |
| 112 | return handler_; |
| 113 | } |
| 114 | |
| 115 | inline static constexpr bool TryComplete() { |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | private: |
| 120 | handler_t handler_; |
| 121 | file_t log_; |
| 122 | }; |
| 123 | |
| 124 | } |
| 125 | } // namespace FASTER::device |