Skip to content
Open
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
22 changes: 13 additions & 9 deletions presto-native-execution/presto_cpp/main/QueryContextManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "presto_cpp/main/QueryContextManager.h"
#include <folly/executors/IOThreadPoolExecutor.h>
#include "presto_cpp/main/PrestoToVeloxQueryConfig.h"
#include "presto_cpp/main/SessionProperties.h"
#include "presto_cpp/main/common/Configs.h"

#include "velox/connectors/hive/HiveConfig.h"
#include "velox/core/QueryConfig.h"

#include <folly/executors/IOThreadPoolExecutor.h>

using namespace facebook::velox;

using facebook::presto::protocol::QueryId;
Expand Down Expand Up @@ -60,8 +61,11 @@ std::shared_ptr<velox::core::QueryCtx> QueryContextCache::insert(
evict();
}
queryIds_.push_front(queryId);
queryCtxs_[queryId] = {
folly::to_weak_ptr(queryCtx), queryIds_.begin(), false};
queryCtxs_.insert(
{queryId,
{.queryCtx = folly::to_weak_ptr(queryCtx),
.idListIterator = queryIds_.begin(),
.hasStartedTasks = false}});
return queryCtx;
}

Expand All @@ -83,11 +87,11 @@ void QueryContextCache::setTasksStarted(const protocol::QueryId& queryId) {

void QueryContextCache::evict() {
// Evict least recently used queryCtx if it is not referenced elsewhere.
for (auto victim = queryIds_.end(); victim != queryIds_.begin();) {
--victim;
if (!queryCtxs_[*victim].queryCtx.lock()) {
queryCtxs_.erase(*victim);
queryIds_.erase(victim);
for (auto victim = queryIds_.rbegin(); victim != queryIds_.rend(); ++victim) {
auto iter = queryCtxs_.find(*victim);
if (iter != queryCtxs_.end() && !iter->second.queryCtx.lock()) {
queryCtxs_.erase(iter);
queryIds_.erase(std::next(victim).base());
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class QueryContextCache {
};
using QueryCtxMap = std::unordered_map<protocol::QueryId, QueryCtxCacheValue>;

QueryContextCache(size_t initial_capacity = kInitialCapacity)
explicit QueryContextCache(size_t initial_capacity = kInitialCapacity)
: capacity_(initial_capacity) {}

size_t capacity() const {
Expand Down
11 changes: 7 additions & 4 deletions presto-native-execution/presto_cpp/main/TaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,14 @@ void enqueueTask(
TaskManager::TaskManager(
folly::Executor* driverExecutor,
folly::Executor* httpSrvCpuExecutor,
folly::Executor* spillerExecutor)
folly::Executor* spillerExecutor,
std::unique_ptr<QueryContextManager> queryContextManager)
: queryContextManager_(
std::make_unique<QueryContextManager>(
driverExecutor,
spillerExecutor)),
queryContextManager == nullptr
? std::make_unique<QueryContextManager>(
driverExecutor,
spillerExecutor)
: std::move(queryContextManager)),
bufferManager_(velox::exec::OutputBufferManager::getInstanceRef()),
httpSrvCpuExecutor_(httpSrvCpuExecutor),
lastNotOverloadedTimeInSecs_(velox::getCurrentTimeSec()) {
Expand Down
26 changes: 14 additions & 12 deletions presto-native-execution/presto_cpp/main/TaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,23 @@ class TaskManager {
TaskManager(
folly::Executor* driverExecutor,
folly::Executor* httpSrvExecutor,
folly::Executor* spillerExecutor);
folly::Executor* spillerExecutor,
std::unique_ptr<QueryContextManager> queryContextManager = nullptr);

virtual ~TaskManager() = default;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Changing the access specifier here may unintentionally make all following TaskManager methods protected.

Placing protected: here changes the visibility of shutdown() and all following members until the next access specifier. If no later public: is declared, this will hide the existing TaskManager public API and change the class interface. If you only intend shutdown() to be protected, move protected: immediately before shutdown() and add public: again afterward (or adjust only shutdown()’s declaration).

/// Always returns tuple of non-empty string containing the spill directory
/// and the date string directory, which is parent directory of task spill
/// directory.
static std::tuple<std::string, std::string> buildTaskSpillDirectoryPath(
const std::string& baseSpillPath,
const std::string& nodeIp,
const std::string& nodeId,
const std::string& queryId,
const protocol::TaskId& taskId,
bool includeNodeInSpillPath);

protected:
/// Invoked by Presto server shutdown to wait for all the tasks to complete
/// and cleanup the completed tasks.
void shutdown();
Expand Down Expand Up @@ -166,17 +179,6 @@ class TaskManager {
std::vector<std::string>& deadlockTasks,
std::vector<velox::exec::Task::OpCallInfo>& stuckOpCalls) const;

/// Always returns tuple of non-empty string containing the spill directory
/// and the date string directory, which is parent directory of task spill
/// directory.
static std::tuple<std::string, std::string> buildTaskSpillDirectoryPath(
const std::string& baseSpillPath,
const std::string& nodeIp,
const std::string& nodeId,
const std::string& queryId,
const protocol::TaskId& taskId,
bool includeNodeInSpillPath);

/// Presto Server can notify the Task Manager that the former is overloaded,
/// so the Task Manager can optionally change Task admission algorithm.
void setServerOverloaded(bool serverOverloaded);
Expand Down
Loading