8000 Backport rocksdb diskspace bugfix (#14352) · arangodb/arangodb@d5be537 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5be537

Browse files
authored
Backport rocksdb diskspace bugfix (#14352)
* 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.
1 parent 6f73a6a commit d5be537

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

3rdParty/rocksdb/6.8/env/fs_posix.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,17 @@ class PosixFileSystem : public FileSystem {
832832
return IOError("While doing statvfs", fname, errno);
833833
}
834834

835-
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bfree);
835+
// sbuf.bfree is total free space available to root
836+
// sbuf.bavail is total free space available to unprivileged user
837+
// sbuf.bavail <= sbuf.bfree ... pick correct based upon effective user id
838+
if (geteuid()) {
839+
// non-zero user is unprivileged, or -1 if error. take more conservative
840+
// size
841+
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bavail);
842+
} else {
843+
// root user can access all disk space
844+
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bfree);
845+
}
836846
return IOStatus::OK();
837847
}
838848

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
devel
22
-----
33

4+
* Backport bugfix from upstream rocksdb repository for calculating the
5+
free disk space for the database directory. Before the bugfix, rocksdb
6+
could overestimate the amount of free space when the arangod process
7+
was run as non-privileged users.
8+
49
* Add soft coordinator shutdown: This is a new option `soft=true` for the
510
DELETE /_admin/shutdown API. Has only meaning for coordinators, otherwise
611
ignored. A number of things are allowed to finish but no new things are

arangod/RocksDBEngine/RocksDBEngine.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,17 @@ void RocksDBEngine::start() {
479479
FATAL_ERROR_EXIT();
480480
}
481481
}
482+
483+
uint64_t totalSpace;
484+
uint64_t freeSpace;
485+
if (TRI_GetDiskSpaceInfo(_path, totalSpace, freeSpace).ok() && totalSpace != 0) {
486+
LOG_TOPIC("b71b9", DEBUG, arangodb::Logger::ENGINES)
487+
<< "total disk space for database directory mount: "
488+
<< basics::StringUtils::formatSize(totalSpace)
489+
<< ", free disk space for database directory mount: "
490+
<< basics::StringUtils::formatSize(freeSpace)
491+
<< " (" << (100.0 * double(freeSpace) / double(totalSpace)) << "% free)";
492+
}
482493

483494
// options imported set by RocksDBOptionFeature
484495
auto const& opts = server().getFeature<arangodb::RocksDBOptionFeature>();

lib/Basics/files.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,8 +2643,18 @@ arangodb::Result TRI_GetDiskSpaceInfo(std::string const& path,
26432643
TRI_set_errno(TRI_ERROR_SYS_ERROR);
26442644
return {TRI_errno(), TRI_last_error()};
26452645
}
2646-
totalSpace = static_cast<uint64_t>(stat.f_frsize) * static_cast<uint64_t>(stat.f_blocks);
2647-
freeSpace = static_cast<uint64_t>(stat.f_frsize) * static_cast<uint64_t>(stat.f_bfree);
2646+
totalSpace = static_cast<uint64_t>(stat.f_bsize) * static_cast<uint64_t>(stat.f_blocks);
2647+
2648+
// sbuf.bfree is total free space available to root
2649+
// sbuf.bavail is total free space available to unprivileged user
2650+
// sbuf.bavail <= sbuf.bfree ... pick correct based upon effective user id
2651+
if (geteuid()) {
2652+
// non-zero user is unprivileged, or -1 if error. take more conservative size
2653+
freeSpace = static_cast<uint64_t>(stat.f_bsize) * static_cast<uint64_t>(stat.f_bavail);
2654+
} else {
2655+
// root user can access all disk space
2656+
freeSpace = static_cast<uint64_t>(stat.f_bsize) * static_cast<uint64_t>(stat.f_bfree);
2657+
}
26482658
#endif
26492659
return {};
26502660
}

0 commit comments

Comments
 (0)
0