]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
2 | // This source code is licensed under both the GPLv2 (found in the |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
7c673cae FG |
5 | // |
6 | #pragma once | |
7 | #include <string> | |
8 | ||
f67539c2 | 9 | #include "file/filename.h" |
7c673cae FG |
10 | #include "options/db_options.h" |
11 | #include "rocksdb/env.h" | |
f67539c2 | 12 | #include "rocksdb/file_system.h" |
20effc67 | 13 | #include "rocksdb/sst_file_writer.h" |
7c673cae FG |
14 | #include "rocksdb/status.h" |
15 | #include "rocksdb/types.h" | |
20effc67 | 16 | #include "trace_replay/io_tracer.h" |
7c673cae | 17 | |
f67539c2 | 18 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
19 | // use_fsync maps to options.use_fsync, which determines the way that |
20 | // the file is synced after copying. | |
20effc67 TL |
21 | extern IOStatus CopyFile(FileSystem* fs, const std::string& source, |
22 | const std::string& destination, uint64_t size, | |
23 | bool use_fsync, | |
24 | const std::shared_ptr<IOTracer>& io_tracer = nullptr); | |
7c673cae | 25 | |
20effc67 TL |
26 | extern IOStatus CreateFile(FileSystem* fs, const std::string& destination, |
27 | const std::string& contents, bool use_fsync); | |
7c673cae | 28 | |
494da23a TL |
29 | extern Status DeleteDBFile(const ImmutableDBOptions* db_options, |
30 | const std::string& fname, | |
f67539c2 TL |
31 | const std::string& path_to_sync, const bool force_bg, |
32 | const bool force_fg); | |
7c673cae | 33 | |
f67539c2 TL |
34 | extern bool IsWalDirSameAsDBPath(const ImmutableDBOptions* db_options); |
35 | ||
20effc67 TL |
36 | extern IOStatus GenerateOneFileChecksum( |
37 | FileSystem* fs, const std::string& file_path, | |
38 | FileChecksumGenFactory* checksum_factory, | |
39 | const std::string& requested_checksum_func_name, std::string* file_checksum, | |
40 | std::string* file_checksum_func_name, | |
41 | size_t verify_checksums_readahead_size, bool allow_mmap_reads, | |
42 | std::shared_ptr<IOTracer>& io_tracer); | |
43 | ||
44 | inline IOStatus PrepareIOFromReadOptions(const ReadOptions& ro, Env* env, | |
45 | IOOptions& opts) { | |
46 | if (!env) { | |
47 | env = Env::Default(); | |
48 | } | |
49 | ||
50 | if (ro.deadline.count()) { | |
51 | std::chrono::microseconds now = std::chrono::microseconds(env->NowMicros()); | |
52 | // Ensure there is atleast 1us available. We don't want to pass a value of | |
53 | // 0 as that means no timeout | |
54 | if (now >= ro.deadline) { | |
55 | return IOStatus::TimedOut("Deadline exceeded"); | |
56 | } | |
57 | opts.timeout = ro.deadline - now; | |
58 | } | |
59 | ||
60 | if (ro.io_timeout.count() && | |
61 | (!opts.timeout.count() || ro.io_timeout < opts.timeout)) { | |
62 | opts.timeout = ro.io_timeout; | |
63 | } | |
64 | return IOStatus::OK(); | |
65 | } | |
66 | ||
67 | // Test method to delete the input directory and all of its contents. | |
68 | // This method is destructive and is meant for use only in tests!!! | |
69 | Status DestroyDir(Env* env, const std::string& dir); | |
f67539c2 | 70 | } // namespace ROCKSDB_NAMESPACE |