Implement getfreespace for WinEnv (#6265)

Summary:
A new interface method Env::GetFreeSpace was added in https://github.com/facebook/rocksdb/issues/4164. It needs to be implemented for Windows port. Some error_handler_test cases fail on Windows because recovery cannot succeed without free space being reported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6265

Differential Revision: D19303065

fbshipit-source-id: 1f1a83e53f334284781cf61feabc996e87b945ca
This commit is contained in:
Huisheng Liu 2020-01-07 13:54:18 -08:00 committed by Facebook Github Bot
parent a8b1085ae2
commit 2fdd8087ce
3 changed files with 32 additions and 0 deletions

View File

@ -1075,6 +1075,20 @@ std::string WinEnvIO::TimeToString(uint64_t secondsSince1970) {
return result; return result;
} }
Status WinEnvIO::GetFreeSpace(const std::string& path, uint64_t* diskfree) {
assert(diskfree != nullptr);
ULARGE_INTEGER freeBytes;
BOOL f = RX_GetDiskFreeSpaceEx(RX_FN(path).c_str(), &freeBytes, NULL, NULL);
if (f) {
*diskfree = freeBytes.QuadPart;
return Status::OK();
} else {
DWORD lastError = GetLastError();
return IOErrorFromWindowsError("Failed to get free space: " + path,
lastError);
}
}
EnvOptions WinEnvIO::OptimizeForLogWrite(const EnvOptions& env_options, EnvOptions WinEnvIO::OptimizeForLogWrite(const EnvOptions& env_options,
const DBOptions& db_options) const { const DBOptions& db_options) const {
EnvOptions optimized(env_options); EnvOptions optimized(env_options);
@ -1467,6 +1481,10 @@ uint64_t WinEnv::GetThreadID() const {
return winenv_threads_.GetThreadID(); return winenv_threads_.GetThreadID();
} }
Status WinEnv::GetFreeSpace(const std::string& path, uint64_t* diskfree) {
return winenv_io_.GetFreeSpace(path, diskfree);
}
void WinEnv::SleepForMicroseconds(int micros) { void WinEnv::SleepForMicroseconds(int micros) {
return winenv_threads_.SleepForMicroseconds(micros); return winenv_threads_.SleepForMicroseconds(micros);
} }

View File

@ -164,6 +164,12 @@ public:
virtual Status GetAbsolutePath(const std::string& db_path, virtual Status GetAbsolutePath(const std::string& db_path,
std::string* output_path); std::string* output_path);
// This seems to clash with a macro on Windows, so #undef it here
#undef GetFreeSpace
// Get the amount of free disk space
virtual Status GetFreeSpace(const std::string& path, uint64_t* diskfree);
virtual std::string TimeToString(uint64_t secondsSince1970); virtual std::string TimeToString(uint64_t secondsSince1970);
virtual EnvOptions OptimizeForLogWrite(const EnvOptions& env_options, virtual EnvOptions OptimizeForLogWrite(const EnvOptions& env_options,
@ -307,6 +313,12 @@ public:
uint64_t GetThreadID() const override; uint64_t GetThreadID() const override;
// This seems to clash with a macro on Windows, so #undef it here
#undef GetFreeSpace
// Get the amount of free disk space
Status GetFreeSpace(const std::string& path, uint64_t* diskfree) override;
void SleepForMicroseconds(int micros) override; void SleepForMicroseconds(int micros) override;
// Allow increasing the number of worker threads. // Allow increasing the number of worker threads.

View File

@ -363,6 +363,7 @@ std::wstring utf8_to_utf16(const std::string& utf8);
#define RX_CreateHardLink CreateHardLinkW #define RX_CreateHardLink CreateHardLinkW
#define RX_PathIsRelative PathIsRelativeW #define RX_PathIsRelative PathIsRelativeW
#define RX_GetCurrentDirectory GetCurrentDirectoryW #define RX_GetCurrentDirectory GetCurrentDirectoryW
#define RX_GetDiskFreeSpaceEx GetDiskFreeSpaceExW
#else #else
@ -386,6 +387,7 @@ std::wstring utf8_to_utf16(const std::string& utf8);
#define RX_CreateHardLink CreateHardLinkA #define RX_CreateHardLink CreateHardLinkA
#define RX_PathIsRelative PathIsRelativeA #define RX_PathIsRelative PathIsRelativeA
#define RX_GetCurrentDirectory GetCurrentDirectoryA #define RX_GetCurrentDirectory GetCurrentDirectoryA
#define RX_GetDiskFreeSpaceEx GetDiskFreeSpaceExA
#endif #endif