mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-28 15:33:54 +00:00
Fix integer overflow in GetL0ThresholdSpeedupCompaction (#1378)
This commit is contained in:
parent
f83cd64c0b
commit
99c052a34f
|
@ -542,14 +542,34 @@ int GetL0ThresholdSpeedupCompaction(int level0_file_num_compaction_trigger,
|
||||||
// SanitizeOptions() ensures it.
|
// SanitizeOptions() ensures it.
|
||||||
assert(level0_file_num_compaction_trigger <= level0_slowdown_writes_trigger);
|
assert(level0_file_num_compaction_trigger <= level0_slowdown_writes_trigger);
|
||||||
|
|
||||||
|
if (level0_file_num_compaction_trigger < 0) {
|
||||||
|
return std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int twice_level0_trigger = level0_file_num_compaction_trigger * 2;
|
||||||
|
|
||||||
|
// overflow protection
|
||||||
|
if (twice_level0_trigger < 0) {
|
||||||
|
return std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
// 1/4 of the way between L0 compaction trigger threshold and slowdown
|
// 1/4 of the way between L0 compaction trigger threshold and slowdown
|
||||||
// condition.
|
// condition.
|
||||||
|
const int one_fourth_trigger_slowdown =
|
||||||
|
level0_file_num_compaction_trigger +
|
||||||
|
((level0_slowdown_writes_trigger - level0_file_num_compaction_trigger) /
|
||||||
|
4);
|
||||||
|
|
||||||
|
// overflow protection
|
||||||
|
if (one_fourth_trigger_slowdown < 0) {
|
||||||
|
return std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(twice_level0_trigger >= 0);
|
||||||
|
assert(one_fourth_trigger_slowdown >= 0);
|
||||||
|
|
||||||
// Or twice as compaction trigger, if it is smaller.
|
// Or twice as compaction trigger, if it is smaller.
|
||||||
return std::min(level0_file_num_compaction_trigger * 2,
|
return std::min(twice_level0_trigger, one_fourth_trigger_slowdown);
|
||||||
level0_file_num_compaction_trigger +
|
|
||||||
(level0_slowdown_writes_trigger -
|
|
||||||
level0_file_num_compaction_trigger) /
|
|
||||||
4);
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace port {
|
||||||
std::string GetWindowsErrSz(DWORD err);
|
std::string GetWindowsErrSz(DWORD err);
|
||||||
|
|
||||||
inline Status IOErrorFromWindowsError(const std::string& context, DWORD err) {
|
inline Status IOErrorFromWindowsError(const std::string& context, DWORD err) {
|
||||||
return (err == ERROR_HANDLE_DISK_FULL) ?
|
return ((err == ERROR_HANDLE_DISK_FULL) || (err == ERROR_DISK_FULL)) ?
|
||||||
Status::NoSpace(context, GetWindowsErrSz(err)) :
|
Status::NoSpace(context, GetWindowsErrSz(err)) :
|
||||||
Status::IOError(context, GetWindowsErrSz(err));
|
Status::IOError(context, GetWindowsErrSz(err));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue