8000 Backport rocksdb diskspace bugfix by jsteemann · Pull Request #14352 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Backport rocksdb diskspace bugfix #14352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 3rdParty/rocksdb/6.8/env/fs_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,17 @@ class PosixFileSystem : public FileSystem {
return IOError("While doing statvfs", fname, errno);
}

*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bfree);
// sbuf.bfree is total free space available to root
// sbuf.bavail is total free space available to unprivileged user
// sbuf.bavail <= sbuf.bfree ... pick correct based upon effective user id
if (geteuid()) {
// non-zero user is unprivileged, or -1 if error. take more conservative
// size
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bavail);
} else {
// root user can access all disk space
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bfree);
}
return IOStatus::OK();
}

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG
10000
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
devel
-----

* Backport bugfix from upstream rocksdb repository for calculating the
free disk space for the database directory. Before the bugfix, rocksdb
could overestimate the amount of free space when the arangod process
was run as non-privileged users.

* Add soft coordinator shutdown: This is a new option `soft=true` for the
DELETE /_admin/shutdown API. Has only meaning for coordinators, otherwise
ignored. A number of things are allowed to finish but no new things are
Expand Down
11 changes: 11 additions & 0 deletions arangod/RocksDBEngine/RocksDBEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@ void RocksDBEngine::start() {
FATAL_ERROR_EXIT();
}
}

uint64_t totalSpace;
uint64_t freeSpace;
if (TRI_GetDiskSpaceInfo(_path, totalSpace, freeSpace).ok() && totalSpace != 0) {
LOG_TOPIC("b71b9", DEBUG, arangodb::Logger::ENGINES)
<< "total disk space for database directory mount: "
<< basics::StringUtils::formatSize(totalSpace)
<< ", free disk space for database directory mount: "
<< basics::StringUtils::formatSize(freeSpace)
<< " (" << (100.0 * double(freeSpace) / double(totalSpace)) << "% free)";
}

// options imported set by RocksDBOptionFeature
auto const& opts = server().getFeature<arangodb::RocksDBOptionFeature>();
Expand Down
14 changes: 12 additions & 2 deletions lib/Basics/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2643,8 +2643,18 @@ arangodb::Result TRI_GetDiskSpaceInfo(std::string const& path,
TRI_set_errno(TRI_ERROR_SYS_ERROR);
return {TRI_errno(), TRI_last_error()};
}
totalSpace = static_cast<uint64_t>(stat.f_frsize) * static_cast<uint64_t>(stat.f_blocks);
freeSpace = static_cast<uint64_t>(stat.f_frsize) * static_cast<uint64_t>(stat.f_bfree);
totalSpace = static_cast<uint64_t>(stat.f_bsize) * static_cast<uint64_t>(stat.f_blocks);

// sbuf.bfree is total free space available to root
// sbuf.bavail is total free space available to unprivileged user
// sbuf.bavail <= sbuf.bfree ... pick correct based upon effective user id
if (geteuid()) {
// non-zero user is unprivileged, or -1 if error. take more conservative size
freeSpace = static_cast<uint64_t>(stat.f_bsize) * static_cast<uint64_t>(stat.f_bavail);
} else {
// root user can access all disk space
freeSpace = static_cast<uint64_t>(stat.f_bsize) * static_cast<uint64_t>(stat.f_bfree);
}
#endif
return {};
}
Expand Down
0