be/src/service/http/action/clear_cache_action.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "service/http/action/clear_cache_action.h" |
19 | | |
20 | | #include <sstream> |
21 | | #include <string> |
22 | | |
23 | | #include "runtime/memory/cache_manager.h" |
24 | | #include "service/http/http_channel.h" |
25 | | #include "service/http/http_headers.h" |
26 | | #include "service/http/http_request.h" |
27 | | #include "service/http/http_status.h" |
28 | | |
29 | | namespace doris { |
30 | | |
31 | 0 | void ClearCacheAction::handle(HttpRequest* req) { |
32 | 0 | req->add_output_header(HttpHeaders::CONTENT_TYPE, "text/plain; version=0.0.4"); |
33 | 0 | std::string cache_type_str = req->param("type"); |
34 | 0 | fmt::memory_buffer return_string_buffer; |
35 | 0 | int64_t freed_size = 0; |
36 | 0 | if (cache_type_str == "all") { |
37 | 0 | freed_size = CacheManager::instance()->for_each_cache_prune_all(nullptr, true); |
38 | 0 | } else { |
39 | 0 | CachePolicy::CacheType cache_type = CachePolicy::string_to_type(cache_type_str); |
40 | 0 | if (cache_type == CachePolicy::CacheType::NONE) { |
41 | 0 | fmt::format_to(return_string_buffer, |
42 | 0 | "ClearCacheAction not match type:{} of cache policy", cache_type_str); |
43 | 0 | LOG(WARNING) << fmt::to_string(return_string_buffer); |
44 | 0 | HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, |
45 | 0 | fmt::to_string(return_string_buffer)); |
46 | 0 | return; |
47 | 0 | } |
48 | 0 | freed_size = CacheManager::instance()->cache_prune_all(cache_type, true); |
49 | 0 | if (freed_size == -1) { |
50 | 0 | fmt::format_to(return_string_buffer, |
51 | 0 | "ClearCacheAction cache:{} is not allowed to be pruned", cache_type_str); |
52 | 0 | LOG(WARNING) << fmt::to_string(return_string_buffer); |
53 | 0 | HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, |
54 | 0 | fmt::to_string(return_string_buffer)); |
55 | 0 | return; |
56 | 0 | } |
57 | 0 | } |
58 | 0 | fmt::format_to(return_string_buffer, "ClearCacheAction cache:{} prune win, freed size {}", |
59 | 0 | cache_type_str, freed_size); |
60 | | LOG(WARNING) << fmt::to_string(return_string_buffer); |
61 | 0 | HttpChannel::send_reply(req, HttpStatus::OK, fmt::to_string(return_string_buffer)); |
62 | 0 | } |
63 | | |
64 | | } // end namespace doris |