Skip to content

Commit 6f9424a

Browse files
author
Bogdan Degtyariov
committed
Merge branch 'wl12497'
2 parents 1ff32ec + 50c757b commit 6f9424a

File tree

6 files changed

+64
-36
lines changed

6 files changed

+64
-36
lines changed

cdk/include/mysql/cdk/mysqlx/session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class Session
550550
void check_protocol_fields();
551551
bool has_prepared_statements();
552552
void set_has_prepared_statements(bool);
553+
bool has_keep_open();
553554

554555
/*
555556
Clear diagnostic information that accumulated for the session.
@@ -562,7 +563,6 @@ class Session
562563
{ m_da.clear(); }
563564

564565
void reset();
565-
566566
void close();
567567

568568
/*

cdk/include/mysql/cdk/protocol/mysqlx.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ struct Protocol_fields
460460
Enum values will be used as binary flags,
461461
so they must be as 2^N
462462
*/
463-
enum value { ROW_LOCKING = 1 , UPSERT = 2, PREPARED_STATEMENTS = 4 };
463+
enum value { ROW_LOCKING = 1 , UPSERT = 2, PREPARED_STATEMENTS = 4,
464+
KEEP_OPEN = 8 };
464465
};
465466

466467
} // api namespace
@@ -533,8 +534,12 @@ class Protocol
533534
Op& snd_CapabilitiesSet(const api::Any::Document& caps);
534535
Op& snd_AuthenticateStart(const char* mechanism, bytes data, bytes response);
535536
Op& snd_AuthenticateContinue(bytes data);
536-
Op& snd_SessionReset();
537-
Op& snd_Close();
537+
// Depending on whether the server supports keep_open in
538+
// SESS_RESET message the session close has to be handled
539+
// differently.
540+
Op& snd_SessionReset(bool keep_open = false);
541+
Op& snd_SessionClose();
542+
Op& snd_ConnectionClose();
538543

539544
/**
540545
Send protocol command which executes a statement.

cdk/mysqlx/session.cc

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct Proto_field_checker : public cdk::protocol::mysqlx::api::Expectations
6060
unsigned int m_code = 0;
6161

6262
void error(unsigned int code, short int,
63-
cdk::protocol::mysqlx::sql_state_t, const string &)
63+
cdk::protocol::mysqlx::sql_state_t, const string &)
6464
{
6565
m_code = code;
6666
}
@@ -79,26 +79,29 @@ struct Proto_field_checker : public cdk::protocol::mysqlx::api::Expectations
7979
}
8080

8181
/*
82-
This method sets the expectation and returns
83-
the field flag if it is supported, otherwise 0 is returned.
82+
This method sets the expectation and returns
83+
the field flag if it is supported, otherwise 0 is returned.
8484
*/
8585
uint64_t is_supported(Protocol_fields::value v)
8686
{
8787
switch (v)
8888
{
89-
case Protocol_fields::ROW_LOCKING:
90-
// Find=17, locking=12
91-
m_data = bytes("17.12");
92-
break;
93-
case Protocol_fields::UPSERT:
94-
// Insert=18, upsert=6
95-
m_data = bytes("18.6");
96-
break;
97-
case Protocol_fields::PREPARED_STATEMENTS:
98-
m_data = bytes("40");
99-
break;
100-
default:
101-
return 0;
89+
case Protocol_fields::ROW_LOCKING:
90+
// Find=17, locking=12
91+
m_data = bytes("17.12");
92+
break;
93+
case Protocol_fields::UPSERT:
94+
// Insert=18, upsert=6
95+
m_data = bytes("18.6");
96+
break;
97+
case Protocol_fields::PREPARED_STATEMENTS:
98+
m_data = bytes("40");
99+
break;
100+
case Protocol_fields::KEEP_OPEN:
101+
m_data = bytes("6.1");
102+
break;
103+
default:
104+
return 0;
102105
}
103106
m_proto.snd_Expect_Open(*this, false).wait();
104107

@@ -109,8 +112,8 @@ struct Proto_field_checker : public cdk::protocol::mysqlx::api::Expectations
109112
if (prc.m_code == 0 || prc.m_code == 5168)
110113
{
111114
/*
112-
The expectation block needs to be closed if no error
113-
or expectation failed error (5168)
115+
The expectation block needs to be closed if no error
116+
or expectation failed error (5168)
114117
*/
115118
m_proto.snd_Expect_Close().wait();
116119
m_proto.rcv_Reply(prc).wait();
@@ -346,6 +349,7 @@ class AuthSha256Memory
346349

347350
};
348351

352+
349353
/*
350354
Class Session
351355
*/
@@ -457,17 +461,18 @@ option_t Session::is_valid()
457461

458462
void Session::check_protocol_fields()
459463
{
464+
wait();
465+
if (0 < entry_count())
466+
get_error().rethrow();
460467
if (m_proto_fields == UINT64_MAX)
461468
{
462-
wait();
463-
if (0 < entry_count())
464-
get_error().rethrow();
465469
Proto_field_checker field_checker(m_protocol);
466470
m_proto_fields = 0;
467471
/* More fields checks will be added here */
468472
m_proto_fields |= field_checker.is_supported(Protocol_fields::ROW_LOCKING);
469473
m_proto_fields |= field_checker.is_supported(Protocol_fields::UPSERT);
470474
m_proto_fields |= field_checker.is_supported(Protocol_fields::PREPARED_STATEMENTS);
475+
m_proto_fields |= field_checker.is_supported(Protocol_fields::KEEP_OPEN);
471476
}
472477
}
473478

@@ -485,6 +490,12 @@ void Session::set_has_prepared_statements(bool x)
485490
m_proto_fields &= ~Protocol_fields::PREPARED_STATEMENTS;
486491
}
487492

493+
bool Session::has_keep_open()
494+
{
495+
check_protocol_fields();
496+
return (m_proto_fields & Protocol_fields::KEEP_OPEN) != 0;
497+
}
498+
488499

489500
option_t Session::check_valid()
490501
{
@@ -495,21 +506,23 @@ option_t Session::check_valid()
495506

496507
void Session::reset()
497508
{
509+
check_protocol_fields(); // This will be used for lazy checks
498510
clear_errors();
499511

500512
m_reply_op_queue.clear();
501513

502514
if (is_valid())
503515
{
504-
m_protocol.snd_SessionReset().wait();
505-
m_protocol.rcv_Reply(*this).wait();
516+
m_protocol.snd_SessionReset(has_keep_open()).wait();
506517

507-
m_isvalid = false;
518+
m_protocol.rcv_Reply(*this).wait();
508519

509-
// Re-authenticate
510-
send_auth();
520+
if (!has_keep_open())
521+
{
522+
m_isvalid = false;
523+
send_auth(); // Re-authenticate for servers not supporting keep-open
524+
}
511525
}
512-
513526
}
514527

515528

@@ -519,7 +532,7 @@ void Session::close()
519532

520533
if (is_valid())
521534
{
522-
m_protocol.snd_Close().wait();
535+
m_protocol.snd_ConnectionClose().wait();
523536
m_protocol.rcv_Reply(*this).wait();
524537
}
525538
m_isvalid = false;

cdk/protocol/mysqlx/pb/mysqlx_session.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ message AuthenticateOk {
9090
}
9191

9292
// reset the current session
93+
// param keep_open: if is true the session will be reset, but stays authenticated.
94+
// otherwise, the session will be closed and needs to be authenticated again.
9395
//
9496
// :Returns: :protobuf:msg:`Mysqlx::Ok`
9597
message Reset {
98+
optional bool keep_open = 1 [ default = false ];
99+
96100
option (client_message_id) = SESS_RESET; // comment_out_if PROTOBUF_LITE
97101
}
98102

cdk/protocol/mysqlx/protocol.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,20 @@ class Rcv_reply : public Op_rcv
855855
};
856856

857857

858-
Protocol::Op& Protocol::snd_SessionReset()
858+
Protocol::Op& Protocol::snd_SessionReset(bool keep_open)
859859
{
860860
Mysqlx::Session::Reset reset;
861+
reset.set_keep_open(keep_open);
861862
return get_impl().snd_start(reset, msg_type::cli_SessionReset);
862863
}
863864

864-
Protocol::Op& Protocol::snd_Close()
865+
Protocol::Op& Protocol::snd_SessionClose()
866+
{
867+
Mysqlx::Session::Close close;
868+
return get_impl().snd_start(close, msg_type::cli_SessionClose);
869+
}
870+
871+
Protocol::Op& Protocol::snd_ConnectionClose()
865872
{
866873
Mysqlx::Connection::Close close;
867874
return get_impl().snd_start(close, msg_type::cli_Close);
@@ -940,7 +947,6 @@ Protocol::Op& Protocol_server::rcv_Command(Cmd_processor &prc)
940947
return get_impl().rcv_start<Rcv_command>(prc);
941948
}
942949

943-
944950
// ------------------------------------------------------------
945951

946952
size_t Processor_base::message_begin_internal(msg_type_t type, bool &flag)

common/session.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ void Session_pool::release_session(cdk::shared_ptr<cdk::Session> &sess)
536536

537537
if (el != m_pool.end())
538538
try {
539-
el->first->reset();
540539
el->second = system_clock::now() + m_time_to_live;
541540
}
542541
catch (...) {
@@ -577,6 +576,7 @@ std::shared_ptr<cdk::Session> Session_pool::get_session()
577576
if (it->first.unique())
578577
{
579578
try {
579+
it->first->reset();
580580
if(!it->first->is_valid())
581581
{
582582
throw "Remove this";

0 commit comments

Comments
 (0)