diff --git a/presto-native-execution/presto_cpp/main/PrestoServer.cpp b/presto-native-execution/presto_cpp/main/PrestoServer.cpp index c47ccb1800fe..2c58d7c86cdb 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServer.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoServer.cpp @@ -651,6 +651,29 @@ void PrestoServer::initializeThreadPools() { } } +std::unique_ptr PrestoServer::setupSsdCache() { + VELOX_CHECK_NULL(cacheExecutor_); + auto* systemConfig = SystemConfig::instance(); + if (systemConfig->asyncCacheSsdGb() == 0) { + return nullptr; + } + + constexpr int32_t kNumSsdShards = 16; + cacheExecutor_ = std::make_unique(kNumSsdShards); + cache::SsdCache::Config cacheConfig( + systemConfig->asyncCacheSsdPath(), + systemConfig->asyncCacheSsdGb() << 30, + kNumSsdShards, + cacheExecutor_.get(), + systemConfig->asyncCacheSsdCheckpointGb() << 30, + systemConfig->asyncCacheSsdDisableFileCow(), + systemConfig->ssdCacheChecksumEnabled(), + systemConfig->ssdCacheReadVerificationEnabled()); + PRESTO_STARTUP_LOG(INFO) << "Initializing SSD cache with " + << cacheConfig.toString(); + return std::make_unique(cacheConfig); +} + void PrestoServer::initializeVeloxMemory() { auto* systemConfig = SystemConfig::instance(); const uint64_t memoryGb = systemConfig->systemMemoryGb(); @@ -695,29 +718,7 @@ void PrestoServer::initializeVeloxMemory() { << memory::memoryManager()->toString(); if (systemConfig->asyncDataCacheEnabled()) { - std::unique_ptr ssd; - const auto asyncCacheSsdGb = systemConfig->asyncCacheSsdGb(); - if (asyncCacheSsdGb > 0) { - constexpr int32_t kNumSsdShards = 16; - cacheExecutor_ = - std::make_unique(kNumSsdShards); - auto asyncCacheSsdCheckpointGb = - systemConfig->asyncCacheSsdCheckpointGb(); - auto asyncCacheSsdDisableFileCow = - systemConfig->asyncCacheSsdDisableFileCow(); - PRESTO_STARTUP_LOG(INFO) - << "Initializing SSD cache with capacity " << asyncCacheSsdGb - << "GB, checkpoint size " << asyncCacheSsdCheckpointGb - << "GB, file cow " - << (asyncCacheSsdDisableFileCow ? "DISABLED" : "ENABLED"); - ssd = std::make_unique( - systemConfig->asyncCacheSsdPath(), - asyncCacheSsdGb << 30, - kNumSsdShards, - cacheExecutor_.get(), - asyncCacheSsdCheckpointGb << 30, - asyncCacheSsdDisableFileCow); - } + std::unique_ptr ssd = setupSsdCache(); std::string cacheStr = ssd == nullptr ? "AsyncDataCache" : "AsyncDataCache with SSD"; cache_ = cache::AsyncDataCache::create( diff --git a/presto-native-execution/presto_cpp/main/PrestoServer.h b/presto-native-execution/presto_cpp/main/PrestoServer.h index a413c3ead311..414452b0f38f 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServer.h +++ b/presto-native-execution/presto_cpp/main/PrestoServer.h @@ -202,6 +202,8 @@ class PrestoServer { void registerSystemConnector(); + std::unique_ptr setupSsdCache(); + const std::string configDirectoryPath_; std::shared_ptr coordinatorDiscoverer_; diff --git a/presto-native-execution/presto_cpp/main/common/Configs.cpp b/presto-native-execution/presto_cpp/main/common/Configs.cpp index 5e74a2178be1..d3746292aaee 100644 --- a/presto-native-execution/presto_cpp/main/common/Configs.cpp +++ b/presto-native-execution/presto_cpp/main/common/Configs.cpp @@ -438,6 +438,14 @@ bool SystemConfig::asyncCacheSsdDisableFileCow() const { return optionalProperty(kAsyncCacheSsdDisableFileCow).value(); } +bool SystemConfig::ssdCacheChecksumEnabled() const { + return optionalProperty(kSsdCacheChecksumEnabled).value(); +} + +bool SystemConfig::ssdCacheReadVerificationEnabled() const { + return optionalProperty(kSsdCacheReadVerificationEnabled).value(); +} + std::string SystemConfig::shuffleName() const { return optionalProperty(kShuffleName).value(); } diff --git a/presto-native-execution/presto_cpp/main/common/Configs.h b/presto-native-execution/presto_cpp/main/common/Configs.h index 065821e6edab..5cb427fc0984 100644 --- a/presto-native-execution/presto_cpp/main/common/Configs.h +++ b/presto-native-execution/presto_cpp/main/common/Configs.h @@ -320,6 +320,14 @@ class SystemConfig : public ConfigBase { /// option to disable cow for cache files. static constexpr std::string_view kAsyncCacheSsdDisableFileCow{ "async-cache-ssd-disable-file-cow"}; + /// When enabled, a CRC-based checksum is calculated for each cache entry + /// written to SSD. The checksum is stored in the next checkpoint file. + static constexpr std::string_view kSsdCacheChecksumEnabled{ + "ssd-cache-checksum-enabled"}; + /// When enabled, the checksum is recalculated and verified against the stored + /// value when cache data is loaded from the SSD. + static constexpr std::string_view kSsdCacheReadVerificationEnabled{ + "ssd-cache-read-verification-enabled"}; static constexpr std::string_view kEnableSerializedPageChecksum{ "enable-serialized-page-checksum"}; @@ -625,6 +633,10 @@ class SystemConfig : public ConfigBase { bool asyncCacheSsdDisableFileCow() const; + bool ssdCacheChecksumEnabled() const; + + bool ssdCacheReadVerificationEnabled() const; + std::string shuffleName() const; bool enableSerializedPageChecksum() const;