gavinchou commented on code in PR #51711:
URL: https://github.com/apache/doris/pull/51711#discussion_r2145047213


##########
be/src/io/cache/block_file_cache_factory.cpp:
##########
@@ -174,16 +171,52 @@ std::vector<std::string> 
FileCacheFactory::get_base_paths() {
     return paths;
 }
 
+std::string validate_capacity(const std::string& path, int64_t new_capacity,
+                              int64_t& valid_capacity) {
+    struct statfs stat;
+    if (statfs(path.c_str(), &stat) < 0) {
+        auto ret = fmt::format("reset capacity {} statfs error {}. ", path, 
strerror(errno));
+        LOG_ERROR(ret);
+        return ret;
+    }
+    size_t disk_capacity = 
static_cast<size_t>(static_cast<size_t>(stat.f_blocks) *
+                                               
static_cast<size_t>(stat.f_bsize));
+    if (new_capacity == 0 || disk_capacity < new_capacity) {
+        auto ret = fmt::format(
+                "The cache {} config size {} is larger than disk size {} or 
zero, recalc "
+                "it to disk size. ",
+                path, new_capacity, disk_capacity);
+        valid_capacity = disk_capacity;
+        LOG_WARNING(ret);
+        return ret;
+    }
+    valid_capacity = new_capacity;
+    return "";
+}
+
 std::string FileCacheFactory::reset_capacity(const std::string& path, int64_t 
new_capacity) {
+    std::stringstream ss;
+    size_t total_capacity = 0;
     if (path.empty()) {
-        std::stringstream ss;
-        for (auto& [_, cache] : _path_to_cache) {
-            ss << cache->reset_capacity(new_capacity);
+        for (auto& [p, cache] : _path_to_cache) {
+            int64_t valid_capacity;
+            ss << validate_capacity(p, new_capacity, valid_capacity);

Review Comment:
   if `validate_capacity` return error like "statfs error", we should not 
proceed.



##########
be/src/io/cache/block_file_cache_factory.cpp:
##########
@@ -174,16 +171,52 @@ std::vector<std::string> 
FileCacheFactory::get_base_paths() {
     return paths;
 }
 
+std::string validate_capacity(const std::string& path, int64_t new_capacity,
+                              int64_t& valid_capacity) {
+    struct statfs stat;
+    if (statfs(path.c_str(), &stat) < 0) {
+        auto ret = fmt::format("reset capacity {} statfs error {}. ", path, 
strerror(errno));
+        LOG_ERROR(ret);
+        return ret;
+    }
+    size_t disk_capacity = 
static_cast<size_t>(static_cast<size_t>(stat.f_blocks) *
+                                               
static_cast<size_t>(stat.f_bsize));
+    if (new_capacity == 0 || disk_capacity < new_capacity) {
+        auto ret = fmt::format(
+                "The cache {} config size {} is larger than disk size {} or 
zero, recalc "
+                "it to disk size. ",
+                path, new_capacity, disk_capacity);
+        valid_capacity = disk_capacity;
+        LOG_WARNING(ret);
+        return ret;
+    }
+    valid_capacity = new_capacity;
+    return "";
+}
+
 std::string FileCacheFactory::reset_capacity(const std::string& path, int64_t 
new_capacity) {
+    std::stringstream ss;
+    size_t total_capacity = 0;
     if (path.empty()) {
-        std::stringstream ss;
-        for (auto& [_, cache] : _path_to_cache) {
-            ss << cache->reset_capacity(new_capacity);
+        for (auto& [p, cache] : _path_to_cache) {
+            int64_t valid_capacity;
+            ss << validate_capacity(p, new_capacity, valid_capacity);
+            ss << cache->reset_capacity(valid_capacity);
+            total_capacity += cache->capacity();
         }
+        _capacity = total_capacity;
         return ss.str();
     } else {
         if (auto iter = _path_to_cache.find(path); iter != 
_path_to_cache.end()) {
-            return iter->second->reset_capacity(new_capacity);
+            int64_t valid_capacity;
+            ss << validate_capacity(path, new_capacity, valid_capacity);

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to