Skip to content

Commit 6322596

Browse files
author
Bogdan Degtyariov
committed
Bug 26188740 Make mysqlx_session_option_set() function atomic
1 parent 7a8387d commit 6322596

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

xapi/mysqlx.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,20 @@ mysqlx_session_option_set(mysqlx_session_options_t *opt, ...)
16721672
SAFE_EXCEPTION_BEGIN(opt, RESULT_ERROR)
16731673
va_list args;
16741674
va_start(args, opt);
1675-
opt->set_multiple_options(args);
1675+
// Save the options before the call
1676+
mysqlx_session_options_t save_opt;
1677+
save_opt = *opt;
1678+
try
1679+
{
1680+
opt->set_multiple_options(args);
1681+
}
1682+
catch(...)
1683+
{
1684+
// Restore the options state as was before the call
1685+
*opt = save_opt;
1686+
va_end(args);
1687+
throw;
1688+
}
16761689
va_end(args);
16771690

16781691
return RESULT_OK;

xapi/mysqlx_cc_internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,6 @@ typedef struct mysqlx_session_options_struct
461461

462462
public:
463463

464-
/* Move constructor should be disabled */
465-
mysqlx_session_options_struct(mysqlx_session_options_struct &&) = delete;
466-
467464
mysqlx_session_options_struct(source_state state = source_state::unknown)
468465
: m_source_state(state)
469466
{

xapi/session.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const unsigned max_priority = 100;
3333
mysqlx_session_struct::mysqlx_session_struct(
3434
const mysqlx_session_options_t &opt
3535
)
36-
: m_session(opt.get_multi_source()),
36+
: m_session(mysqlx_session_options_t(opt).get_multi_source()),
3737
m_stmt(NULL)
3838
{
3939
const string *db = opt.get_db();

xapi/tests/xapi-t.cc

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ TEST_F(xapi, failover_test)
10441044

10451045
}
10461046

1047-
10481047
TEST_F(xapi, failover_test_url)
10491048
{
10501049
SKIP_IF_NO_XPLUGIN
@@ -1314,6 +1313,68 @@ TEST_F(xapi, conn_options_test)
13141313
}
13151314
}
13161315

1316+
TEST_F(xapi, conn_options_atomic)
1317+
{
1318+
SKIP_IF_NO_XPLUGIN
1319+
1320+
unsigned int port = 0, ssl_mode = SSL_MODE_DISABLED;
1321+
1322+
char buf[1024];
1323+
1324+
const char *test_host1 = "host1";
1325+
const char *test_db1 = "db1";
1326+
const char *test_user1 = "user1";
1327+
const char *test_pwd1 = "pwd1";
1328+
unsigned short test_port1 = 1;
1329+
1330+
const char *test_host2 = "host2";
1331+
const char *test_db2 = "db2";
1332+
const char *test_user2 = "user2";
1333+
const char *test_pwd2 = "pwd2";
1334+
unsigned short test_port2 = 1;
1335+
1336+
mysqlx_session_options_t *opt = mysqlx_session_options_new();
1337+
1338+
// Setting options Call 1
1339+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_set(opt,
1340+
OPT_HOST(test_host1),
1341+
OPT_PORT(test_port1),
1342+
OPT_USER(test_user1),
1343+
OPT_PWD(test_pwd1),
1344+
OPT_DB(test_db1),
1345+
OPT_SSL_MODE(SSL_MODE_REQUIRED),
1346+
PARAM_END));
1347+
1348+
// Setting options Call 2
1349+
EXPECT_EQ(RESULT_ERROR, mysqlx_session_option_set(opt,
1350+
OPT_HOST(test_host2),
1351+
OPT_PORT(test_port2),
1352+
OPT_USER(test_user2),
1353+
OPT_PWD(test_pwd2),
1354+
OPT_DB(test_db2),
1355+
OPT_SSL_MODE(SSL_MODE_DISABLED),
1356+
OPT_SSL_CA("ca.pem"),
1357+
PARAM_END));
1358+
1359+
// Call 2 failed, but opt settings are supposed to be from Call 1
1360+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_HOST, buf));
1361+
EXPECT_STREQ(test_host1, buf);
1362+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_PORT, &port));
1363+
EXPECT_EQ(true, test_port1 == port);
1364+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_USER, buf));
1365+
EXPECT_STREQ(test_user1, buf);
1366+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_PWD, buf));
1367+
EXPECT_STREQ(test_pwd1, buf);
1368+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_DB, buf));
1369+
EXPECT_STREQ(test_db1, buf);
1370+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_SSL_MODE, &ssl_mode));
1371+
EXPECT_EQ(true, SSL_MODE_REQUIRED == ssl_mode);
1372+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_get(opt, MYSQLX_OPT_SSL_CA, buf));
1373+
EXPECT_STREQ("", buf);
1374+
1375+
mysqlx_free_options(opt);
1376+
}
1377+
13171378

13181379
TEST_F(xapi, default_db_test)
13191380
{

0 commit comments

Comments
 (0)