Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions presto-docs/src/main/sphinx/presto_cpp/properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Worker Properties

The configuration properties of Presto C++ workers are described here, in alphabetical order.

``async-cache-persistence-interval``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* **Type:** ``string``
* **Default value:** ``0s``

The interval for persisting in-memory cache to SSD. Setting this config
to a non-zero value will activate periodic cache persistence.

``async-data-cache-enabled``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
29 changes: 8 additions & 21 deletions presto-native-execution/presto_cpp/main/PrestoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ bool isCacheTtlEnabled() {
return false;
}

bool isCachePeriodicFullPersistenceEnabled() {
bool cachePeriodicPersistenceEnabled() {
const auto* systemConfig = SystemConfig::instance();
return systemConfig->asyncDataCacheEnabled() &&
systemConfig->asyncCacheSsdGb() > 0 &&
systemConfig->asyncCacheFullPersistenceInterval() >
systemConfig->asyncCachePersistenceInterval() >
std::chrono::seconds::zero();
}

Expand Down Expand Up @@ -1008,7 +1008,7 @@ void PrestoServer::addServerPeriodicTasks() {
"cache_ttl");
}

if (isCachePeriodicFullPersistenceEnabled()) {
if (cachePeriodicPersistenceEnabled()) {
PRESTO_STARTUP_LOG(INFO)
<< "Initializing cache periodic full persistence task...";
auto* cache = velox::cache::AsyncDataCache::getInstance();
Expand All @@ -1018,31 +1018,18 @@ void PrestoServer::addServerPeriodicTasks() {
const auto* systemConfig = SystemConfig::instance();
const int64_t cacheFullPersistenceIntervalUs =
std::chrono::duration_cast<std::chrono::microseconds>(
systemConfig->asyncCacheFullPersistenceInterval())
systemConfig->asyncCachePersistenceInterval())
.count();
const auto asyncCacheSsdCheckpointGb =
systemConfig->asyncCacheSsdCheckpointGb();
periodicTaskManager_->addTask(
[asyncCacheSsdCheckpointGb, cache, ssdCache]() {
[cache, ssdCache]() {
try {
if (!ssdCache->startWrite()) {
return;
}
LOG(INFO) << "Persisting full cache to SSD...";
cache->saveToSsd(true);
ssdCache->waitForWriteToFinish();
LOG(INFO) << "Cache full persistence completed.";

if (asyncCacheSsdCheckpointGb == 0) {
return;
}

if (!ssdCache->startWrite()) {
return;
}

ssdCache->checkpoint();
LOG(INFO) << "Flush in-memory cache to SSD...";
cache->saveToSsd();
ssdCache->waitForWriteToFinish();
LOG(INFO) << "Flushing in-memory cache to SSD completed.";
} catch (const std::exception& e) {
LOG(ERROR) << "Failed to persistent cache to SSD: " << e.what();
}
Expand Down
6 changes: 3 additions & 3 deletions presto-native-execution/presto_cpp/main/common/Configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ SystemConfig::SystemConfig() {
NUM_PROP(kAsyncCacheMaxSsdWriteRatio, 0.7),
NUM_PROP(kAsyncCacheSsdSavableRatio, 0.125),
NUM_PROP(kAsyncCacheMinSsdSavableBytes, 1 << 24 /*16MB*/),
STR_PROP(kAsyncCacheFullPersistenceInterval, "0s"),
STR_PROP(kAsyncCachePersistenceInterval, "0s"),
BOOL_PROP(kAsyncCacheSsdDisableFileCow, false),
BOOL_PROP(kSsdCacheChecksumEnabled, false),
BOOL_PROP(kSsdCacheReadVerificationEnabled, false),
Expand Down Expand Up @@ -465,10 +465,10 @@ int32_t SystemConfig::asyncCacheMinSsdSavableBytes() const {
return optionalProperty<int32_t>(kAsyncCacheMinSsdSavableBytes).value();
}

std::chrono::duration<double> SystemConfig::asyncCacheFullPersistenceInterval()
std::chrono::duration<double> SystemConfig::asyncCachePersistenceInterval()
const {
return velox::config::toDuration(
optionalProperty(kAsyncCacheFullPersistenceInterval).value());
optionalProperty(kAsyncCachePersistenceInterval).value());
}

bool SystemConfig::asyncCacheSsdDisableFileCow() const {
Expand Down
8 changes: 4 additions & 4 deletions presto-native-execution/presto_cpp/main/common/Configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ class SystemConfig : public ConfigBase {
static constexpr std::string_view kAsyncCacheMinSsdSavableBytes{
"async-cache-min-ssd-savable-bytes"};

/// The interval for persisting full memory cache to SSD. Setting this config
/// The interval for persisting in-memory cache to SSD. Setting this config
/// to a non-zero value will activate periodic cache persistence.
static constexpr std::string_view kAsyncCacheFullPersistenceInterval{
"async-cache-full-persistence-interval"};
static constexpr std::string_view kAsyncCachePersistenceInterval{
"async-cache-persistence-interval"};

/// In file systems, such as btrfs, supporting cow (copy on write), the ssd
/// cache can use all ssd space and stop working. To prevent that, use this
Expand Down Expand Up @@ -747,7 +747,7 @@ class SystemConfig : public ConfigBase {

int32_t asyncCacheMinSsdSavableBytes() const;

std::chrono::duration<double> asyncCacheFullPersistenceInterval() const;
std::chrono::duration<double> asyncCachePersistenceInterval() const;

bool asyncCacheSsdDisableFileCow() const;

Expand Down