Skip to content

Commit

Permalink
[VL] Make glog config be session level (#4785)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohahaha authored Feb 29, 2024
1 parent 7af6d0c commit 908b2f6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
7 changes: 7 additions & 0 deletions cpp/core/config/GlutenConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ const std::string kShuffleCompressionCodecBackend = "spark.gluten.sql.columnar.s
const std::string kQatBackendName = "qat";
const std::string kIaaBackendName = "iaa";

// Velox conf
const std::string kGlogVerboseLevel = "spark.gluten.sql.columnar.backend.velox.glogVerboseLevel";
const uint32_t kGlogVerboseLevelDefault = 0;
const uint32_t kGlogVerboseLevelMaximum = 99;
const std::string kGlogSeverityLevel = "spark.gluten.sql.columnar.backend.velox.glogSeverityLevel";
const uint32_t kGlogSeverityLevelDefault = 1;

std::unordered_map<std::string, std::string>
parseConfMap(JNIEnv* env, const uint8_t* planData, const int32_t planDataLength);

Expand Down
18 changes: 7 additions & 11 deletions cpp/velox/compute/VeloxBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ const std::string kEnableUserExceptionStacktrace =
"spark.gluten.sql.columnar.backend.velox.enableUserExceptionStacktrace";
const bool kEnableUserExceptionStacktraceDefault = true;

const std::string kGlogVerboseLevel = "spark.gluten.sql.columnar.backend.velox.glogVerboseLevel";
const uint32_t kGlogVerboseLevelDefault = 0;

const std::string kGlogSeverityLevel = "spark.gluten.sql.columnar.backend.velox.glogSeverityLevel";
const uint32_t kGlogSeverityLevelDefault = 1;

const std::string kEnableSystemExceptionStacktrace =
"spark.gluten.sql.columnar.backend.velox.enableSystemExceptionStacktrace";
const bool kEnableSystemExceptionStacktraceDefault = true;
Expand Down Expand Up @@ -148,12 +142,14 @@ void VeloxBackend::init(const std::unordered_map<std::string, std::string>& conf

// Init glog and log level.
if (!veloxcfg->get<bool>(kDebugModeEnabled, false)) {
uint32_t vlogLevel = veloxcfg->get<uint32_t>(kGlogVerboseLevel, kGlogVerboseLevelDefault);
FLAGS_v = vlogLevel;
uint32_t severityLogLevel = veloxcfg->get<uint32_t>(kGlogSeverityLevel, kGlogSeverityLevelDefault);
FLAGS_minloglevel = severityLogLevel;
FLAGS_v = veloxcfg->get<uint32_t>(kGlogVerboseLevel, kGlogVerboseLevelDefault);
FLAGS_minloglevel = veloxcfg->get<uint32_t>(kGlogSeverityLevel, kGlogSeverityLevelDefault);
} else {
FLAGS_v = 99;
if (veloxcfg->isValueExists(kGlogVerboseLevel)) {
FLAGS_v = veloxcfg->get<uint32_t>(kGlogVerboseLevel, kGlogVerboseLevelDefault);
} else {
FLAGS_v = kGlogVerboseLevelMaximum;
}
}
FLAGS_logtostderr = true;
google::InitGoogleLogging("gluten");
Expand Down
14 changes: 10 additions & 4 deletions cpp/velox/compute/VeloxRuntime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ using namespace facebook;

namespace gluten {

VeloxRuntime::VeloxRuntime(const std::unordered_map<std::string, std::string>& confMap) : Runtime(confMap) {}
VeloxRuntime::VeloxRuntime(const std::unordered_map<std::string, std::string>& confMap) : Runtime(confMap) {
// Refresh session config.
veloxCfg_ = std::make_shared<const facebook::velox::core::MemConfigMutable>(confMap_);
debugModeEnabled_ = veloxCfg_->get<bool>(kDebugModeEnabled, false);
FLAGS_minloglevel = veloxCfg_->get<uint32_t>(kGlogSeverityLevel, FLAGS_minloglevel);
FLAGS_v = veloxCfg_->get<uint32_t>(kGlogVerboseLevel, FLAGS_v);
}

void VeloxRuntime::parsePlan(
const uint8_t* data,
int32_t size,
SparkTaskInfo taskInfo,
std::optional<std::string> dumpFile) {
taskInfo_ = taskInfo;
if (debugModeEnabled(confMap_)) {
if (debugModeEnabled_) {
try {
auto jsonPlan = substraitFromPbToJson("Plan", data, size, dumpFile);
LOG(INFO) << std::string(50, '#') << " received substrait::Plan:";
Expand All @@ -59,7 +65,7 @@ void VeloxRuntime::parsePlan(
}

void VeloxRuntime::parseSplitInfo(const uint8_t* data, int32_t size, std::optional<std::string> dumpFile) {
if (debugModeEnabled(confMap_)) {
if (debugModeEnabled_) {
try {
auto jsonPlan = substraitFromPbToJson("ReadRel.LocalFiles", data, size, dumpFile);
LOG(INFO) << std::string(50, '#') << " received substrait::ReadRel.LocalFiles:";
Expand Down Expand Up @@ -111,7 +117,7 @@ std::shared_ptr<ResultIterator> VeloxRuntime::createResultIterator(
const std::string& spillDir,
const std::vector<std::shared_ptr<ResultIterator>>& inputs,
const std::unordered_map<std::string, std::string>& sessionConf) {
if (debugModeEnabled(confMap_)) {
if (debugModeEnabled_) {
LOG(INFO) << "VeloxRuntime session config:" << printConfig(confMap_);
}

Expand Down
6 changes: 6 additions & 0 deletions cpp/velox/compute/VeloxRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class VeloxRuntime final : public Runtime {
return veloxPlan_;
}

bool debugModeEnabled() const {
return debugModeEnabled_;
}

static void getInfoAndIds(
const std::unordered_map<facebook::velox::core::PlanNodeId, std::shared_ptr<SplitInfo>>& splitInfoMap,
const std::unordered_set<facebook::velox::core::PlanNodeId>& leafPlanNodeIds,
Expand All @@ -129,6 +133,8 @@ class VeloxRuntime final : public Runtime {

private:
std::shared_ptr<const facebook::velox::core::PlanNode> veloxPlan_;
std::shared_ptr<const facebook::velox::Config> veloxCfg_;
bool debugModeEnabled_{false};

std::unordered_map<int32_t, std::shared_ptr<ColumnarBatch>> emptySchemaBatchLoopUp_;
};
Expand Down
4 changes: 3 additions & 1 deletion cpp/velox/jni/VeloxJniWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <exception>
#include "JniUdf.h"
#include "compute/VeloxBackend.h"
#include "compute/VeloxRuntime.h"
#include "config/GlutenConfig.h"
#include "jni/JniError.h"
#include "jni/JniFileSystem.h"
Expand Down Expand Up @@ -94,7 +95,8 @@ Java_io_glutenproject_vectorized_PlanEvaluatorJniWrapper_nativeValidateWithFailu
auto safeArray = gluten::getByteArrayElementsSafe(env, planArray);
auto planData = safeArray.elems();
auto planSize = env->GetArrayLength(planArray);
if (gluten::debugModeEnabled(ctx->getConfMap())) {
auto runtime = dynamic_cast<gluten::VeloxRuntime*>(ctx);
if (runtime->debugModeEnabled()) {
try {
auto jsonPlan = gluten::substraitFromPbToJson("Plan", planData, planSize, std::nullopt);
LOG(INFO) << std::string(50, '#') << " received substrait::Plan: for validation";
Expand Down
6 changes: 0 additions & 6 deletions cpp/velox/utils/ConfigExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ std::string getConfigValue(
return got->second;
}

bool debugModeEnabled(const std::unordered_map<std::string, std::string>& confMap) {
std::shared_ptr<const facebook::velox::Config> veloxCfg =
std::make_shared<const facebook::velox::core::MemConfigMutable>(confMap);
return veloxCfg->get<bool>(kDebugModeEnabled, false);
}

std::shared_ptr<facebook::velox::core::MemConfigMutable> getHiveConfig(
const std::shared_ptr<const facebook::velox::Config>& conf) {
auto hiveConf = std::make_shared<facebook::velox::core::MemConfigMutable>();
Expand Down
2 changes: 0 additions & 2 deletions cpp/velox/utils/ConfigExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ std::string getConfigValue(
const std::string& key,
const std::optional<std::string>& fallbackValue);

bool debugModeEnabled(const std::unordered_map<std::string, std::string>& confMap);

std::shared_ptr<facebook::velox::core::MemConfigMutable> getHiveConfig(
const std::shared_ptr<const facebook::velox::Config>& conf);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,14 +1195,14 @@ object GlutenConfig {
.createWithDefault(2)

val COLUMNAR_VELOX_GLOG_VERBOSE_LEVEL =
buildStaticConf("spark.gluten.sql.columnar.backend.velox.glogVerboseLevel")
buildConf("spark.gluten.sql.columnar.backend.velox.glogVerboseLevel")
.internal()
.doc("Set glog verbose level in Velox backend, same as FLAGS_v.")
.intConf
.createWithDefault(0)

val COLUMNAR_VELOX_GLOG_SEVERITY_LEVEL =
buildStaticConf("spark.gluten.sql.columnar.backend.velox.glogSeverityLevel")
buildConf("spark.gluten.sql.columnar.backend.velox.glogSeverityLevel")
.internal()
.doc("Set glog severity level in Velox backend, same as FLAGS_minloglevel.")
.intConf
Expand Down

0 comments on commit 908b2f6

Please sign in to comment.