Skip to content

Commit

Permalink
[native] Adapt new async cache config
Browse files Browse the repository at this point in the history
  • Loading branch information
zacw7 committed Jun 1, 2024
1 parent 6514b46 commit fea27e0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
47 changes: 24 additions & 23 deletions presto-native-execution/presto_cpp/main/PrestoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,29 @@ void PrestoServer::initializeThreadPools() {
}
}

std::unique_ptr<cache::SsdCache> 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<folly::IOThreadPoolExecutor>(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<cache::SsdCache>(cacheConfig);
}

void PrestoServer::initializeVeloxMemory() {
auto* systemConfig = SystemConfig::instance();
const uint64_t memoryGb = systemConfig->systemMemoryGb();
Expand Down Expand Up @@ -695,29 +718,7 @@ void PrestoServer::initializeVeloxMemory() {
<< memory::memoryManager()->toString();

if (systemConfig->asyncDataCacheEnabled()) {
std::unique_ptr<cache::SsdCache> ssd;
const auto asyncCacheSsdGb = systemConfig->asyncCacheSsdGb();
if (asyncCacheSsdGb > 0) {
constexpr int32_t kNumSsdShards = 16;
cacheExecutor_ =
std::make_unique<folly::IOThreadPoolExecutor>(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<cache::SsdCache>(
systemConfig->asyncCacheSsdPath(),
asyncCacheSsdGb << 30,
kNumSsdShards,
cacheExecutor_.get(),
asyncCacheSsdCheckpointGb << 30,
asyncCacheSsdDisableFileCow);
}
std::unique_ptr<cache::SsdCache> ssd = setupSsdCache();
std::string cacheStr =
ssd == nullptr ? "AsyncDataCache" : "AsyncDataCache with SSD";
cache_ = cache::AsyncDataCache::create(
Expand Down
2 changes: 2 additions & 0 deletions presto-native-execution/presto_cpp/main/PrestoServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class PrestoServer {

void registerSystemConnector();

std::unique_ptr<velox::cache::SsdCache> setupSsdCache();

const std::string configDirectoryPath_;

std::shared_ptr<CoordinatorDiscoverer> coordinatorDiscoverer_;
Expand Down
8 changes: 8 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ bool SystemConfig::asyncCacheSsdDisableFileCow() const {
return optionalProperty<bool>(kAsyncCacheSsdDisableFileCow).value();
}

bool SystemConfig::ssdCacheChecksumEnabled() const {
return optionalProperty<bool>(kSsdCacheChecksumEnabled).value();
}

bool SystemConfig::ssdCacheReadVerificationEnabled() const {
return optionalProperty<bool>(kSsdCacheReadVerificationEnabled).value();
}

std::string SystemConfig::shuffleName() const {
return optionalProperty(kShuffleName).value();
}
Expand Down
12 changes: 12 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"};

Expand Down Expand Up @@ -625,6 +633,10 @@ class SystemConfig : public ConfigBase {

bool asyncCacheSsdDisableFileCow() const;

bool ssdCacheChecksumEnabled() const;

bool ssdCacheReadVerificationEnabled() const;

std::string shuffleName() const;

bool enableSerializedPageChecksum() const;
Expand Down

0 comments on commit fea27e0

Please sign in to comment.