diff --git a/presto-native-execution/presto_cpp/main/PrestoServerOperations.cpp b/presto-native-execution/presto_cpp/main/PrestoServerOperations.cpp index ead1eed679063..0983b5bf3b63f 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServerOperations.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoServerOperations.cpp @@ -14,6 +14,8 @@ #include "presto_cpp/main/PrestoServerOperations.h" #include #include +#include +#include #include #include "presto_cpp/main/PrestoServer.h" #include "presto_cpp/main/ServerOperation.h" @@ -250,6 +252,10 @@ std::string PrestoServerOperations::serverOperation( return serverOperationSetState(message); case ServerOperation::Action::kAnnouncer: return serverOperationAnnouncer(message); + case ServerOperation::Action::kClearCache: + return serverOperationClearCache(message); + case ServerOperation::Action::kWriteSSD: + return serverOperationWriteSsd(message); default: break; } @@ -310,4 +316,60 @@ std::string PrestoServerOperations::serverOperationAnnouncer( return "No PrestoServer to change announcer of (it is nullptr)."; } +std::string PrestoServerOperations::serverOperationClearCache( + proxygen::HTTPMessage* message) { + static const std::string kMemoryCacheType = "memory"; + static const std::string kServerCacheType = "ssd"; + + std::string type = message->getQueryParam("type"); + if (type.empty()) { + type = kMemoryCacheType; + } + if (type != kMemoryCacheType && type != kServerCacheType) { + VELOX_USER_FAIL( + "Unknown cache type '{}' for server cache clear operation", type); + } + + auto* cache = velox::cache::AsyncDataCache::getInstance(); + if (cache == nullptr) { + return "No memory cache set on server"; + } + + cache->clear(); + if (type == kMemoryCacheType) { + return "Cleared memory cache"; + } + + auto* ssdCache = cache->ssdCache(); + if (ssdCache == nullptr) { + return "No ssd cache set on server"; + } + ssdCache->clear(); + return "Cleared ssd cache"; +} + +std::string PrestoServerOperations::serverOperationWriteSsd( + proxygen::HTTPMessage* message) { + auto* cache = velox::cache::AsyncDataCache::getInstance(); + if (cache == nullptr) { + return "No memory cache set on server"; + } + auto* ssdCache = cache->ssdCache(); + if (ssdCache == nullptr) { + return "No ssd cache set on server"; + } + + if (!ssdCache->startWrite()) { + return "Failed to start write to ssd cache"; + } + cache->saveToSsd(true); + ssdCache->waitForWriteToFinish(); + + if (!ssdCache->startWrite()) { + return "Failed to start checkpoint on ssd cache"; + } + ssdCache->checkpoint(); + ssdCache->waitForWriteToFinish(); + return "Succeeded write ssd cache"; +} } // namespace facebook::presto diff --git a/presto-native-execution/presto_cpp/main/PrestoServerOperations.h b/presto-native-execution/presto_cpp/main/PrestoServerOperations.h index d2a8a746f3582..2fe2ff90c1c98 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServerOperations.h +++ b/presto-native-execution/presto_cpp/main/PrestoServerOperations.h @@ -63,6 +63,12 @@ class PrestoServerOperations { std::string serverOperationAnnouncer(proxygen::HTTPMessage* message); + // Clears the in-memory (and optional ssd) cache. + std::string serverOperationClearCache(proxygen::HTTPMessage* message); + + // Writes the in-memory cache into SSD and makes checkpoints. + std::string serverOperationWriteSsd(proxygen::HTTPMessage* message); + TaskManager* const taskManager_; PrestoServer* const server_; }; diff --git a/presto-native-execution/presto_cpp/main/ServerOperation.cpp b/presto-native-execution/presto_cpp/main/ServerOperation.cpp index 0b5fadaf82ae2..ebcb66cd761d5 100644 --- a/presto-native-execution/presto_cpp/main/ServerOperation.cpp +++ b/presto-native-execution/presto_cpp/main/ServerOperation.cpp @@ -20,6 +20,7 @@ const folly::F14FastMap ServerOperation::kActionLookup{ {"clearCache", ServerOperation::Action::kClearCache}, {"getCacheStats", ServerOperation::Action::kGetCacheStats}, + {"writeSsd", ServerOperation::Action::kWriteSSD}, {"setProperty", ServerOperation::Action::kSetProperty}, {"getProperty", ServerOperation::Action::kGetProperty}, {"getDetail", ServerOperation::Action::kGetDetail}, @@ -32,6 +33,7 @@ const folly::F14FastMap ServerOperation::kReverseActionLookup{ {ServerOperation::Action::kClearCache, "clearCache"}, {ServerOperation::Action::kGetCacheStats, "getCacheStats"}, + {ServerOperation::Action::kWriteSSD, "writeSsd"}, {ServerOperation::Action::kSetProperty, "setProperty"}, {ServerOperation::Action::kGetProperty, "getProperty"}, {ServerOperation::Action::kGetDetail, "getDetail"}, diff --git a/presto-native-execution/presto_cpp/main/ServerOperation.h b/presto-native-execution/presto_cpp/main/ServerOperation.h index 79c0dcc3725c7..387c07858ae01 100644 --- a/presto-native-execution/presto_cpp/main/ServerOperation.h +++ b/presto-native-execution/presto_cpp/main/ServerOperation.h @@ -32,7 +32,9 @@ struct ServerOperation { /// The action this operation is trying to take enum class Action { - /// Applicable to kConnector. Clears the connector cache. + /// Applicable to kConnector and kServer. If it is for kConnector, it clears + /// the connector cache. If it is for kServer, it clears the memory (and + /// ssd) cache. kClearCache, /// Applicable to kConnector. Returns stats of the connector cache. kGetCacheStats, @@ -52,6 +54,8 @@ struct ServerOperation { kSetState, /// Applicable to kServer. Enable/disable Presto Announcer. kAnnouncer, + /// Applicable to kServer. Write in-memory cache data to SSD. + kWriteSSD, }; static const folly::F14FastMap kTargetLookup; diff --git a/presto-native-execution/velox b/presto-native-execution/velox index 6caa7d5351ef4..07684ea944350 160000 --- a/presto-native-execution/velox +++ b/presto-native-execution/velox @@ -1 +1 @@ -Subproject commit 6caa7d5351ef4a83acfaebaab7b4389ae3231421 +Subproject commit 07684ea94435031e90155847c88b5da4876f27d8