This is an automated email from the ASF dual-hosted git repository.
lihaopeng pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 326b40cde2f [branch-2.1](memory) Add HTTP API to clear data cache
(#37704)
326b40cde2f is described below
commit 326b40cde2f67f7df08a5791fd40a04b5f878c61
Author: Xinyi Zou <[email protected]>
AuthorDate: Fri Jul 12 17:21:52 2024 +0800
[branch-2.1](memory) Add HTTP API to clear data cache (#37704)
pick #36599
Co-authored-by: Gabriel <[email protected]>
---
be/src/http/action/clear_cache_action.cpp | 39 +++++++++++++++++++++++++++++++
be/src/http/action/clear_cache_action.h | 35 +++++++++++++++++++++++++++
be/src/runtime/memory/cache_manager.cpp | 7 ++++++
be/src/runtime/memory/cache_manager.h | 1 +
be/src/service/http_service.cpp | 6 +++++
5 files changed, 88 insertions(+)
diff --git a/be/src/http/action/clear_cache_action.cpp
b/be/src/http/action/clear_cache_action.cpp
new file mode 100644
index 00000000000..f42499090c4
--- /dev/null
+++ b/be/src/http/action/clear_cache_action.cpp
@@ -0,0 +1,39 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "http/action/clear_cache_action.h"
+
+#include <sstream>
+#include <string>
+
+#include "http/http_channel.h"
+#include "http/http_headers.h"
+#include "http/http_request.h"
+#include "http/http_status.h"
+#include "runtime/memory/cache_manager.h"
+
+namespace doris {
+
+const static std::string HEADER_JSON = "application/json";
+
+void ClearDataCacheAction::handle(HttpRequest* req) {
+ req->add_output_header(HttpHeaders::CONTENT_TYPE, "text/plain;
version=0.0.4");
+ CacheManager::instance()->clear_once();
+ HttpChannel::send_reply(req, HttpStatus::OK, "");
+}
+
+} // end namespace doris
diff --git a/be/src/http/action/clear_cache_action.h
b/be/src/http/action/clear_cache_action.h
new file mode 100644
index 00000000000..3840f63593f
--- /dev/null
+++ b/be/src/http/action/clear_cache_action.h
@@ -0,0 +1,35 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include "http/http_handler.h"
+
+namespace doris {
+
+class HttpRequest;
+
+class ClearDataCacheAction : public HttpHandler {
+public:
+ ClearDataCacheAction() = default;
+
+ ~ClearDataCacheAction() override = default;
+
+ void handle(HttpRequest* req) override;
+};
+
+} // end namespace doris
diff --git a/be/src/runtime/memory/cache_manager.cpp
b/be/src/runtime/memory/cache_manager.cpp
index d17954ffe8b..9bf3d1e12d0 100644
--- a/be/src/runtime/memory/cache_manager.cpp
+++ b/be/src/runtime/memory/cache_manager.cpp
@@ -56,6 +56,13 @@ int64_t
CacheManager::for_each_cache_prune_all(RuntimeProfile* profile) {
return 0;
}
+void CacheManager::clear_once() {
+ std::lock_guard<std::mutex> l(_caches_lock);
+ for (const auto& pair : _caches) {
+ pair.second->prune_all(true);
+ }
+}
+
void CacheManager::clear_once(CachePolicy::CacheType type) {
std::lock_guard<std::mutex> l(_caches_lock);
_caches[type]->prune_all(true); // will print log
diff --git a/be/src/runtime/memory/cache_manager.h
b/be/src/runtime/memory/cache_manager.h
index c4d8c7bb6f3..20372366aa1 100644
--- a/be/src/runtime/memory/cache_manager.h
+++ b/be/src/runtime/memory/cache_manager.h
@@ -66,6 +66,7 @@ public:
int64_t for_each_cache_prune_all(RuntimeProfile* profile = nullptr);
+ void clear_once();
void clear_once(CachePolicy::CacheType type);
bool need_prune(int64_t* last_timestamp, const std::string& type) {
diff --git a/be/src/service/http_service.cpp b/be/src/service/http_service.cpp
index 695153f697e..f9d873fc5bb 100644
--- a/be/src/service/http_service.cpp
+++ b/be/src/service/http_service.cpp
@@ -31,6 +31,7 @@
#include "http/action/check_rpc_channel_action.h"
#include "http/action/check_tablet_segment_action.h"
#include "http/action/checksum_action.h"
+#include "http/action/clear_cache_action.h"
#include "http/action/compaction_action.h"
#include "http/action/config_action.h"
#include "http/action/debug_point_action.h"
@@ -179,6 +180,11 @@ Status HttpService::start() {
HealthAction* health_action = _pool.add(new HealthAction());
_ev_http_server->register_handler(HttpMethod::GET, "/api/health",
health_action);
+ // Dump all running pipeline tasks
+ ClearDataCacheAction* clear_data_cache_action = _pool.add(new
ClearDataCacheAction());
+ _ev_http_server->register_handler(HttpMethod::GET, "/api/clear_data_cache",
+ clear_data_cache_action);
+
// Dump all running pipeline tasks
PipelineTaskAction* pipeline_task_action = _pool.add(new
PipelineTaskAction());
_ev_http_server->register_handler(HttpMethod::GET,
"/api/running_pipeline_tasks",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]