2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2015-07-02 01:13:49 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2020-09-23 21:54:29 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
2016-12-22 21:51:29 +01:00
|
|
|
#include "port/win/env_win.h"
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
#include <direct.h> // _rmdir, _mkdir, _getcwd
|
2015-07-02 01:13:49 +02:00
|
|
|
#include <errno.h>
|
2021-01-06 19:48:24 +01:00
|
|
|
#include <io.h> // _access
|
|
|
|
#include <rpc.h> // for uuid generation
|
|
|
|
#include <shlwapi.h>
|
2015-07-02 01:13:49 +02:00
|
|
|
#include <sys/stat.h>
|
2021-01-06 19:48:24 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <windows.h>
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <ctime>
|
|
|
|
#include <thread>
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "monitoring/iostats_context_imp.h"
|
|
|
|
#include "monitoring/thread_status_updater.h"
|
|
|
|
#include "monitoring/thread_status_util.h"
|
2021-01-06 19:48:24 +01:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "port/port_dirent.h"
|
|
|
|
#include "port/win/io_win.h"
|
|
|
|
#include "port/win/win_logger.h"
|
|
|
|
#include "port/win/win_thread.h"
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/slice.h"
|
2018-03-06 20:47:42 +01:00
|
|
|
#include "strsafe.h"
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
// Undefine the functions windows might use (again)...
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#undef DeleteFile
|
|
|
|
#undef LoadLibrary
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-07-02 01:13:49 +02:00
|
|
|
|
|
|
|
ThreadStatusUpdater* CreateThreadStatusUpdater() {
|
|
|
|
return new ThreadStatusUpdater();
|
|
|
|
}
|
|
|
|
|
2016-05-17 02:01:00 +02:00
|
|
|
namespace {
|
|
|
|
|
2019-03-28 00:31:30 +01:00
|
|
|
// Sector size used when physical sector size cannot be obtained from device.
|
|
|
|
static const size_t kSectorSize = 512;
|
2018-03-06 20:47:42 +01:00
|
|
|
|
2015-07-02 01:13:49 +02:00
|
|
|
// RAII helpers for HANDLEs
|
|
|
|
const auto CloseHandleFunc = [](HANDLE h) { ::CloseHandle(h); };
|
|
|
|
typedef std::unique_ptr<void, decltype(CloseHandleFunc)> UniqueCloseHandlePtr;
|
|
|
|
|
2018-03-06 20:47:42 +01:00
|
|
|
const auto FindCloseFunc = [](HANDLE h) { ::FindClose(h); };
|
|
|
|
typedef std::unique_ptr<void, decltype(FindCloseFunc)> UniqueFindClosePtr;
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
void WinthreadCall(const char* label, std::error_code result) {
|
|
|
|
if (0 != result.value()) {
|
|
|
|
fprintf(stderr, "pthread %s: %s\n", label, strerror(result.value()));
|
|
|
|
abort();
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
} // namespace
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
namespace port {
|
2021-01-06 19:48:24 +01:00
|
|
|
WinClock::WinClock()
|
|
|
|
: perf_counter_frequency_(0),
|
2019-03-21 23:10:38 +01:00
|
|
|
nano_seconds_per_period_(0),
|
2016-05-20 01:40:54 +02:00
|
|
|
GetSystemTimePreciseAsFileTime_(NULL) {
|
|
|
|
{
|
|
|
|
LARGE_INTEGER qpf;
|
2018-02-02 21:14:42 +01:00
|
|
|
BOOL ret __attribute__((__unused__));
|
2017-10-23 23:20:53 +02:00
|
|
|
ret = QueryPerformanceFrequency(&qpf);
|
2016-05-20 01:40:54 +02:00
|
|
|
assert(ret == TRUE);
|
|
|
|
perf_counter_frequency_ = qpf.QuadPart;
|
2019-03-21 23:10:38 +01:00
|
|
|
|
|
|
|
if (std::nano::den % perf_counter_frequency_ == 0) {
|
|
|
|
nano_seconds_per_period_ = std::nano::den / perf_counter_frequency_;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
HMODULE module = GetModuleHandle("kernel32.dll");
|
|
|
|
if (module != NULL) {
|
2019-03-28 00:31:30 +01:00
|
|
|
GetSystemTimePreciseAsFileTime_ =
|
2021-01-06 19:48:24 +01:00
|
|
|
(FnGetSystemTimePreciseAsFileTime)GetProcAddress(
|
|
|
|
module, "GetSystemTimePreciseAsFileTime");
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
const std::shared_ptr<WinClock>& WinClock::Default() {
|
|
|
|
static std::shared_ptr<WinClock> clock = std::make_shared<WinClock>();
|
|
|
|
return clock;
|
|
|
|
}
|
|
|
|
void WinClock::SleepForMicroseconds(int micros) {
|
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(micros));
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
std::string WinClock::TimeToString(uint64_t secondsSince1970) {
|
|
|
|
std::string result;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
const time_t seconds = secondsSince1970;
|
|
|
|
const int maxsize = 64;
|
2018-10-12 08:22:42 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
struct tm t;
|
|
|
|
errno_t ret = localtime_s(&t, &seconds);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
result = std::to_string(seconds);
|
|
|
|
} else {
|
|
|
|
result.resize(maxsize);
|
|
|
|
char* p = &result[0];
|
|
|
|
|
|
|
|
int len =
|
|
|
|
snprintf(p, maxsize, "%04d/%02d/%02d-%02d:%02d:%02d ", t.tm_year + 1900,
|
|
|
|
t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
|
|
|
|
assert(len > 0);
|
|
|
|
|
|
|
|
result.resize(len);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
uint64_t WinClock::NowMicros() {
|
|
|
|
if (GetSystemTimePreciseAsFileTime_ != NULL) {
|
|
|
|
// all std::chrono clocks on windows proved to return
|
|
|
|
// values that may repeat that is not good enough for some uses.
|
|
|
|
const int64_t c_UnixEpochStartTicks = 116444736000000000LL;
|
|
|
|
const int64_t c_FtToMicroSec = 10;
|
|
|
|
|
|
|
|
// This interface needs to return system time and not
|
|
|
|
// just any microseconds because it is often used as an argument
|
|
|
|
// to TimedWait() on condition variable
|
|
|
|
FILETIME ftSystemTime;
|
|
|
|
GetSystemTimePreciseAsFileTime_(&ftSystemTime);
|
|
|
|
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
li.LowPart = ftSystemTime.dwLowDateTime;
|
|
|
|
li.HighPart = ftSystemTime.dwHighDateTime;
|
|
|
|
// Subtract unix epoch start
|
|
|
|
li.QuadPart -= c_UnixEpochStartTicks;
|
|
|
|
// Convert to microsecs
|
|
|
|
li.QuadPart /= c_FtToMicroSec;
|
|
|
|
return li.QuadPart;
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
2021-01-06 19:48:24 +01:00
|
|
|
using namespace std::chrono;
|
|
|
|
return duration_cast<microseconds>(system_clock::now().time_since_epoch())
|
|
|
|
.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t WinClock::NowNanos() {
|
|
|
|
if (nano_seconds_per_period_ != 0) {
|
|
|
|
// all std::chrono clocks on windows have the same resolution that is only
|
|
|
|
// good enough for microseconds but not nanoseconds
|
|
|
|
// On Windows 8 and Windows 2012 Server
|
|
|
|
// GetSystemTimePreciseAsFileTime(¤t_time) can be used
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
QueryPerformanceCounter(&li);
|
|
|
|
// Convert performance counter to nanoseconds by precomputed ratio.
|
|
|
|
// Directly multiply nano::den with li.QuadPart causes overflow.
|
|
|
|
// Only do this when nano::den is divisible by perf_counter_frequency_,
|
|
|
|
// which most likely is the case in reality. If it's not, fall back to
|
|
|
|
// high_resolution_clock, which may be less precise under old compilers.
|
|
|
|
li.QuadPart *= nano_seconds_per_period_;
|
|
|
|
return li.QuadPart;
|
|
|
|
}
|
|
|
|
using namespace std::chrono;
|
|
|
|
return duration_cast<nanoseconds>(
|
|
|
|
high_resolution_clock::now().time_since_epoch())
|
|
|
|
.count();
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
Status WinClock::GetCurrentTime(int64_t* unix_time) {
|
2016-05-20 01:40:54 +02:00
|
|
|
time_t time = std::time(nullptr);
|
|
|
|
if (time == (time_t)(-1)) {
|
|
|
|
return Status::NotSupported("Failed to get time");
|
2016-05-17 02:01:00 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
*unix_time = time;
|
|
|
|
return Status::OK();
|
2016-05-17 02:01:00 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
WinFileSystem::WinFileSystem(const std::shared_ptr<WinClock>& clock)
|
|
|
|
: clock_(clock), page_size_(4 * 1024), allocation_granularity_(page_size_) {
|
|
|
|
SYSTEM_INFO sinfo;
|
|
|
|
GetSystemInfo(&sinfo);
|
|
|
|
|
|
|
|
page_size_ = sinfo.dwPageSize;
|
|
|
|
allocation_granularity_ = sinfo.dwAllocationGranularity;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::shared_ptr<WinFileSystem>& WinFileSystem::Default() {
|
|
|
|
static std::shared_ptr<WinFileSystem> fs =
|
|
|
|
std::make_shared<WinFileSystem>(WinClock::Default());
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
WinEnvIO::WinEnvIO(Env* hosted_env) : hosted_env_(hosted_env) {}
|
|
|
|
|
|
|
|
WinEnvIO::~WinEnvIO() {}
|
|
|
|
|
|
|
|
IOStatus WinFileSystem::DeleteFile(const std::string& fname,
|
|
|
|
const IOOptions& /*options*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
|
|
|
|
|
|
|
BOOL ret = RX_DeleteFile(RX_FN(fname).c_str());
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
result = IOErrorFromWindowsError("Failed to delete: " + fname, lastError);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
IOStatus WinFileSystem::Truncate(const std::string& fname, size_t size,
|
|
|
|
const IOOptions& /*options*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
|
|
|
int result = ROCKSDB_NAMESPACE::port::Truncate(fname, size);
|
|
|
|
if (result != 0) {
|
|
|
|
s = IOError("Failed to truncate: " + fname, errno);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
IOStatus WinFileSystem::NewSequentialFile(
|
|
|
|
const std::string& fname, const FileOptions& options,
|
|
|
|
std::unique_ptr<FSSequentialFile>* result, IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
result->reset();
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// Corruption test needs to rename and delete files of these kind
|
|
|
|
// while they are still open with another handle. For that reason we
|
|
|
|
// allow share_write and delete(allows rename).
|
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
2017-01-15 22:11:04 +01:00
|
|
|
|
|
|
|
DWORD fileFlags = FILE_ATTRIBUTE_READONLY;
|
|
|
|
|
|
|
|
if (options.use_direct_reads && !options.use_mmap_reads) {
|
|
|
|
fileFlags |= FILE_FLAG_NO_BUFFERING;
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2018-10-12 08:22:42 +02:00
|
|
|
hFile = RX_CreateFile(
|
2019-03-28 00:31:30 +01:00
|
|
|
RX_FN(fname).c_str(), GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
|
|
|
|
OPEN_EXISTING, // Original fopen mode is "rb"
|
|
|
|
fileFlags, NULL);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
s = IOErrorFromWindowsError("Failed to open NewSequentialFile" + fname,
|
2019-03-28 00:31:30 +01:00
|
|
|
lastError);
|
2016-05-20 01:40:54 +02:00
|
|
|
} else {
|
|
|
|
result->reset(new WinSequentialFile(fname, hFile, options));
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::NewRandomAccessFile(
|
|
|
|
const std::string& fname, const FileOptions& options,
|
|
|
|
std::unique_ptr<FSRandomAccessFile>* result, IODebugContext* dbg) {
|
2016-05-20 01:40:54 +02:00
|
|
|
result->reset();
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus s;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// Open the file for read-only random access
|
|
|
|
// Random access is to disable read-ahead as the system reads too much data
|
|
|
|
DWORD fileFlags = FILE_ATTRIBUTE_READONLY;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-12-22 21:51:29 +01:00
|
|
|
if (options.use_direct_reads && !options.use_mmap_reads) {
|
2016-05-20 01:40:54 +02:00
|
|
|
fileFlags |= FILE_FLAG_NO_BUFFERING;
|
|
|
|
} else {
|
|
|
|
fileFlags |= FILE_FLAG_RANDOM_ACCESS;
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-17 02:01:00 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
/// Shared access is necessary for corruption test to pass
|
|
|
|
// almost all tests would work with a possible exception of fault_injection
|
|
|
|
HANDLE hFile = 0;
|
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2021-01-06 19:48:24 +01:00
|
|
|
hFile =
|
|
|
|
RX_CreateFile(RX_FN(fname).c_str(), GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
NULL, OPEN_EXISTING, fileFlags, NULL);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"NewRandomAccessFile failed to Create/Open: " + fname, lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
UniqueCloseHandlePtr fileGuard(hFile, CloseHandleFunc);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// CAUTION! This will map the entire file into the process address space
|
|
|
|
if (options.use_mmap_reads && sizeof(void*) >= 8) {
|
|
|
|
// Use mmap when virtual address-space is plentiful.
|
|
|
|
uint64_t fileSize;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
s = GetFileSize(fname, IOOptions(), &fileSize, dbg);
|
2016-04-30 01:43:13 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
// Will not map empty files
|
|
|
|
if (fileSize == 0) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOError("NewRandomAccessFile failed to map empty file: " + fname,
|
|
|
|
EINVAL);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-04-30 01:43:13 +02:00
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
HANDLE hMap = RX_CreateFileMapping(hFile, NULL, PAGE_READONLY,
|
2019-03-28 00:31:30 +01:00
|
|
|
0, // At its present length
|
|
|
|
0,
|
|
|
|
NULL); // Mapping name
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (!hMap) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"Failed to create file mapping for NewRandomAccessFile: " + fname,
|
|
|
|
lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
UniqueCloseHandlePtr mapGuard(hMap, CloseHandleFunc);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
const void* mapped_region =
|
2021-01-06 19:48:24 +01:00
|
|
|
MapViewOfFileEx(hMap, FILE_MAP_READ,
|
|
|
|
0, // High DWORD of access start
|
|
|
|
0, // Low DWORD
|
|
|
|
static_cast<SIZE_T>(fileSize),
|
|
|
|
NULL); // Let the OS choose the mapping
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (!mapped_region) {
|
|
|
|
auto lastError = GetLastError();
|
2015-07-13 21:11:05 +02:00
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"Failed to MapViewOfFile for NewRandomAccessFile: " + fname,
|
|
|
|
lastError);
|
2015-07-13 21:11:05 +02:00
|
|
|
}
|
2016-04-30 01:43:13 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
result->reset(new WinMmapReadableFile(fname, hFile, hMap, mapped_region,
|
2019-03-28 00:31:30 +01:00
|
|
|
static_cast<size_t>(fileSize)));
|
2016-05-20 01:40:54 +02:00
|
|
|
|
|
|
|
mapGuard.release();
|
|
|
|
fileGuard.release();
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
} else {
|
2021-01-06 19:48:24 +01:00
|
|
|
result->reset(new WinRandomAccessFile(
|
|
|
|
fname, hFile, std::max(GetSectorSize(fname), page_size_), options));
|
2016-05-20 01:40:54 +02:00
|
|
|
fileGuard.release();
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::OpenWritableFile(
|
|
|
|
const std::string& fname, const FileOptions& options,
|
|
|
|
std::unique_ptr<FSWritableFile>* result, bool reopen) {
|
2016-05-20 01:40:54 +02:00
|
|
|
const size_t c_BufferCapacity = 64 * 1024;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
EnvOptions local_options(options);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
result->reset();
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus s;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
DWORD fileFlags = FILE_ATTRIBUTE_NORMAL;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-12-22 21:51:29 +01:00
|
|
|
if (local_options.use_direct_writes && !local_options.use_mmap_writes) {
|
2017-12-22 03:37:27 +01:00
|
|
|
fileFlags = FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// Desired access. We are want to write only here but if we want to memory
|
|
|
|
// map
|
|
|
|
// the file then there is no write only mode so we have to create it
|
|
|
|
// Read/Write
|
|
|
|
// However, MapViewOfFile specifies only Write only
|
|
|
|
DWORD desired_access = GENERIC_WRITE;
|
|
|
|
DWORD shared_mode = FILE_SHARE_READ;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (local_options.use_mmap_writes) {
|
|
|
|
desired_access |= GENERIC_READ;
|
2018-03-06 20:47:42 +01:00
|
|
|
} else {
|
2016-05-20 01:40:54 +02:00
|
|
|
// Adding this solely for tests to pass (fault_injection_test,
|
|
|
|
// wal_manager_test).
|
|
|
|
shared_mode |= (FILE_SHARE_WRITE | FILE_SHARE_DELETE);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2017-06-20 19:16:24 +02:00
|
|
|
// This will always truncate the file
|
|
|
|
DWORD creation_disposition = CREATE_ALWAYS;
|
|
|
|
if (reopen) {
|
|
|
|
creation_disposition = OPEN_ALWAYS;
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
HANDLE hFile = 0;
|
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2018-10-12 08:22:42 +02:00
|
|
|
hFile = RX_CreateFile(
|
2019-03-28 00:31:30 +01:00
|
|
|
RX_FN(fname).c_str(),
|
|
|
|
desired_access, // Access desired
|
|
|
|
shared_mode,
|
2021-01-06 19:48:24 +01:00
|
|
|
NULL, // Security attributes
|
2019-03-28 00:31:30 +01:00
|
|
|
// Posix env says (reopen) ? (O_CREATE | O_APPEND) : O_CREAT | O_TRUNC
|
|
|
|
creation_disposition,
|
2021-01-06 19:48:24 +01:00
|
|
|
fileFlags, // Flags
|
|
|
|
NULL); // Template File
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"Failed to create a NewWriteableFile: " + fname, lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 19:16:24 +02:00
|
|
|
// We will start writing at the end, appending
|
|
|
|
if (reopen) {
|
|
|
|
LARGE_INTEGER zero_move;
|
|
|
|
zero_move.QuadPart = 0;
|
|
|
|
BOOL ret = SetFilePointerEx(hFile, zero_move, NULL, FILE_END);
|
|
|
|
if (!ret) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"Failed to create a ReopenWritableFile move to the end: " + fname,
|
|
|
|
lastError);
|
2017-06-20 19:16:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (options.use_mmap_writes) {
|
|
|
|
// We usually do not use mmmapping on SSD and thus we pass memory
|
|
|
|
// page_size
|
|
|
|
result->reset(new WinMmapFile(fname, hFile, page_size_,
|
2019-03-28 00:31:30 +01:00
|
|
|
allocation_granularity_, local_options));
|
2016-05-20 01:40:54 +02:00
|
|
|
} else {
|
|
|
|
// Here we want the buffer allocation to be aligned by the SSD page size
|
|
|
|
// and to be a multiple of it
|
2021-01-06 19:48:24 +01:00
|
|
|
result->reset(new WinWritableFile(
|
|
|
|
fname, hFile, std::max(GetSectorSize(fname), GetPageSize()),
|
|
|
|
c_BufferCapacity, local_options));
|
2015-09-11 18:57:02 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
2015-09-11 18:57:02 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::NewWritableFile(const std::string& fname,
|
|
|
|
const FileOptions& options,
|
|
|
|
std::unique_ptr<FSWritableFile>* result,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
return OpenWritableFile(fname, options, result, false);
|
|
|
|
}
|
2016-10-14 01:36:34 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::ReopenWritableFile(
|
|
|
|
const std::string& fname, const FileOptions& options,
|
|
|
|
std::unique_ptr<FSWritableFile>* result, IODebugContext* /*dbg*/) {
|
|
|
|
return OpenWritableFile(fname, options, result, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
IOStatus WinFileSystem::NewRandomRWFile(const std::string& fname,
|
|
|
|
const FileOptions& options,
|
|
|
|
std::unique_ptr<FSRandomRWFile>* result,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2016-10-14 01:36:34 +02:00
|
|
|
|
|
|
|
// Open the file for read-only random access
|
|
|
|
// Random access is to disable read-ahead as the system reads too much data
|
|
|
|
DWORD desired_access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
DWORD shared_mode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
2021-01-06 19:48:24 +01:00
|
|
|
DWORD creation_disposition = OPEN_EXISTING; // Fail if file does not exist
|
2016-10-14 01:36:34 +02:00
|
|
|
DWORD file_flags = FILE_FLAG_RANDOM_ACCESS;
|
|
|
|
|
2016-12-22 21:51:29 +01:00
|
|
|
if (options.use_direct_reads && options.use_direct_writes) {
|
2016-10-14 01:36:34 +02:00
|
|
|
file_flags |= FILE_FLAG_NO_BUFFERING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Shared access is necessary for corruption test to pass
|
|
|
|
// almost all tests would work with a possible exception of fault_injection
|
|
|
|
HANDLE hFile = 0;
|
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2021-01-06 19:48:24 +01:00
|
|
|
hFile = RX_CreateFile(RX_FN(fname).c_str(), desired_access, shared_mode,
|
|
|
|
NULL, // Security attributes
|
|
|
|
creation_disposition, file_flags, NULL);
|
2016-10-14 01:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2021-01-06 19:48:24 +01:00
|
|
|
"NewRandomRWFile failed to Create/Open: " + fname, lastError);
|
2016-10-14 01:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UniqueCloseHandlePtr fileGuard(hFile, CloseHandleFunc);
|
2021-01-06 19:48:24 +01:00
|
|
|
result->reset(new WinRandomRWFile(
|
|
|
|
fname, hFile, std::max(GetSectorSize(fname), GetPageSize()), options));
|
2016-10-14 01:36:34 +02:00
|
|
|
fileGuard.release();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::NewMemoryMappedFileBuffer(
|
|
|
|
const std::string& fname, std::unique_ptr<MemoryMappedFileBuffer>* result) {
|
|
|
|
IOStatus s;
|
2018-05-25 00:05:00 +02:00
|
|
|
result->reset();
|
|
|
|
|
|
|
|
DWORD fileFlags = FILE_ATTRIBUTE_READONLY;
|
|
|
|
|
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2018-10-12 08:22:42 +02:00
|
|
|
hFile = RX_CreateFile(
|
2019-03-28 00:31:30 +01:00
|
|
|
RX_FN(fname).c_str(), GENERIC_READ | GENERIC_WRITE,
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
|
2019-03-28 00:31:30 +01:00
|
|
|
OPEN_EXISTING, // Open only if it exists
|
2021-01-06 19:48:24 +01:00
|
|
|
fileFlags, NULL);
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
2019-03-28 00:31:30 +01:00
|
|
|
s = IOErrorFromWindowsError(
|
|
|
|
"Failed to open NewMemoryMappedFileBuffer: " + fname, lastError);
|
2018-05-25 00:05:00 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
UniqueCloseHandlePtr fileGuard(hFile, CloseHandleFunc);
|
|
|
|
|
|
|
|
uint64_t fileSize = 0;
|
2021-01-06 19:48:24 +01:00
|
|
|
s = GetFileSize(fname, IOOptions(), &fileSize, nullptr);
|
2018-05-25 00:05:00 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
// Will not map empty files
|
|
|
|
if (fileSize == 0) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::NotSupported(
|
2019-03-28 00:31:30 +01:00
|
|
|
"NewMemoryMappedFileBuffer can not map zero length files: " + fname);
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// size_t is 32-bit with 32-bit builds
|
|
|
|
if (fileSize > std::numeric_limits<size_t>::max()) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::NotSupported(
|
|
|
|
"The specified file size does not fit into 32-bit memory addressing: " +
|
|
|
|
fname);
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
HANDLE hMap = RX_CreateFileMapping(hFile, NULL, PAGE_READWRITE,
|
2019-03-28 00:31:30 +01:00
|
|
|
0, // Whole file at its present length
|
|
|
|
0,
|
|
|
|
NULL); // Mapping name
|
2018-05-25 00:05:00 +02:00
|
|
|
|
|
|
|
if (!hMap) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"Failed to create file mapping for: " + fname, lastError);
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
|
|
|
UniqueCloseHandlePtr mapGuard(hMap, CloseHandleFunc);
|
|
|
|
|
|
|
|
void* base = MapViewOfFileEx(hMap, FILE_MAP_WRITE,
|
2019-03-28 00:31:30 +01:00
|
|
|
0, // High DWORD of access start
|
|
|
|
0, // Low DWORD
|
|
|
|
static_cast<SIZE_T>(fileSize),
|
|
|
|
NULL); // Let the OS choose the mapping
|
2018-05-25 00:05:00 +02:00
|
|
|
|
|
|
|
if (!base) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError(
|
2019-03-28 00:31:30 +01:00
|
|
|
"Failed to MapViewOfFile for NewMemoryMappedFileBuffer: " + fname,
|
|
|
|
lastError);
|
2018-05-25 00:05:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 00:31:30 +01:00
|
|
|
result->reset(new WinMemoryMappedBuffer(hFile, hMap, base,
|
|
|
|
static_cast<size_t>(fileSize)));
|
2018-05-25 00:05:00 +02:00
|
|
|
|
|
|
|
mapGuard.release();
|
|
|
|
fileGuard.release();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::NewDirectory(const std::string& name,
|
|
|
|
const IOOptions& /*options*/,
|
|
|
|
std::unique_ptr<FSDirectory>* result,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2016-05-20 01:40:54 +02:00
|
|
|
// Must be nullptr on failure
|
|
|
|
result->reset();
|
2018-03-06 20:47:42 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (!DirExists(name)) {
|
2021-01-06 19:48:24 +01:00
|
|
|
s = IOErrorFromWindowsError("open folder: " + name, ERROR_DIRECTORY);
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE handle = INVALID_HANDLE_VALUE;
|
|
|
|
// 0 - for access means read metadata
|
|
|
|
{
|
2016-05-20 01:40:54 +02:00
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2019-03-28 00:31:30 +01:00
|
|
|
handle = RX_CreateFile(
|
|
|
|
RX_FN(name).c_str(), 0,
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
2019-03-28 00:31:30 +01:00
|
|
|
OPEN_EXISTING,
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_FLAG_BACKUP_SEMANTICS, // make opening folders possible
|
2019-03-28 00:31:30 +01:00
|
|
|
NULL);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == handle) {
|
|
|
|
auto lastError = GetLastError();
|
2019-03-28 00:31:30 +01:00
|
|
|
s = IOErrorFromWindowsError("open folder: " + name, lastError);
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->reset(new WinDirectory(handle));
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::FileExists(const std::string& fname,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2018-03-06 20:47:42 +01:00
|
|
|
// TODO: This does not follow symbolic links at this point
|
|
|
|
// which is consistent with _access() impl on windows
|
|
|
|
// but can be added
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
2019-03-28 00:31:30 +01:00
|
|
|
if (FALSE == RX_GetFileAttributesEx(RX_FN(fname).c_str(),
|
|
|
|
GetFileExInfoStandard, &attrs)) {
|
2018-03-06 20:47:42 +01:00
|
|
|
auto lastError = GetLastError();
|
|
|
|
switch (lastError) {
|
2021-01-06 19:48:24 +01:00
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
case ERROR_NOT_FOUND:
|
|
|
|
case ERROR_FILE_NOT_FOUND:
|
|
|
|
case ERROR_PATH_NOT_FOUND:
|
|
|
|
s = IOStatus::NotFound();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s = IOErrorFromWindowsError("Unexpected error for: " + fname,
|
|
|
|
lastError);
|
|
|
|
break;
|
2018-03-06 20:47:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::GetChildren(const std::string& dir,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
std::vector<std::string>* result,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus status;
|
2017-01-10 00:37:57 +01:00
|
|
|
result->clear();
|
2016-05-20 01:40:54 +02:00
|
|
|
std::vector<std::string> output;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
RX_WIN32_FIND_DATA data;
|
|
|
|
memset(&data, 0, sizeof(data));
|
2018-03-06 20:47:42 +01:00
|
|
|
std::string pattern(dir);
|
|
|
|
pattern.append("\\").append("*");
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
HANDLE handle =
|
|
|
|
RX_FindFirstFileEx(RX_FN(pattern).c_str(),
|
|
|
|
// Do not want alternative name
|
|
|
|
FindExInfoBasic, &data, FindExSearchNameMatch,
|
|
|
|
NULL, // lpSearchFilter
|
|
|
|
0);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2018-03-06 20:47:42 +01:00
|
|
|
if (handle == INVALID_HANDLE_VALUE) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
switch (lastError) {
|
2021-01-06 19:48:24 +01:00
|
|
|
case ERROR_NOT_FOUND:
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
case ERROR_FILE_NOT_FOUND:
|
|
|
|
case ERROR_PATH_NOT_FOUND:
|
|
|
|
status = IOStatus::NotFound();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = IOErrorFromWindowsError("Failed to GetChhildren for: " + dir,
|
|
|
|
lastError);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2018-03-06 20:47:42 +01:00
|
|
|
return status;
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2016-04-30 01:43:13 +02:00
|
|
|
|
2018-03-06 20:47:42 +01:00
|
|
|
UniqueFindClosePtr fc(handle, FindCloseFunc);
|
|
|
|
|
|
|
|
if (result->capacity() > 0) {
|
|
|
|
output.reserve(result->capacity());
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2018-03-06 20:47:42 +01:00
|
|
|
// For safety
|
|
|
|
data.cFileName[MAX_PATH - 1] = 0;
|
|
|
|
|
|
|
|
while (true) {
|
2018-10-12 08:22:42 +02:00
|
|
|
auto x = RX_FILESTRING(data.cFileName, RX_FNLEN(data.cFileName));
|
|
|
|
output.emplace_back(FN_TO_RX(x));
|
2021-01-06 19:48:24 +01:00
|
|
|
BOOL ret = -RX_FindNextFile(handle, &data);
|
2018-03-06 20:47:42 +01:00
|
|
|
// If the function fails the return value is zero
|
|
|
|
// and non-zero otherwise. Not TRUE or FALSE.
|
|
|
|
if (ret == FALSE) {
|
|
|
|
// Posix does not care why we stopped
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
data.cFileName[MAX_PATH - 1] = 0;
|
|
|
|
}
|
|
|
|
output.swap(*result);
|
2016-05-20 01:40:54 +02:00
|
|
|
return status;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::CreateDir(const std::string& name,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
2018-10-12 08:22:42 +02:00
|
|
|
BOOL ret = RX_CreateDirectory(RX_FN(name).c_str(), NULL);
|
2018-03-06 20:47:42 +01:00
|
|
|
if (!ret) {
|
|
|
|
auto lastError = GetLastError();
|
2021-01-06 19:48:24 +01:00
|
|
|
result = IOErrorFromWindowsError("Failed to create a directory: " + name,
|
|
|
|
lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::CreateDirIfMissing(const std::string& name,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
2016-05-20 01:40:54 +02:00
|
|
|
|
2018-05-04 01:07:41 +02:00
|
|
|
if (DirExists(name)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
BOOL ret = RX_CreateDirectory(RX_FN(name).c_str(), NULL);
|
2018-03-06 20:47:42 +01:00
|
|
|
if (!ret) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
if (lastError != ERROR_ALREADY_EXISTS) {
|
2021-01-06 19:48:24 +01:00
|
|
|
result = IOErrorFromWindowsError("Failed to create a directory: " + name,
|
|
|
|
lastError);
|
2018-05-04 01:07:41 +02:00
|
|
|
} else {
|
2021-01-06 19:48:24 +01:00
|
|
|
result = IOStatus::IOError(name + ": exists but is not a directory");
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::DeleteDir(const std::string& name,
|
|
|
|
const IOOptions& /*options*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
2018-10-12 08:22:42 +02:00
|
|
|
BOOL ret = RX_RemoveDirectory(RX_FN(name).c_str());
|
2018-03-06 20:47:42 +01:00
|
|
|
if (!ret) {
|
|
|
|
auto lastError = GetLastError();
|
2021-01-06 19:48:24 +01:00
|
|
|
result =
|
|
|
|
IOErrorFromWindowsError("Failed to remove dir: " + name, lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::GetFileSize(const std::string& fname,
|
|
|
|
const IOOptions& /*opts*/, uint64_t* size,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2016-04-30 01:43:13 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
2019-03-28 00:31:30 +01:00
|
|
|
if (RX_GetFileAttributesEx(RX_FN(fname).c_str(), GetFileExInfoStandard,
|
|
|
|
&attrs)) {
|
2016-05-20 01:40:54 +02:00
|
|
|
ULARGE_INTEGER file_size;
|
|
|
|
file_size.HighPart = attrs.nFileSizeHigh;
|
|
|
|
file_size.LowPart = attrs.nFileSizeLow;
|
|
|
|
*size = file_size.QuadPart;
|
|
|
|
} else {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
s = IOErrorFromWindowsError("Can not get size for: " + fname, lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
2016-05-17 02:01:00 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
uint64_t WinFileSystem::FileTimeToUnixTime(const FILETIME& ftTime) {
|
2016-05-20 01:40:54 +02:00
|
|
|
const uint64_t c_FileTimePerSecond = 10000000U;
|
|
|
|
// UNIX epoch starts on 1970-01-01T00:00:00Z
|
|
|
|
// Windows FILETIME starts on 1601-01-01T00:00:00Z
|
|
|
|
// Therefore, we need to subtract the below number of seconds from
|
|
|
|
// the seconds that we obtain from FILETIME with an obvious loss of
|
|
|
|
// precision
|
|
|
|
const uint64_t c_SecondBeforeUnixEpoch = 11644473600U;
|
|
|
|
|
|
|
|
ULARGE_INTEGER li;
|
|
|
|
li.HighPart = ftTime.dwHighDateTime;
|
|
|
|
li.LowPart = ftTime.dwLowDateTime;
|
|
|
|
|
|
|
|
uint64_t result =
|
2021-01-06 19:48:24 +01:00
|
|
|
(li.QuadPart / c_FileTimePerSecond) - c_SecondBeforeUnixEpoch;
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::GetFileModificationTime(const std::string& fname,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
uint64_t* file_mtime,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2016-05-20 01:40:54 +02:00
|
|
|
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
2019-03-28 00:31:30 +01:00
|
|
|
if (RX_GetFileAttributesEx(RX_FN(fname).c_str(), GetFileExInfoStandard,
|
2021-01-06 19:48:24 +01:00
|
|
|
&attrs)) {
|
2016-05-20 01:40:54 +02:00
|
|
|
*file_mtime = FileTimeToUnixTime(attrs.ftLastWriteTime);
|
|
|
|
} else {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
s = IOErrorFromWindowsError(
|
2021-01-06 19:48:24 +01:00
|
|
|
"Can not get file modification time for: " + fname, lastError);
|
2016-05-20 01:40:54 +02:00
|
|
|
*file_mtime = 0;
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::RenameFile(const std::string& src,
|
|
|
|
const std::string& target,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
2015-08-27 03:51:18 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// rename() is not capable of replacing the existing file as on Linux
|
|
|
|
// so use OS API directly
|
2019-03-28 00:31:30 +01:00
|
|
|
if (!RX_MoveFileEx(RX_FN(src).c_str(), RX_FN(target).c_str(),
|
|
|
|
MOVEFILE_REPLACE_EXISTING)) {
|
2016-05-20 01:40:54 +02:00
|
|
|
DWORD lastError = GetLastError();
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
std::string text("Failed to rename: ");
|
|
|
|
text.append(src).append(" to: ").append(target);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
result = IOErrorFromWindowsError(text, lastError);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2015-08-27 03:51:18 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::LinkFile(const std::string& src,
|
|
|
|
const std::string& target,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
if (!RX_CreateHardLink(RX_FN(target).c_str(), RX_FN(src).c_str(), NULL)) {
|
2016-05-20 01:40:54 +02:00
|
|
|
DWORD lastError = GetLastError();
|
2018-09-14 19:12:30 +02:00
|
|
|
if (lastError == ERROR_NOT_SAME_DEVICE) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::NotSupported("No cross FS links allowed");
|
2018-09-14 19:12:30 +02:00
|
|
|
}
|
2015-10-27 22:44:16 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
std::string text("Failed to link: ");
|
|
|
|
text.append(src).append(" to: ").append(target);
|
2015-10-27 22:44:16 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
result = IOErrorFromWindowsError(text, lastError);
|
2015-10-27 22:44:16 +01:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2015-10-27 22:44:16 +01:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::NumFileLinks(const std::string& fname,
|
|
|
|
const IOOptions& /*opts*/, uint64_t* count,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
|
|
|
HANDLE handle =
|
|
|
|
RX_CreateFile(RX_FN(fname).c_str(), 0,
|
|
|
|
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
2018-08-09 23:21:35 +02:00
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == handle) {
|
|
|
|
auto lastError = GetLastError();
|
2018-08-23 19:04:10 +02:00
|
|
|
s = IOErrorFromWindowsError("NumFileLinks: " + fname, lastError);
|
2018-08-09 23:21:35 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
UniqueCloseHandlePtr handle_guard(handle, CloseHandleFunc);
|
|
|
|
FILE_STANDARD_INFO standard_info;
|
2018-08-23 19:04:10 +02:00
|
|
|
if (0 != GetFileInformationByHandleEx(handle, FileStandardInfo,
|
|
|
|
&standard_info,
|
|
|
|
sizeof(standard_info))) {
|
2018-08-09 23:21:35 +02:00
|
|
|
*count = standard_info.NumberOfLinks;
|
|
|
|
} else {
|
|
|
|
auto lastError = GetLastError();
|
2018-08-23 19:04:10 +02:00
|
|
|
s = IOErrorFromWindowsError("GetFileInformationByHandleEx: " + fname,
|
|
|
|
lastError);
|
2018-08-09 23:21:35 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::AreFilesSame(const std::string& first,
|
|
|
|
const std::string& second,
|
|
|
|
const IOOptions& /*opts*/, bool* res,
|
|
|
|
IODebugContext* /*dbg*/) {
|
2018-03-06 20:47:42 +01:00
|
|
|
// For MinGW builds
|
|
|
|
#if (_WIN32_WINNT == _WIN32_WINNT_VISTA)
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus s = IOStatus::NotSupported();
|
2018-03-06 20:47:42 +01:00
|
|
|
#else
|
|
|
|
assert(res != nullptr);
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus s;
|
2018-03-06 20:47:42 +01:00
|
|
|
if (res == nullptr) {
|
2021-01-06 19:48:24 +01:00
|
|
|
s = IOStatus::InvalidArgument("res");
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0 - for access means read metadata
|
2019-03-28 00:31:30 +01:00
|
|
|
HANDLE file_1 = RX_CreateFile(
|
|
|
|
RX_FN(first).c_str(), 0,
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
2019-03-28 00:31:30 +01:00
|
|
|
OPEN_EXISTING,
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_FLAG_BACKUP_SEMANTICS, // make opening folders possible
|
2019-03-28 00:31:30 +01:00
|
|
|
NULL);
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == file_1) {
|
|
|
|
auto lastError = GetLastError();
|
2019-03-28 00:31:30 +01:00
|
|
|
s = IOErrorFromWindowsError("open file: " + first, lastError);
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
UniqueCloseHandlePtr g_1(file_1, CloseHandleFunc);
|
|
|
|
|
2019-03-28 00:31:30 +01:00
|
|
|
HANDLE file_2 = RX_CreateFile(
|
|
|
|
RX_FN(second).c_str(), 0,
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_FLAG_BACKUP_SEMANTICS, // make opening folders possible
|
2019-03-28 00:31:30 +01:00
|
|
|
NULL);
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == file_2) {
|
|
|
|
auto lastError = GetLastError();
|
2019-03-28 00:31:30 +01:00
|
|
|
s = IOErrorFromWindowsError("open file: " + second, lastError);
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
UniqueCloseHandlePtr g_2(file_2, CloseHandleFunc);
|
|
|
|
|
|
|
|
FILE_ID_INFO FileInfo_1;
|
|
|
|
BOOL result = GetFileInformationByHandleEx(file_1, FileIdInfo, &FileInfo_1,
|
2019-03-28 00:31:30 +01:00
|
|
|
sizeof(FileInfo_1));
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
auto lastError = GetLastError();
|
2019-03-28 00:31:30 +01:00
|
|
|
s = IOErrorFromWindowsError("stat file: " + first, lastError);
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
FILE_ID_INFO FileInfo_2;
|
|
|
|
result = GetFileInformationByHandleEx(file_2, FileIdInfo, &FileInfo_2,
|
|
|
|
sizeof(FileInfo_2));
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
auto lastError = GetLastError();
|
2019-03-28 00:31:30 +01:00
|
|
|
s = IOErrorFromWindowsError("stat file: " + second, lastError);
|
2018-03-06 20:47:42 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FileInfo_1.VolumeSerialNumber == FileInfo_2.VolumeSerialNumber) {
|
2021-01-06 19:48:24 +01:00
|
|
|
*res =
|
|
|
|
(0 == memcmp(FileInfo_1.FileId.Identifier, FileInfo_2.FileId.Identifier,
|
|
|
|
sizeof(FileInfo_1.FileId.Identifier)));
|
2018-03-06 20:47:42 +01:00
|
|
|
} else {
|
|
|
|
*res = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::LockFile(const std::string& lockFname,
|
|
|
|
const IOOptions& /*opts*/, FileLock** lock,
|
|
|
|
IODebugContext* /*dbg*/) {
|
2016-05-20 01:40:54 +02:00
|
|
|
assert(lock != nullptr);
|
2015-10-27 22:44:16 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
*lock = NULL;
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus result;
|
2016-02-01 22:14:37 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// No-sharing, this is a LOCK file
|
|
|
|
const DWORD ExclusiveAccessON = 0;
|
2016-02-01 22:14:37 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// Obtain exclusive access to the LOCK file
|
|
|
|
// Previously, instead of NORMAL attr we set DELETE on close and that worked
|
|
|
|
// well except with fault_injection test that insists on deleting it.
|
|
|
|
HANDLE hFile = 0;
|
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2019-03-28 00:31:30 +01:00
|
|
|
hFile = RX_CreateFile(RX_FN(lockFname).c_str(),
|
2021-01-06 19:48:24 +01:00
|
|
|
(GENERIC_READ | GENERIC_WRITE), ExclusiveAccessON,
|
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
2016-02-01 22:14:37 +01:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
2021-01-06 19:48:24 +01:00
|
|
|
result = IOErrorFromWindowsError("Failed to create lock file: " + lockFname,
|
|
|
|
lastError);
|
2016-05-20 01:40:54 +02:00
|
|
|
} else {
|
|
|
|
*lock = new WinFileLock(hFile);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2015-07-13 21:11:05 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::UnlockFile(FileLock* lock, const IOOptions& /*opts*/,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus result;
|
2015-10-27 22:44:16 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
assert(lock != nullptr);
|
2016-02-01 22:14:37 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
delete lock;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return result;
|
|
|
|
}
|
2016-02-01 22:14:37 +01:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::GetTestDirectory(const IOOptions& opts,
|
|
|
|
std::string* result,
|
|
|
|
IODebugContext* dbg) {
|
2016-05-20 01:40:54 +02:00
|
|
|
std::string output;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
const char* env = getenv("TEST_TMPDIR");
|
|
|
|
if (env && env[0] != '\0') {
|
|
|
|
output = env;
|
|
|
|
} else {
|
|
|
|
env = getenv("TMP");
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (env && env[0] != '\0') {
|
|
|
|
output = env;
|
|
|
|
} else {
|
|
|
|
output = "c:\\tmp";
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2015-09-11 18:57:02 +02:00
|
|
|
}
|
2021-01-06 19:48:24 +01:00
|
|
|
CreateDir(output, opts, dbg);
|
2015-09-11 18:57:02 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
output.append("\\testrocksdb-");
|
2020-06-03 20:59:37 +02:00
|
|
|
output.append(std::to_string(GetCurrentProcessId()));
|
2015-10-27 22:44:16 +01:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
CreateDir(output, opts, dbg);
|
2016-05-17 02:01:00 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
output.swap(*result);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::OK();
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::NewLogger(const std::string& fname,
|
|
|
|
const IOOptions& /*opts*/,
|
|
|
|
std::shared_ptr<Logger>* result,
|
|
|
|
IODebugContext* /*dbg*/) {
|
|
|
|
IOStatus s;
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
result->reset();
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
HANDLE hFile = 0;
|
|
|
|
{
|
|
|
|
IOSTATS_TIMER_GUARD(open_nanos);
|
2018-10-12 08:22:42 +02:00
|
|
|
hFile = RX_CreateFile(
|
2019-03-28 00:31:30 +01:00
|
|
|
RX_FN(fname).c_str(), GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_DELETE, // In RocksDb log files are
|
|
|
|
// renamed and deleted before
|
|
|
|
// they are closed. This enables
|
|
|
|
// doing so.
|
|
|
|
NULL,
|
|
|
|
CREATE_ALWAYS, // Original fopen mode is "w"
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == hFile) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
s = IOErrorFromWindowsError("Failed to open LogFile" + fname, lastError);
|
|
|
|
} else {
|
|
|
|
{
|
|
|
|
// With log files we want to set the true creation time as of now
|
|
|
|
// because the system
|
|
|
|
// for some reason caches the attributes of the previous file that just
|
|
|
|
// been renamed from
|
|
|
|
// this name so auto_roll_logger_test fails
|
|
|
|
FILETIME ft;
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
// Set creation, last access and last write time to the same value
|
|
|
|
SetFileTime(hFile, &ft, &ft, &ft);
|
|
|
|
}
|
2021-01-06 19:48:24 +01:00
|
|
|
result->reset(new WinLogger(&WinEnvThreads::gettid, clock_, hFile));
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::IsDirectory(const std::string& path,
|
|
|
|
const IOOptions& /*opts*/, bool* is_dir,
|
|
|
|
IODebugContext* /*dbg*/) {
|
2020-04-17 23:36:51 +02:00
|
|
|
BOOL ret = RX_PathIsDirectory(RX_FN(path).c_str());
|
|
|
|
if (is_dir) {
|
|
|
|
*is_dir = ret ? true : false;
|
|
|
|
}
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::OK();
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
Status WinEnvIO::GetHostName(char* name, uint64_t len) {
|
|
|
|
Status s;
|
|
|
|
DWORD nSize = static_cast<DWORD>(
|
2021-01-06 19:48:24 +01:00
|
|
|
std::min<uint64_t>(len, std::numeric_limits<DWORD>::max()));
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
if (!::GetComputerNameA(name, &nSize)) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
s = IOErrorFromWindowsError("GetHostName", lastError);
|
|
|
|
} else {
|
|
|
|
name[nSize] = 0;
|
2015-09-11 18:57:02 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::GetAbsolutePath(const std::string& db_path,
|
|
|
|
const IOOptions& /*options*/,
|
|
|
|
std::string* output_path,
|
|
|
|
IODebugContext* dbg) {
|
2016-05-20 01:40:54 +02:00
|
|
|
// Check if we already have an absolute path
|
2018-03-06 20:47:42 +01:00
|
|
|
// For test compatibility we will consider starting slash as an
|
|
|
|
// absolute path
|
|
|
|
if ((!db_path.empty() && (db_path[0] == '\\' || db_path[0] == '/')) ||
|
2021-01-06 19:48:24 +01:00
|
|
|
!RX_PathIsRelative(RX_FN(db_path).c_str())) {
|
2016-05-20 01:40:54 +02:00
|
|
|
*output_path = db_path;
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::OK();
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
RX_FILESTRING result;
|
2018-03-06 20:47:42 +01:00
|
|
|
result.resize(MAX_PATH);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2018-03-06 20:47:42 +01:00
|
|
|
// Hopefully no changes the current directory while we do this
|
|
|
|
// however _getcwd also suffers from the same limitation
|
2018-10-12 08:22:42 +02:00
|
|
|
DWORD len = RX_GetCurrentDirectory(MAX_PATH, &result[0]);
|
2018-03-06 20:47:42 +01:00
|
|
|
if (len == 0) {
|
|
|
|
auto lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError("Failed to get current working directory",
|
2019-03-28 00:31:30 +01:00
|
|
|
lastError);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2018-03-06 20:47:42 +01:00
|
|
|
result.resize(len);
|
2018-10-12 08:22:42 +02:00
|
|
|
std::string res = FN_TO_RX(result);
|
2019-03-28 00:31:30 +01:00
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
res.swap(*output_path);
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::OK();
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
IOStatus WinFileSystem::GetFreeSpace(const std::string& path,
|
|
|
|
const IOOptions& /*options*/,
|
|
|
|
uint64_t* diskfree,
|
|
|
|
IODebugContext* /*dbg*/) {
|
2020-01-07 22:54:18 +01:00
|
|
|
assert(diskfree != nullptr);
|
|
|
|
ULARGE_INTEGER freeBytes;
|
|
|
|
BOOL f = RX_GetDiskFreeSpaceEx(RX_FN(path).c_str(), &freeBytes, NULL, NULL);
|
|
|
|
if (f) {
|
|
|
|
*diskfree = freeBytes.QuadPart;
|
2021-01-06 19:48:24 +01:00
|
|
|
return IOStatus::OK();
|
2020-01-07 22:54:18 +01:00
|
|
|
} else {
|
|
|
|
DWORD lastError = GetLastError();
|
|
|
|
return IOErrorFromWindowsError("Failed to get free space: " + path,
|
|
|
|
lastError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
FileOptions WinFileSystem::OptimizeForLogWrite(
|
|
|
|
const FileOptions& file_options, const DBOptions& db_options) const {
|
|
|
|
FileOptions optimized(file_options);
|
2018-05-25 00:05:00 +02:00
|
|
|
// These two the same as default optimizations
|
2016-05-20 01:40:54 +02:00
|
|
|
optimized.bytes_per_sync = db_options.wal_bytes_per_sync;
|
2017-10-31 21:49:25 +01:00
|
|
|
optimized.writable_file_max_buffer_size =
|
|
|
|
db_options.writable_file_max_buffer_size;
|
2018-05-25 00:05:00 +02:00
|
|
|
|
|
|
|
// This adversely affects %999 on windows
|
|
|
|
optimized.use_mmap_writes = false;
|
|
|
|
// Direct writes will produce a huge perf impact on
|
|
|
|
// Windows. Pre-allocate space for WAL.
|
|
|
|
optimized.use_direct_writes = false;
|
2016-05-20 01:40:54 +02:00
|
|
|
return optimized;
|
|
|
|
}
|
2016-05-17 02:01:00 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
FileOptions WinFileSystem::OptimizeForManifestWrite(
|
|
|
|
const FileOptions& options) const {
|
|
|
|
FileOptions optimized(options);
|
2016-05-20 01:40:54 +02:00
|
|
|
optimized.use_mmap_writes = false;
|
2018-05-25 00:05:00 +02:00
|
|
|
optimized.use_direct_reads = false;
|
|
|
|
return optimized;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
FileOptions WinFileSystem::OptimizeForManifestRead(
|
|
|
|
const FileOptions& file_options) const {
|
|
|
|
FileOptions optimized(file_options);
|
2018-05-25 00:05:00 +02:00
|
|
|
optimized.use_mmap_writes = false;
|
|
|
|
optimized.use_direct_reads = false;
|
2016-05-20 01:40:54 +02:00
|
|
|
return optimized;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true iff the named directory exists and is a directory.
|
2021-01-06 19:48:24 +01:00
|
|
|
bool WinFileSystem::DirExists(const std::string& dname) {
|
2016-05-20 01:40:54 +02:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
2021-01-06 19:48:24 +01:00
|
|
|
if (RX_GetFileAttributesEx(RX_FN(dname).c_str(), GetFileExInfoStandard,
|
|
|
|
&attrs)) {
|
2016-05-20 01:40:54 +02:00
|
|
|
return 0 != (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
2016-05-17 02:01:00 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
size_t WinFileSystem::GetSectorSize(const std::string& fname) {
|
2018-03-06 20:47:42 +01:00
|
|
|
size_t sector_size = kSectorSize;
|
|
|
|
|
2018-10-12 08:22:42 +02:00
|
|
|
if (RX_PathIsRelative(RX_FN(fname).c_str())) {
|
2018-03-06 20:47:42 +01:00
|
|
|
return sector_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain device handle
|
|
|
|
char devicename[7] = "\\\\.\\";
|
|
|
|
int erresult = strncat_s(devicename, sizeof(devicename), fname.c_str(), 2);
|
|
|
|
|
|
|
|
if (erresult) {
|
|
|
|
assert(false);
|
|
|
|
return sector_size;
|
|
|
|
}
|
|
|
|
|
2019-03-28 00:31:30 +01:00
|
|
|
HANDLE hDevice = CreateFile(devicename, 0, 0, nullptr, OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, nullptr);
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (hDevice == INVALID_HANDLE_VALUE) {
|
|
|
|
return sector_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
STORAGE_PROPERTY_QUERY spropertyquery;
|
|
|
|
spropertyquery.PropertyId = StorageAccessAlignmentProperty;
|
|
|
|
spropertyquery.QueryType = PropertyStandardQuery;
|
|
|
|
|
|
|
|
BYTE output_buffer[sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR)];
|
|
|
|
DWORD output_bytes = 0;
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
BOOL ret = DeviceIoControl(
|
|
|
|
hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &spropertyquery,
|
|
|
|
sizeof(spropertyquery), output_buffer,
|
|
|
|
sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR), &output_bytes, nullptr);
|
2018-03-06 20:47:42 +01:00
|
|
|
|
|
|
|
if (ret) {
|
2021-01-06 19:48:24 +01:00
|
|
|
sector_size = ((STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR*)output_buffer)
|
|
|
|
->BytesPerLogicalSector;
|
2018-03-06 20:47:42 +01:00
|
|
|
} else {
|
2021-01-06 19:48:24 +01:00
|
|
|
// many devices do not support StorageProcessAlignmentProperty. Any failure
|
|
|
|
// here and we fall back to logical alignment
|
2018-03-06 20:47:42 +01:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
DISK_GEOMETRY_EX geometry = {0};
|
|
|
|
ret = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, nullptr, 0,
|
|
|
|
&geometry, sizeof(geometry), &output_bytes, nullptr);
|
2018-03-06 20:47:42 +01:00
|
|
|
if (ret) {
|
|
|
|
sector_size = geometry.Geometry.BytesPerSector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hDevice != INVALID_HANDLE_VALUE) {
|
|
|
|
CloseHandle(hDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sector_size;
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// WinEnvThreads
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2019-03-28 00:31:30 +01:00
|
|
|
WinEnvThreads::WinEnvThreads(Env* hosted_env)
|
|
|
|
: hosted_env_(hosted_env), thread_pools_(Env::Priority::TOTAL) {
|
2016-05-20 01:40:54 +02:00
|
|
|
for (int pool_id = 0; pool_id < Env::Priority::TOTAL; ++pool_id) {
|
|
|
|
thread_pools_[pool_id].SetThreadPriority(
|
2021-01-06 19:48:24 +01:00
|
|
|
static_cast<Env::Priority>(pool_id));
|
2016-05-20 01:40:54 +02:00
|
|
|
// This allows later initializing the thread-local-env of each thread.
|
|
|
|
thread_pools_[pool_id].SetHostEnv(hosted_env);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
WinEnvThreads::~WinEnvThreads() {
|
|
|
|
WaitForJoin();
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
for (auto& thpool : thread_pools_) {
|
|
|
|
thpool.JoinAllThreads();
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
void WinEnvThreads::Schedule(void (*function)(void*), void* arg,
|
2019-03-28 00:31:30 +01:00
|
|
|
Env::Priority pri, void* tag,
|
2021-01-06 19:48:24 +01:00
|
|
|
void (*unschedFunction)(void* arg)) {
|
2017-08-09 02:16:14 +02:00
|
|
|
assert(pri >= Env::Priority::BOTTOM && pri <= Env::Priority::HIGH);
|
2016-05-20 01:40:54 +02:00
|
|
|
thread_pools_[pri].Schedule(function, arg, tag, unschedFunction);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
int WinEnvThreads::UnSchedule(void* arg, Env::Priority pri) {
|
|
|
|
return thread_pools_[pri].UnSchedule(arg);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
namespace {
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
struct StartThreadState {
|
|
|
|
void (*user_function)(void*);
|
|
|
|
void* arg;
|
|
|
|
};
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
void* StartThreadWrapper(void* arg) {
|
|
|
|
std::unique_ptr<StartThreadState> state(
|
2016-05-20 01:40:54 +02:00
|
|
|
reinterpret_cast<StartThreadState*>(arg));
|
2021-01-06 19:48:24 +01:00
|
|
|
state->user_function(state->arg);
|
|
|
|
return nullptr;
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void WinEnvThreads::StartThread(void (*function)(void* arg), void* arg) {
|
2016-05-20 01:40:54 +02:00
|
|
|
std::unique_ptr<StartThreadState> state(new StartThreadState);
|
|
|
|
state->user_function = function;
|
|
|
|
state->arg = arg;
|
|
|
|
try {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::port::WindowsThread th(&StartThreadWrapper, state.get());
|
2016-05-20 01:40:54 +02:00
|
|
|
state.release();
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
std::lock_guard<std::mutex> lg(mu_);
|
|
|
|
threads_to_join_.push_back(std::move(th));
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
} catch (const std::system_error& ex) {
|
|
|
|
WinthreadCall("start thread", ex.code());
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
void WinEnvThreads::WaitForJoin() {
|
|
|
|
for (auto& th : threads_to_join_) {
|
|
|
|
th.join();
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
2016-05-20 01:40:54 +02:00
|
|
|
threads_to_join_.clear();
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
unsigned int WinEnvThreads::GetThreadPoolQueueLen(Env::Priority pri) const {
|
2017-08-09 02:16:14 +02:00
|
|
|
assert(pri >= Env::Priority::BOTTOM && pri <= Env::Priority::HIGH);
|
2016-05-20 01:40:54 +02:00
|
|
|
return thread_pools_[pri].GetQueueLen();
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
uint64_t WinEnvThreads::gettid() {
|
|
|
|
uint64_t thread_id = GetCurrentThreadId();
|
|
|
|
return thread_id;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
uint64_t WinEnvThreads::GetThreadID() const { return gettid(); }
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
void WinEnvThreads::SetBackgroundThreads(int num, Env::Priority pri) {
|
2017-08-09 02:16:14 +02:00
|
|
|
assert(pri >= Env::Priority::BOTTOM && pri <= Env::Priority::HIGH);
|
2016-05-20 01:40:54 +02:00
|
|
|
thread_pools_[pri].SetBackgroundThreads(num);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2017-05-23 20:04:25 +02:00
|
|
|
int WinEnvThreads::GetBackgroundThreads(Env::Priority pri) {
|
2017-08-09 02:16:14 +02:00
|
|
|
assert(pri >= Env::Priority::BOTTOM && pri <= Env::Priority::HIGH);
|
2017-05-23 20:04:25 +02:00
|
|
|
return thread_pools_[pri].GetBackgroundThreads();
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
void WinEnvThreads::IncBackgroundThreadsIfNeeded(int num, Env::Priority pri) {
|
2017-08-09 02:16:14 +02:00
|
|
|
assert(pri >= Env::Priority::BOTTOM && pri <= Env::Priority::HIGH);
|
2016-05-20 01:40:54 +02:00
|
|
|
thread_pools_[pri].IncBackgroundThreadsIfNeeded(num);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// WinEnv
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
WinEnv::WinEnv()
|
|
|
|
: CompositeEnv(WinFileSystem::Default()),
|
|
|
|
winenv_io_(this),
|
|
|
|
winenv_threads_(this) {
|
2016-05-20 01:40:54 +02:00
|
|
|
// Protected member of the base class
|
2021-01-06 19:48:24 +01:00
|
|
|
clock_ = WinClock::Default();
|
2016-05-20 01:40:54 +02:00
|
|
|
thread_status_updater_ = CreateThreadStatusUpdater();
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
WinEnv::~WinEnv() {
|
|
|
|
// All threads must be joined before the deletion of
|
|
|
|
// thread_status_updater_.
|
|
|
|
delete thread_status_updater_;
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2019-03-28 00:31:30 +01:00
|
|
|
Status WinEnv::GetThreadList(std::vector<ThreadStatus>* thread_list) {
|
2016-05-20 01:40:54 +02:00
|
|
|
assert(thread_status_updater_);
|
|
|
|
return thread_status_updater_->GetThreadList(thread_list);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
Status WinEnv::GetCurrentTime(int64_t* unix_time) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return clock_->GetCurrentTime(unix_time);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2016-01-27 13:36:22 +01:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
uint64_t WinEnv::NowMicros() { return clock_->NowMicros(); }
|
2020-04-17 23:36:51 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
uint64_t WinEnv::NowNanos() { return clock_->NowNanos(); }
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
Status WinEnv::GetHostName(char* name, uint64_t len) {
|
|
|
|
return winenv_io_.GetHostName(name, len);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
std::string WinEnv::TimeToString(uint64_t secondsSince1970) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return clock_->TimeToString(secondsSince1970);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
void WinEnv::Schedule(void (*function)(void*), void* arg, Env::Priority pri,
|
|
|
|
void* tag, void (*unschedFunction)(void* arg)) {
|
2016-05-20 01:40:54 +02:00
|
|
|
return winenv_threads_.Schedule(function, arg, pri, tag, unschedFunction);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
int WinEnv::UnSchedule(void* arg, Env::Priority pri) {
|
|
|
|
return winenv_threads_.UnSchedule(arg, pri);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
void WinEnv::StartThread(void (*function)(void* arg), void* arg) {
|
2016-05-20 01:40:54 +02:00
|
|
|
return winenv_threads_.StartThread(function, arg);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
void WinEnv::WaitForJoin() { return winenv_threads_.WaitForJoin(); }
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
unsigned int WinEnv::GetThreadPoolQueueLen(Env::Priority pri) const {
|
2016-05-20 01:40:54 +02:00
|
|
|
return winenv_threads_.GetThreadPoolQueueLen(pri);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
uint64_t WinEnv::GetThreadID() const { return winenv_threads_.GetThreadID(); }
|
2020-01-07 22:54:18 +01:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
void WinEnv::SleepForMicroseconds(int micros) {
|
2021-01-06 19:48:24 +01:00
|
|
|
return clock_->SleepForMicroseconds(micros);
|
2016-05-20 01:40:54 +02:00
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
// Allow increasing the number of worker threads.
|
2021-01-06 19:48:24 +01:00
|
|
|
void WinEnv::SetBackgroundThreads(int num, Env::Priority pri) {
|
2016-05-20 01:40:54 +02:00
|
|
|
return winenv_threads_.SetBackgroundThreads(num, pri);
|
|
|
|
}
|
2015-07-02 01:13:49 +02:00
|
|
|
|
2017-05-23 20:04:25 +02:00
|
|
|
int WinEnv::GetBackgroundThreads(Env::Priority pri) {
|
|
|
|
return winenv_threads_.GetBackgroundThreads(pri);
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
void WinEnv::IncBackgroundThreadsIfNeeded(int num, Env::Priority pri) {
|
2016-05-20 01:40:54 +02:00
|
|
|
return winenv_threads_.IncBackgroundThreadsIfNeeded(num, pri);
|
2015-07-02 01:13:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:40:54 +02:00
|
|
|
} // namespace port
|
2015-07-02 01:13:49 +02:00
|
|
|
|
|
|
|
std::string Env::GenerateUniqueId() {
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
UUID uuid;
|
|
|
|
UuidCreateSequential(&uuid);
|
|
|
|
|
|
|
|
RPC_CSTR rpc_str;
|
2017-06-12 22:08:57 +02:00
|
|
|
auto status = UuidToStringA(&uuid, &rpc_str);
|
|
|
|
(void)status;
|
|
|
|
assert(status == RPC_S_OK);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
|
|
|
result = reinterpret_cast<char*>(rpc_str);
|
|
|
|
|
2017-06-12 22:08:57 +02:00
|
|
|
status = RpcStringFreeA(&rpc_str);
|
|
|
|
assert(status == RPC_S_OK);
|
2015-07-02 01:13:49 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:48:24 +01:00
|
|
|
std::shared_ptr<FileSystem> FileSystem::Default() {
|
|
|
|
return port::WinFileSystem::Default();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Env> NewCompositeEnv(const std::shared_ptr<FileSystem>& fs) {
|
|
|
|
return std::unique_ptr<Env>(new CompositeEnvWrapper(Env::Default(), fs));
|
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2020-09-23 21:54:29 +02:00
|
|
|
|
|
|
|
#endif
|