Skip to content

Commit

Permalink
[improve] Refactor block file cache and add more ut case
Browse files Browse the repository at this point in the history
  • Loading branch information
Lchangliang committed Jan 16, 2024
1 parent 0ae9fa1 commit afaa817
Show file tree
Hide file tree
Showing 48 changed files with 7,272 additions and 4,033 deletions.
18 changes: 6 additions & 12 deletions be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,20 +984,14 @@ DEFINE_Bool(enable_file_cache, "false");
// format: [{"path":"/path/to/file_cache","total_size":21474836480,"query_limit":10737418240}]
// format: [{"path":"/path/to/file_cache","total_size":21474836480,"query_limit":10737418240},{"path":"/path/to/file_cache2","total_size":21474836480,"query_limit":10737418240}]
DEFINE_String(file_cache_path, "");
DEFINE_Int64(file_cache_max_file_segment_size, "4194304"); // 4MB
// 4KB <= file_cache_max_file_segment_size <= 256MB
DEFINE_Validator(file_cache_max_file_segment_size, [](const int64_t config) -> bool {
return config >= 4096 && config <= 268435456;
});
DEFINE_Int64(file_cache_min_file_segment_size, "1048576"); // 1MB
// 4KB <= file_cache_min_file_segment_size <= 256MB
DEFINE_Validator(file_cache_min_file_segment_size, [](const int64_t config) -> bool {
return config >= 4096 && config <= 268435456 &&
config <= config::file_cache_max_file_segment_size;
});
DEFINE_Int64(file_cache_each_block_size, "1048576"); // 1MB
// DEFINE_Validator(file_cache_each_block_size, [](const int64_t config) -> bool {
// return config <= config::s3_write_buffer_size && config::s3_write_buffer_size % config == 0;
// });
DEFINE_Bool(clear_file_cache, "false");
DEFINE_Bool(enable_file_cache_query_limit, "false");
DEFINE_mInt32(file_cache_wait_sec_after_fail, "0"); // // zero for no waiting and retrying
DEFINE_mInt32(file_cache_enter_disk_resource_limit_mode_percent, "90");
DEFINE_mInt32(file_cache_exit_disk_resource_limit_mode_percent, "80");

DEFINE_mInt32(index_cache_entry_stay_time_after_lookup_s, "1800");
DEFINE_mInt32(inverted_index_cache_stale_sweep_time_sec, "600");
Expand Down
9 changes: 5 additions & 4 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,13 @@ DECLARE_Bool(enable_file_cache);
// format: [{"path":"/path/to/file_cache","total_size":21474836480,"query_limit":10737418240},{"path":"/path/to/file_cache2","total_size":21474836480,"query_limit":10737418240}]
// format: [{"path":"/path/to/file_cache","total_size":21474836480,"query_limit":10737418240,"normal_percent":85, "disposable_percent":10, "index_percent":5}]
DECLARE_String(file_cache_path);
DECLARE_Int64(file_cache_min_file_segment_size);
DECLARE_Int64(file_cache_max_file_segment_size);
DECLARE_Int64(file_cache_each_block_size);
DECLARE_Bool(clear_file_cache);
DECLARE_Bool(enable_file_cache_query_limit);
// only for debug, will be removed after finding out the root cause
DECLARE_mInt32(file_cache_wait_sec_after_fail); // zero for no waiting and retrying
// default enter disk resource limit mode 5%
DECLARE_Int32(file_cache_enter_disk_resource_limit_mode_percent);
// default exit disk resource limit mode 20%
DECLARE_Int32(file_cache_exit_disk_resource_limit_mode_percent);

// inverted index searcher cache
// cache entry stay time after lookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,27 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// This file is copied from
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Interpreters/Cache/FileCacheSettings.h
// and modified by Doris

#pragma once
#include "http/action/clear_file_cache_action.h"

#include <array>
#include <fmt/core.h>

#include "io/cache/block/block_file_cache_fwd.h"
#include "http/http_channel.h"
#include "http/http_request.h"
#include "io/cache/block_file_cache_factory.h"

namespace doris {
namespace io {

struct FileCacheSettings {
size_t total_size {0};
size_t disposable_queue_size {0};
size_t disposable_queue_elements {0};
size_t index_queue_size {0};
size_t index_queue_elements {0};
size_t query_queue_size {0};
size_t query_queue_elements {0};
size_t max_file_segment_size {0};
size_t max_query_cache_size {0};
};
const std::string SYNC = "sync";

void ClearFileCacheAction::handle(HttpRequest* req) {
std::string sync = req->param(SYNC);
if (sync == "TRUE") {
io::FileCacheFactory::instance()->clear_file_caches(true);
} else {
io::FileCacheFactory::instance()->clear_file_caches(false);
}
HttpChannel::send_reply(req, HttpStatus::OK, Status::OK().to_json());
}

} // namespace io
} // namespace doris
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// This file is copied from
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Interpreters/Cache/FileCache_fwd.h
// and modified by Doris

#pragma once
#include <memory>

#include "vec/common/uint128.h"
#include "http/http_handler.h"

static constexpr size_t GB = 1 * 1024 * 1024 * 1024;
static constexpr size_t KB = 1024;
namespace doris {
namespace io {
class ExecEnv;
class ClearFileCacheAction : public HttpHandler {
public:
ClearFileCacheAction() = default;

using uint128_t = vectorized::UInt128;
using UInt128Hash = vectorized::UInt128Hash;
static constexpr size_t REMOTE_FS_OBJECTS_CACHE_DEFAULT_ELEMENTS = 100 * 1024;
~ClearFileCacheAction() override = default;

} // namespace io
void handle(HttpRequest* req) override;
};
} // namespace doris
2 changes: 1 addition & 1 deletion be/src/http/action/file_cache_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "http/http_headers.h"
#include "http/http_request.h"
#include "http/http_status.h"
#include "io/cache/block/block_file_cache_factory.h"
#include "io/cache/block_file_cache_factory.h"
#include "olap/olap_define.h"
#include "olap/tablet_meta.h"
#include "util/easy_json.h"
Expand Down
229 changes: 0 additions & 229 deletions be/src/io/cache/block/block_file_cache.cpp

This file was deleted.

Loading

0 comments on commit afaa817

Please sign in to comment.