Skip to content

Commit

Permalink
[native] Add config for cpp cache default behavior
Browse files Browse the repository at this point in the history
In Presto Java, cache is disabled by default and only enabled when the config `node_preference` is set to `SOFT_AFFINITY`, while in CPP, cache is enabled by default and only disabled when the config node_preference is set to "NO_PREFERENCE".

This change adds a new config to support the alignment of the default cache behavior.
  • Loading branch information
zacw7 committed Nov 20, 2024
1 parent 72f3cef commit ec60c13
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
11 changes: 11 additions & 0 deletions presto-docs/src/main/sphinx/presto_cpp/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ disabled if ``connector.num-io-threads-hw-multiplier`` is set to zero.

Whether async data cache is enabled.

``query-data-cache-enabled-default``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* **Type** ``bool``
* **Default value:** ``true``

If ``true``, SSD cache is enabled by default and is disabled only if
``node_selection_strategy`` is present and set to ``NO_PREFERENCE``.
Otherwise, SSD cache is disabled by default and is enabled if
``node_selection_strategy`` is present and set to ``SOFT_AFFINITY``.

``async-cache-ssd-gb``
^^^^^^^^^^^^^^^^^^^^^^

Expand Down
23 changes: 17 additions & 6 deletions presto-native-execution/presto_cpp/main/QueryContextManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ void updateVeloxConnectorConfigs(
std::unordered_map<
std::string,
std::unordered_map<std::string, std::string>>& connectorConfigStrings) {
const auto& systemConfig = SystemConfig::instance();
for (auto& entry : connectorConfigStrings) {
auto& connectorConfig = entry.second;

// Do not retain cache if `node_selection_strategy` is explicitly set to
// `NO_PREFERENCE`.
// If queryDataCacheEnabledDefault is true, when `node_selection_strategy`
// is
// not set retain cache
// SOFT_AFFINITY retain cache
// NO_PREFERENCE do not retain cache
// If queryDataCacheEnabledDefault is false, when `node_selection_strategy`
// is
// not set do not retain cache
// SOFT_AFFINITY retain cache
// NO_PREFERENCE do not retain cache
connectorConfig.emplace(
connector::hive::HiveConfig::kCacheNoRetentionSession,
systemConfig->queryDataCacheEnabledDefault() ? "false" : "true");
auto it = connectorConfig.find("node_selection_strategy");
if (it != connectorConfig.end() && it->second == "NO_PREFERENCE") {
connectorConfig.emplace(
connector::hive::HiveConfig::kCacheNoRetentionSession, "true");
if (it != connectorConfig.end()) {
connectorConfig[connector::hive::HiveConfig::kCacheNoRetentionSession] =
it->second == "SOFT_AFFINITY" ? "false" : "true";
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ SystemConfig::SystemConfig() {
BOOL_PROP(kNativeSidecar, false),
BOOL_PROP(kAsyncDataCacheEnabled, true),
NUM_PROP(kAsyncCacheSsdGb, 0),
BOOL_PROP(kQueryDataCacheEnabledDefault, true),
NUM_PROP(kAsyncCacheSsdCheckpointGb, 0),
STR_PROP(kAsyncCacheSsdPath, "/mnt/flash/async_cache."),
NUM_PROP(kAsyncCacheMaxSsdWriteRatio, 0.7),
Expand Down Expand Up @@ -464,6 +465,10 @@ bool SystemConfig::asyncDataCacheEnabled() const {
return optionalProperty<bool>(kAsyncDataCacheEnabled).value();
}

bool SystemConfig::queryDataCacheEnabledDefault() const {
return optionalProperty<bool>(kQueryDataCacheEnabledDefault).value();
}

uint64_t SystemConfig::asyncCacheSsdCheckpointGb() const {
return optionalProperty<uint64_t>(kAsyncCacheSsdCheckpointGb).value();
}
Expand Down
8 changes: 8 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ class SystemConfig : public ConfigBase {

static constexpr std::string_view kAsyncDataCacheEnabled{
"async-data-cache-enabled"};
/// If true, SSD cache is enabled by default and is disabled only if
/// `node_selection_strategy` is present and set to `NO_PREFERENCE`.
/// Otherwise, SSD cache is disabled by default and is enabled if
/// `node_selection_strategy` is present and set to `SOFT_AFFINITY`.
static constexpr std::string_view kQueryDataCacheEnabledDefault{
"query-data-cache-enabled-default"};
static constexpr std::string_view kAsyncCacheSsdGb{"async-cache-ssd-gb"};
static constexpr std::string_view kAsyncCacheSsdCheckpointGb{
"async-cache-ssd-checkpoint-gb"};
Expand Down Expand Up @@ -752,6 +758,8 @@ class SystemConfig : public ConfigBase {

bool asyncDataCacheEnabled() const;

bool queryDataCacheEnabledDefault() const;

uint64_t asyncCacheSsdGb() const;

uint64_t asyncCacheSsdCheckpointGb() const;
Expand Down

0 comments on commit ec60c13

Please sign in to comment.