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
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ std::shared_ptr<core::QueryCtx> QueryContextManager::findOrCreateQueryCtx(
{entry.first, std::make_shared<core::MemConfig>(entry.second)});
}

const int64_t maxTotalMemoryPerNode = getMaxMemoryPerNode(
kQueryMaxTotalMemoryPerNode, kDefaultMaxMemoryPerNode);

const int64_t maxQueryMemoryPerNode =
getMaxMemoryPerNode(kQueryMaxMemoryPerNode, kDefaultMaxMemoryPerNode);
auto pool =
memory::getProcessDefaultMemoryManager().getRoot().addChild("query_root");
pool->setMemoryUsageTracker(
velox::memory::MemoryUsageTracker::create(maxTotalMemoryPerNode));
velox::memory::MemoryUsageTracker::create(maxQueryMemoryPerNode));

auto queryCtx = std::make_shared<core::QueryCtx>(
executor().get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ class QueryContextManager {

static constexpr const char* kQueryMaxMemoryPerNode =
"query.max-memory-per-node";
static constexpr const char* kQueryMaxTotalMemoryPerNode =
"query.max-total-memory-per-node";
static constexpr int64_t kDefaultMaxMemoryPerNode =
std::numeric_limits<int64_t>::max();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class TaskManagerTest : public testing::Test {
} else {
auto resultsOrFailures =
fetchAllResults(outputTaskInfo->taskId, finalOutputType, allTaskIds);
EXPECT_TRUE(resultsOrFailures.status != nullptr);
EXPECT_EQ(resultsOrFailures.status->state, protocol::TaskState::FAILED);
for (const auto& taskId : allTaskIds) {
taskManager_->deleteTask(taskId, true);
Expand Down Expand Up @@ -512,13 +513,10 @@ class TaskManagerTest : public testing::Test {
taskInfo->stats.peakTotalMemoryInBytes);
}

void setMemoryLimits(uint64_t userMax, uint64_t totalMax) {
void setMemoryLimits(uint64_t maxMemory) {
taskManager_->getQueryContextManager()->overrideProperties(
QueryContextManager::kQueryMaxMemoryPerNode,
fmt::format("{}B", userMax));
taskManager_->getQueryContextManager()->overrideProperties(
QueryContextManager::kQueryMaxTotalMemoryPerNode,
fmt::format("{}B", totalMax));
fmt::format("{}B", maxMemory));
}

// Setup the temporary spilling directory and initialize the system config
Expand Down Expand Up @@ -696,15 +694,11 @@ TEST_F(TaskManagerTest, outOfQueryUserMemory) {

auto [peakUser, peakTotal] = testCountAggregation("initial", filePaths);

setMemoryLimits(peakUser - 1, 20 * kGB);
setMemoryLimits(peakUser - 1);
testCountAggregation("max-memory", filePaths, {}, true);

// Verify query.max-total-memory-per-node is respected.
setMemoryLimits(20 * kGB, peakTotal - 1);
testCountAggregation("max-total-memory", filePaths, {}, true);

// Verify the query is successful with some limits.
setMemoryLimits(20 * kGB, 20 * kGB);
setMemoryLimits(20 * kGB);
testCountAggregation("test-count-aggr", filePaths);

// Wait a little to allow for futures to complete.
Expand Down