Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Do not update session when use space, the sessions will update at the… #1355

Merged
merged 2 commits into from
Sep 17, 2021
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
11 changes: 4 additions & 7 deletions src/validator/UseValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "validator/UseValidator.h"
#include "parser/TraverseSentences.h"
#include "planner/plan/Admin.h"
#include "planner/plan/Logic.h"
#include "planner/plan/Query.h"
#include "planner/plan/Admin.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -42,12 +42,9 @@ Status UseValidator::validateImpl() {

Status UseValidator::toPlan() {
// The input will be set by father validator later.
auto switchSpace = SwitchSpace::make(qctx_, nullptr, *spaceName_);
qctx_->rctx()->session()->updateSpaceName(*spaceName_);
auto session = qctx_->rctx()->session()->getSession();
auto update = UpdateSession::make(qctx_, switchSpace, std::move(session));
root_ = update;
tail_ = switchSpace;
auto reg = SwitchSpace::make(qctx_, nullptr, *spaceName_);
root_ = reg;
tail_ = root_;
return Status::OK();
}
} // namespace graph
Expand Down
34 changes: 10 additions & 24 deletions src/validator/test/AdminValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace nebula {
namespace graph {

using PK = nebula::graph::PlanNode::Kind;
class AdminValidatorTest : public ValidatorTestBase {
};
class AdminValidatorTest : public ValidatorTestBase {};

TEST_F(AdminValidatorTest, SpaceTest) {
{
Expand All @@ -19,58 +18,45 @@ TEST_F(AdminValidatorTest, SpaceTest) {
expected));
}
{
std::vector<PlanNode::Kind> expected = {
PK::kUpdateSession, PK::kSwitchSpace, PK::kCreateSpace, PK::kStart};
std::vector<PlanNode::Kind> expected = {PK::kSwitchSpace, PK::kCreateSpace, PK::kStart};
ASSERT_TRUE(
checkResult("CREATE SPACE TEST(vid_type = fixed_string(2)); USE TEST;", expected));
}
}

TEST_F(AdminValidatorTest, ShowHosts) {
{
std::vector<PlanNode::Kind> expected = {
PK::kShowHosts, PK::kStart
};
std::vector<PlanNode::Kind> expected = {PK::kShowHosts, PK::kStart};
ASSERT_TRUE(checkResult("SHOW HOSTS;", expected));
}
// chain
{
std::vector<PlanNode::Kind> expected = {
PK::kShowHosts, PK::kDescSpace, PK::kStart
};
std::vector<PlanNode::Kind> expected = {PK::kShowHosts, PK::kDescSpace, PK::kStart};
ASSERT_TRUE(checkResult("DESC SPACE TEST; SHOW HOSTS", expected));
}
}

TEST_F(AdminValidatorTest, TestParts) {
{
std::vector<PlanNode::Kind> expected = {
PK::kShowParts, PK::kStart
};
std::vector<PlanNode::Kind> expected = {PK::kShowParts, PK::kStart};
ASSERT_TRUE(checkResult("SHOW PARTS;", expected));
}
{
std::vector<PlanNode::Kind> expected = {
PK::kShowParts, PK::kShowParts, PK::kStart
};
std::vector<PlanNode::Kind> expected = {PK::kShowParts, PK::kShowParts, PK::kStart};
ASSERT_TRUE(checkResult("SHOW PARTS; SHOW PART 3;", expected));
}
}

TEST_F(AdminValidatorTest, TestSessions) {
{
std::vector<PlanNode::Kind> expected = {
PK::kShowSessions, PK::kStart
};
std::vector<PlanNode::Kind> expected = {PK::kShowSessions, PK::kStart};
ASSERT_TRUE(checkResult("SHOW SESSIONS;", expected));
}
{
std::vector<PlanNode::Kind> expected = {
PK::kShowSessions, PK::kStart
};
std::vector<PlanNode::Kind> expected = {PK::kShowSessions, PK::kStart};
ASSERT_TRUE(checkResult("SHOW SESSION 1;", expected));
}
}

} // namespace graph
} // namespace nebula
} // namespace graph
} // namespace nebula
8 changes: 5 additions & 3 deletions tests/job/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def test_sessions(self):
for row in resp.rows():
if bytes.decode(row.values[1].get_sVal()) == 'session_user':
session_id = row.values[0].get_iVal()
assert row.values[2].get_sVal() == b''
assert row.values[3].getType() == ttypes.Value.DTVAL
assert row.values[4].getType() == ttypes.Value.DTVAL
assert row.values[2].get_sVal() == b'', f"resp: {resp}"
assert row.values[3].getType() == ttypes.Value.DTVAL, f"resp: {resp}"
assert row.values[4].getType() == ttypes.Value.DTVAL, f"resp: {resp}"
break

assert session_id != 0
Expand All @@ -99,6 +99,8 @@ def test_sessions(self):
resp = client_ok.execute('USE nba')
self.check_resp_succeeded(resp)

# wait for session sync.
time.sleep(3)
resp = self.execute('SHOW SESSION {}'.format(session_id))
self.check_resp_succeeded(resp)
expect_col_names = ['VariableName', 'Value']
Expand Down