You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ji...@apache.org on 2017/09/01 19:22:23 UTC
incubator-quickstep git commit: Redirect stdout and stderr in network
mode. [Forced Update!]
Repository: incubator-quickstep
Updated Branches:
refs/heads/redirect-stream fb9f856a7 -> 3330644cd (forced update)
Redirect stdout and stderr in network mode.
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/3330644c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/3330644c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/3330644c
Branch: refs/heads/redirect-stream
Commit: 3330644cd6fefb965d0e13b09c6f9d44908c3692
Parents: 2981651
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Fri Sep 1 12:07:13 2017 -0500
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Fri Sep 1 14:22:05 2017 -0500
----------------------------------------------------------------------
CMakeLists.txt | 1 +
cli/Flags.cpp | 2 +
cli/Flags.hpp | 2 +
cli/IOInterface.hpp | 11 +-
cli/NetworkCliClientMain.cpp | 1 -
cli/QuickstepCli.cpp | 16 +-
utility/CMakeLists.txt | 13 ++
utility/ScopedReassignment.hpp | 81 +++++++++
utility/tests/ScopedReassignment_unittest.cpp | 189 +++++++++++++++++++++
9 files changed, 307 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ed80fab..e0d020b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -751,6 +751,7 @@ target_link_libraries(quickstep_cli_shell
quickstep_utility_ExecutionDAGVisualizer
quickstep_utility_Macros
quickstep_utility_PtrVector
+ quickstep_utility_ScopedReassignment
quickstep_utility_SqlError
quickstep_utility_StringUtil)
if (ENABLE_HDFS)
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/cli/Flags.cpp
----------------------------------------------------------------------
diff --git a/cli/Flags.cpp b/cli/Flags.cpp
index 362eac3..78e72aa 100644
--- a/cli/Flags.cpp
+++ b/cli/Flags.cpp
@@ -36,6 +36,8 @@ DEFINE_bool(print_query, false,
"Print each input query statement. This is useful when running a "
"large number of queries in a batch.");
+DEFINE_bool(timing, true, "Whether to show execution time of each statement.");
+
DEFINE_bool(initialize_db, false, "If true, initialize a database.");
static bool ValidateNumWorkers(const char *flagname, int value) {
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/cli/Flags.hpp
----------------------------------------------------------------------
diff --git a/cli/Flags.hpp b/cli/Flags.hpp
index 1ae37c4..4d3fd75 100644
--- a/cli/Flags.hpp
+++ b/cli/Flags.hpp
@@ -45,6 +45,8 @@ DECLARE_string(storage_path);
DECLARE_bool(preload_buffer_pool);
+DECLARE_bool(timing);
+
/** @} */
} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/cli/IOInterface.hpp
----------------------------------------------------------------------
diff --git a/cli/IOInterface.hpp b/cli/IOInterface.hpp
index 815596e..dc0d5b2 100644
--- a/cli/IOInterface.hpp
+++ b/cli/IOInterface.hpp
@@ -28,7 +28,7 @@
namespace quickstep {
/**
- * An individual IO interaction with Quickstep.
+ * @brief An individual IO interaction with Quickstep.
*/
class IOHandle {
public:
@@ -56,18 +56,21 @@ class IOHandle {
};
/**
- * Virtual base defines a generic, file-based interface around IO. One IO interaction (eg a SQL query) will be assigned
- * an IOHandle. On destruction of the IOHandle, the IO interaction has finished.
+ * @brief Virtual base defines a generic, file-based interface around IO.
+ * One IO interaction (eg a SQL query) will be assigned an IOHandle.
+ * On destruction of the IOHandle, the IO interaction has finished.
*/
class IOInterface {
public:
/**
- * @note Destructing the IOInterface should close any outstanding IO state (eg an open port).
+ * @note Destructing the IOInterface should close any outstanding IO state
+ * (e.g. an open port).
*/
virtual ~IOInterface() {}
/**
* @brief Retrieves the next IOHandle. Blocks if no IO ready.
+ *
* @return An IOHandle.
*/
virtual IOHandle* getNextIOHandle() = 0;
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/cli/NetworkCliClientMain.cpp
----------------------------------------------------------------------
diff --git a/cli/NetworkCliClientMain.cpp b/cli/NetworkCliClientMain.cpp
index 862941c..c55819b 100644
--- a/cli/NetworkCliClientMain.cpp
+++ b/cli/NetworkCliClientMain.cpp
@@ -53,7 +53,6 @@ int main(int argc, char **argv) {
while (!linereader.bufferEmpty()) {
std::string query = linereader.getNextCommand();
if (!query.empty()) {
- std::cout << query << std::endl;
std::cout << qs_client.Query(query) << std::endl;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/cli/QuickstepCli.cpp
----------------------------------------------------------------------
diff --git a/cli/QuickstepCli.cpp b/cli/QuickstepCli.cpp
index c55bdd7..b413031 100644
--- a/cli/QuickstepCli.cpp
+++ b/cli/QuickstepCli.cpp
@@ -69,6 +69,7 @@
#include "utility/ExecutionDAGVisualizer.hpp"
#include "utility/Macros.hpp"
#include "utility/PtrVector.hpp"
+#include "utility/ScopedReassignment.hpp"
#include "utility/SqlError.hpp"
#include "utility/StringUtil.hpp"
@@ -105,6 +106,7 @@ using quickstep::PtrVector;
using quickstep::QueryExecutionUtil;
using quickstep::QueryHandle;
using quickstep::QueryProcessor;
+using quickstep::ScopedReassignment;
using quickstep::SqlParserWrapper;
using quickstep::Worker;
using quickstep::WorkerDirectory;
@@ -150,6 +152,7 @@ DEFINE_string(mode, "local",
"same manner as with the local cli.");
DECLARE_bool(profile_and_report_workorder_perf);
+DECLARE_bool(timing);
DECLARE_bool(visualize_execution_dag);
} // namespace quickstep
@@ -303,6 +306,9 @@ int main(int argc, char* argv[]) {
for (;;) {
string *command_string = new string();
std::unique_ptr<quickstep::IOHandle> io_handle(io->getNextIOHandle());
+ ScopedReassignment<FILE*> reassign_stdout(&stdout, io_handle->out());
+ ScopedReassignment<FILE*> reassign_stderr(&stderr, io_handle->err());
+
*command_string = io_handle->getCommand();
LOG(INFO) << "Command received: " << *command_string;
if (command_string->size() == 0) {
@@ -397,10 +403,12 @@ int main(int argc, char* argv[]) {
}
query_processor->saveCatalog();
- std::chrono::duration<double, std::milli> time_ms = end - start;
- fprintf(io_handle->out(), "Time: %s ms\n",
- quickstep::DoubleToStringWithSignificantDigits(
- time_ms.count(), 3).c_str());
+ if (quickstep::FLAGS_timing) {
+ std::chrono::duration<double, std::milli> time_ms = end - start;
+ fprintf(io_handle->out(), "Time: %s ms\n",
+ quickstep::DoubleToStringWithSignificantDigits(
+ time_ms.count(), 3).c_str());
+ }
if (quickstep::FLAGS_profile_and_report_workorder_perf) {
// TODO(harshad) - Allow user specified file instead of stdout.
foreman.printWorkOrderProfilingResults(query_id, stdout);
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/utility/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt
index a832404..c5c9dd8 100644
--- a/utility/CMakeLists.txt
+++ b/utility/CMakeLists.txt
@@ -196,6 +196,7 @@ add_library(quickstep_utility_PtrMap ../empty_src.cpp PtrMap.hpp)
add_library(quickstep_utility_PtrVector ../empty_src.cpp PtrVector.hpp)
add_library(quickstep_utility_ScopedBuffer ../empty_src.cpp ScopedBuffer.hpp)
add_library(quickstep_utility_ScopedDeleter ../empty_src.cpp ScopedDeleter.hpp)
+add_library(quickstep_utility_ScopedReassignment ../empty_src.cpp ScopedReassignment.hpp)
add_library(quickstep_utility_ShardedLockManager ../empty_src.cpp ShardedLockManager.hpp)
add_library(quickstep_utility_SortConfiguration SortConfiguration.cpp SortConfiguration.hpp)
add_library(quickstep_utility_SortConfiguration_proto
@@ -313,6 +314,8 @@ target_link_libraries(quickstep_utility_ScopedBuffer
quickstep_utility_Macros)
target_link_libraries(quickstep_utility_ScopedDeleter
quickstep_utility_Macros)
+target_link_libraries(quickstep_utility_ScopedReassignment
+ quickstep_utility_Macros)
target_link_libraries(quickstep_utility_SqlError
glog)
target_link_libraries(quickstep_utility_SortConfiguration
@@ -379,6 +382,7 @@ target_link_libraries(quickstep_utility
quickstep_utility_PtrVector
quickstep_utility_ScopedBuffer
quickstep_utility_ScopedDeleter
+ quickstep_utility_ScopedReassignment
quickstep_utility_ShardedLockManager
quickstep_utility_SortConfiguration
quickstep_utility_SortConfiguration_proto
@@ -462,6 +466,15 @@ target_link_libraries(ScopedDeleter_unittest
${LIBS})
add_test(ScopedDeleter_unittest ScopedDeleter_unittest)
+add_executable(ScopedReassignment_unittest "${CMAKE_CURRENT_SOURCE_DIR}/tests/ScopedReassignment_unittest.cpp")
+target_link_libraries(ScopedReassignment_unittest
+ gtest
+ gtest_main
+ quickstep_utility_Macros
+ quickstep_utility_ScopedReassignment
+ ${LIBS})
+add_test(ScopedReassignment_unittest ScopedReassignment_unittest)
+
add_executable(SqlError_unittest "${CMAKE_CURRENT_SOURCE_DIR}/tests/SqlError_unittest.cpp")
target_link_libraries(SqlError_unittest
glog
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/utility/ScopedReassignment.hpp
----------------------------------------------------------------------
diff --git a/utility/ScopedReassignment.hpp b/utility/ScopedReassignment.hpp
new file mode 100644
index 0000000..bd0bcb2
--- /dev/null
+++ b/utility/ScopedReassignment.hpp
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ **/
+
+#ifndef QUICKSTEP_UTILITY_SCOPED_REASSIGNMENT_HPP_
+#define QUICKSTEP_UTILITY_SCOPED_REASSIGNMENT_HPP_
+
+#include <utility>
+#include <type_traits>
+
+#include "utility/Macros.hpp"
+
+namespace quickstep {
+
+/** \addtogroup Utility
+ * @{
+ */
+
+/**
+ * @brief RAII helper object that assigns a new value to a variable and restores
+ * the old value when the helper object goes out of scope.
+ **/
+template <typename T>
+class ScopedReassignment {
+ public:
+ /**
+ * @brief Constructor.
+ *
+ * @param var The variable.
+ * @param new_value The new value to be assigned to \p var.
+ **/
+ template <typename U>
+ ScopedReassignment(T *var, U &&new_value)
+ : var_(*var),
+ old_value_(std::move(*var)) {
+ *var = std::forward<U>(new_value);
+ }
+
+ /**
+ * @brief Destructor. Restores the old value to \p var_.
+ **/
+ ~ScopedReassignment() {
+ var_ = std::move(old_value_);
+ }
+
+ /**
+ * @brief Get the old value.
+ *
+ * @return A const reference to the old value.
+ */
+ inline const T& old_value() const {
+ return old_value_;
+ }
+
+ private:
+ T &var_;
+ T old_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedReassignment);
+};
+
+/** @} */
+
+} // namespace quickstep
+
+#endif // QUICKSTEP_UTILITY_SCOPED_REASSIGNMENT_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3330644c/utility/tests/ScopedReassignment_unittest.cpp
----------------------------------------------------------------------
diff --git a/utility/tests/ScopedReassignment_unittest.cpp b/utility/tests/ScopedReassignment_unittest.cpp
new file mode 100644
index 0000000..daae170
--- /dev/null
+++ b/utility/tests/ScopedReassignment_unittest.cpp
@@ -0,0 +1,189 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ **/
+
+#include "utility/ScopedReassignment.hpp"
+
+#include <cstddef>
+#include <string>
+#include <vector>
+
+#include "utility/Macros.hpp"
+
+#include "gtest/gtest.h"
+
+namespace quickstep {
+
+namespace {
+
+const int kOldValue = 10;
+const int kNewValue = 20;
+
+} // namespace
+
+/**
+ * @brief A test class that is movable but not copyable.
+ */
+class NonCopyable {
+ public:
+ explicit NonCopyable(const int value)
+ : value_(value) {}
+
+ explicit NonCopyable(NonCopyable &&other)
+ : value_(other.value_) {}
+
+ NonCopyable& operator=(NonCopyable &&other) {
+ value_ = other.value_;
+ return *this;
+ }
+
+ int value() const {
+ return value_;
+ }
+
+ private:
+ int value_;
+
+ DISALLOW_COPY_AND_ASSIGN(NonCopyable);
+};
+
+/**
+ * @brief A test class that is copyable but not movable.
+ */
+class NonMovable {
+ public:
+ explicit NonMovable(const int value)
+ : value_(value) {}
+
+ explicit NonMovable(const NonMovable &other)
+ : value_(other.value_) {}
+
+ NonMovable& operator=(const NonMovable &other) {
+ value_ = other.value_;
+ return *this;
+ }
+
+ int value() const {
+ return value_;
+ }
+
+ private:
+ int value_;
+};
+
+/**
+ * @brief A test class that is copyable and movable.
+ */
+class CopyableMovable {
+ public:
+ explicit CopyableMovable(const int value)
+ : value_(value) {}
+
+ explicit CopyableMovable(const CopyableMovable &other)
+ : copy_constructed_(true),
+ value_(other.value_) {}
+
+ explicit CopyableMovable(CopyableMovable &&other)
+ : value_(other.value_) {}
+
+ CopyableMovable& operator=(const CopyableMovable &other) {
+ value_ = other.value_;
+ copy_assigned_ = true;
+ return *this;
+ }
+
+ CopyableMovable& operator=(CopyableMovable &&other) {
+ value_ = other.value_;
+ copy_assigned_ = false;
+ return *this;
+ }
+
+ int value() const {
+ return value_;
+ }
+
+ bool copy_constructed() const {
+ return copy_constructed_;
+ }
+
+ bool copy_assigned() const {
+ return copy_assigned_;
+ }
+
+ private:
+ const bool copy_constructed_ = false;
+ int value_;
+ bool copy_assigned_ = false;
+};
+
+TEST(ScopedReassignment, NonCopyableTest) {
+ NonCopyable non_copyable(kOldValue);
+ {
+ NonCopyable other(kNewValue);
+ ScopedReassignment<NonCopyable> reassign(&non_copyable, std::move(other));
+ EXPECT_EQ(kNewValue, non_copyable.value());
+ }
+ EXPECT_EQ(kOldValue, non_copyable.value());
+
+ {
+ ScopedReassignment<NonCopyable> reassign(&non_copyable, NonCopyable(kNewValue));
+ EXPECT_EQ(kNewValue, non_copyable.value());
+ }
+ EXPECT_EQ(kOldValue, non_copyable.value());
+}
+
+TEST(ScopedReassignment, NonMovableTest) {
+ NonMovable non_movable(kOldValue);
+ {
+ NonMovable other(kNewValue);
+ ScopedReassignment<NonMovable> reassign(&non_movable, other);
+ EXPECT_EQ(kNewValue, non_movable.value());
+ }
+ EXPECT_EQ(kOldValue, non_movable.value());
+
+ {
+ ScopedReassignment<NonMovable> reassign(&non_movable, NonMovable(kNewValue));
+ EXPECT_EQ(kNewValue, non_movable.value());
+ }
+ EXPECT_EQ(kOldValue, non_movable.value());
+}
+
+TEST(ScopedReassignment, CopyableMovableTest) {
+ CopyableMovable copyable_movable(kOldValue);
+ {
+ CopyableMovable other(kNewValue);
+ ScopedReassignment<CopyableMovable> reassign(©able_movable, other);
+ EXPECT_EQ(kNewValue, copyable_movable.value());
+ EXPECT_FALSE(reassign.old_value().copy_constructed());
+ EXPECT_TRUE(copyable_movable.copy_assigned());
+ }
+ EXPECT_EQ(kOldValue, copyable_movable.value());
+ EXPECT_FALSE(copyable_movable.copy_assigned());
+
+ {
+ CopyableMovable other(kNewValue);
+ ScopedReassignment<CopyableMovable> reassign(©able_movable, std::move(other));
+ EXPECT_EQ(kNewValue, copyable_movable.value());
+ EXPECT_FALSE(reassign.old_value().copy_constructed());
+ EXPECT_FALSE(copyable_movable.copy_assigned());
+ }
+ EXPECT_EQ(kOldValue, copyable_movable.value());
+ EXPECT_FALSE(copyable_movable.copy_assigned());
+}
+
+} // namespace quickstep