10000 backport free disk space bugfix from upstream rocksdb (#14353) · arangodb/arangodb@37e9b60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37e9b60

Browse files
jsteemannKVS85
andauthored
backport free disk space bugfix from upstream rocksdb (#14353)
Co-authored-by: Vadim <vadim@arangodb.com>
1 parent 69fa722 commit 37e9b60

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-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
v3.8.1 (XXXX-XX-XX)
22
-------------------
33

4+
* Backport bugfix from upstream rocksdb repository for calculating the free disk
5+
space for the database directory. Before the bugfix, rocksdb could
6+
overestimate the amount of free space when the arangod process was run as
7+
non-privileged users.
8+
49
* Fixed a problem with active failover, where a failover could take 5 mins
510
because the follower was caught in a bad state during replication. This fixes
611
BTS-425.

arangod/RocksDBEngine/RocksDBEngine.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ void RocksDBEngine::start() {
480480
}
481481
}
482482

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+
<< totalSpace << " bytes"
489+
<< ", free disk space for database directory mount: "
490+
<< freeSpace << " bytes"
491+
<< " (" << (100.0 * double(freeSpace) / double(totalSpace)) << "% free)";
492+
}
493+
494+
483495
// options imported set by RocksDBOptionFeature
484496
auto const& opts = server().getFeature<arangodb::RocksDBOptionFeature>();
485497

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