8000 backport free disk space bugfix from upstream rocksdb by jsteemann · Pull Request #14353 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

backport free disk space bugfix from upstream rocksdb #14353

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 2 commits into from
Jul 28, 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
v3.8.1 (XXXX-XX-XX)
-------------------

* 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.

* Fixed a problem with active failover, where a failover could take 5 mins
because the follower was caught in a bad state during replication. This fixes
BTS-425.
Expand Down
12 changes: 12 additions & 0 deletions arangod/RocksDBEngine/RocksDBEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ void RocksDBEngine::start() {
}
}

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: "
<< totalSpace << " bytes"
<< ", free disk space for database directory mount: "
<< freeSpace << " bytes"
<< " (" << (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