Skip to content

Commit a04aedd

Browse files
committed
wl11374: DevAPI: Support locking modes : NOWAIT and SKIP LOCKED
Change Errors/Warnings logic when FetchDone is received!
1 parent 7f1d554 commit a04aedd

File tree

25 files changed

+613
-170
lines changed

25 files changed

+613
-170
lines changed

cdk/include/mysql/cdk/api/query.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ struct Lock_mode
138138
enum value { NONE, SHARED, EXCLUSIVE };
139139
};
140140

141+
struct Lock_contention
142+
{
143+
enum value { DEFAULT, NOWAIT, SKIP_LOCKED };
144+
};
145+
141146

142147
/*
143148
View specifications.

cdk/include/mysql/cdk/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ typedef cdk::api::Order_by<Expression> Order_by;
529529
typedef cdk::api::Sort_direction Sort_direction;
530530
typedef cdk::api::Doc_base<Value_processor> Param_source;
531531
typedef cdk::api::Lock_mode::value Lock_mode_value;
532+
typedef cdk::api::Lock_contention::value Lock_contention_value;
532533

533534
using cdk::api::View_security;
534535
using cdk::api::View_algorithm;

cdk/include/mysql/cdk/mysqlx/result.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ class Cursor
248248
m_session.error(code, severity, sql_state, msg);
249249
}
250250

251-
void notice(unsigned int /*type*/, short int /*scope*/, bytes /*payload*/)
252-
{ //TODO: Finish notice here
251+
void notice(unsigned int type, short int scope, bytes payload)
252+
{
253+
m_session.notice(type, scope, payload);
253254
}
254255

255256
};

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ class Session
572572
const Expression *having = NULL,
573573
const Limit *lim = NULL,
574574
const Param_source *param = NULL,
575-
const Lock_mode_value lock_mode = Lock_mode_value::NONE);
575+
const Lock_mode_value lock_mode = Lock_mode_value::NONE,
576+
const Lock_contention_value lock_contention
577+
= Lock_contention_value::DEFAULT);
576578
Reply_init &coll_update(const api::Table_ref&,
577579
const Expression*,
578580
const Update_spec&,
@@ -594,7 +596,8 @@ class Session
594596
const Expression *having = NULL,
595597
const Limit *lim = NULL,
596598
const Param_source *param = NULL,
597-
const Lock_mode_value lock_mode = Lock_mode_value::NONE);
599+
const Lock_mode_value lock_mode = Lock_mode_value::NONE,
600+
const Lock_contention_value lock_contention = Lock_contention_value::DEFAULT);
598601
Reply_init &table_insert(const Table_ref&,
599602
Row_source&,
600603
const api::Columns *cols,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ typedef cdk::api::Sort_direction Sort_direction;
420420
typedef cdk::api::Projection<Expression> Projection;
421421
typedef cdk::api::Columns Columns;
422422
typedef cdk::api::Lock_mode::value Lock_mode_value;
423+
typedef cdk::api::Lock_contention::value Lock_contention_value;
423424

424425
typedef cdk::api::View_options View_options;
425426

@@ -484,11 +485,13 @@ struct Find_spec : public Select_spec
484485
typedef api::Projection Projection;
485486
typedef api::Expr_list Expr_list;
486487
typedef api::Lock_mode_value Lock_mode_value;
488+
typedef api::Lock_contention_value Lock_contention_value;
487489

488490
virtual const Projection* project() const = 0;
489491
virtual const Expr_list* group_by() const = 0;
490492
virtual const Expression* having() const = 0;
491493
virtual Lock_mode_value locking() const = 0;
494+
virtual Lock_contention_value contention() const = 0;
492495
};
493496

494497

cdk/include/mysql/cdk/session.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,13 @@ class Session
311311
const Expression *having = NULL,
312312
const Limit *lim = NULL,
313313
const Param_source *param = NULL,
314-
const Lock_mode_value lock_mode = Lock_mode_value::NONE
314+
const Lock_mode_value lock_mode = Lock_mode_value::NONE,
315+
const Lock_contention_value lock_contention = Lock_contention_value::DEFAULT
315316
)
316317
{
317318
return m_session->coll_find(coll, view, expr, proj, order_by,
318-
group_by, having, lim, param, lock_mode);
319+
group_by, having, lim, param,
320+
lock_mode, lock_contention);
319321
}
320322

321323
/**
@@ -365,10 +367,12 @@ class Session
365367
const Expression *having = NULL,
366368
const Limit* lim = NULL,
367369
const Param_source *param = NULL,
368-
const Lock_mode_value lock_mode = Lock_mode_value::NONE)
370+
const Lock_mode_value lock_mode = Lock_mode_value::NONE,
371+
const Lock_contention_value lock_contention = Lock_contention_value::DEFAULT)
369372
{
370373
return m_session->table_select(tab, view, expr, proj, order_by,
371-
group_by, having, lim, param, lock_mode);
374+
group_by, having, lim, param,
375+
lock_mode, lock_contention);
372376
}
373377

374378
/**

cdk/mysqlx/delayed_op.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,11 @@ class SndFind
574574
typedef typename Find_traits<DM>::Projection Projection;
575575
typedef typename Find_traits<DM>::Projection_converter Projection_converter;
576576

577-
Projection_converter m_proj_conv;
578-
Expr_list_converter m_group_by_conv;
579-
Expr_converter m_having_conv;
580-
Lock_mode_value m_lock_mode;
577+
Projection_converter m_proj_conv;
578+
Expr_list_converter m_group_by_conv;
579+
Expr_converter m_having_conv;
580+
Lock_mode_value m_lock_mode;
581+
Lock_contention_value m_lock_contention;
581582

582583
Proto_op* start()
583584
{
@@ -595,12 +596,14 @@ class SndFind
595596
const cdk::Expression *having = NULL,
596597
const cdk::Limit *lim = NULL,
597598
const cdk::Param_source *param = NULL,
598-
const Lock_mode_value locking = Lock_mode_value::NONE
599+
const Lock_mode_value locking = Lock_mode_value::NONE,
600+
const Lock_contention_value contention = Lock_contention_value::DEFAULT
599601
)
600602
: Select_op_base(protocol, coll, expr, order_by, lim, param)
601603
, m_proj_conv(proj)
602604
, m_group_by_conv(group_by), m_having_conv(having)
603605
, m_lock_mode(locking)
606+
, m_lock_contention(contention)
604607
{}
605608

606609
private:
@@ -625,6 +628,11 @@ class SndFind
625628
return m_lock_mode;
626629
}
627630

631+
Lock_contention_value contention() const
632+
{
633+
return m_lock_contention;
634+
}
635+
628636
friend class SndViewCrud<DM>;
629637
};
630638

cdk/mysqlx/session.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,8 @@ Reply_init& Session::coll_find(const Table_ref &coll,
621621
const Expression *having,
622622
const Limit *lim,
623623
const Param_source *param,
624-
const Lock_mode_value lock_mode)
624+
const Lock_mode_value lock_mode,
625+
const Lock_contention_value lock_contention)
625626
{
626627
if (lock_mode != Lock_mode_value::NONE &&
627628
!(m_proto_fields & Protocol_fields::ROW_LOCKING))
@@ -630,7 +631,7 @@ Reply_init& Session::coll_find(const Table_ref &coll,
630631
SndFind<protocol::mysqlx::DOCUMENT> *find
631632
= new SndFind<protocol::mysqlx::DOCUMENT>(
632633
m_protocol, coll, expr, proj, order_by,
633-
group_by, having, lim, param, lock_mode
634+
group_by, having, lim, param, lock_mode, lock_contention
634635
);
635636

636637
if (view)
@@ -683,7 +684,8 @@ Reply_init& Session::table_select(const Table_ref &coll,
683684
const Expression *having,
684685
const Limit *lim,
685686
const Param_source *param,
686-
const Lock_mode_value lock_mode)
687+
const Lock_mode_value lock_mode,
688+
const Lock_contention_value lock_contention)
687689
{
688690
if (lock_mode != Lock_mode_value::NONE &&
689691
!(m_proto_fields & Protocol_fields::ROW_LOCKING))
@@ -692,7 +694,7 @@ Reply_init& Session::table_select(const Table_ref &coll,
692694
SndFind<protocol::mysqlx::TABLE> *find
693695
= new SndFind<protocol::mysqlx::TABLE>(
694696
m_protocol, coll, expr, proj, order_by,
695-
group_by, having, lim, param, lock_mode
697+
group_by, having, lim, param, lock_mode, lock_contention
696698
);
697699

698700
if (view)

cdk/protocol/mysqlx/crud.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,19 @@ void set_find(Mysqlx::Crud::Find &msg,
486486
break;
487487
}
488488

489+
switch (fs.contention())
490+
{
491+
case api::Lock_contention_value::NOWAIT:
492+
msg.set_locking_options(Mysqlx::Crud::Find_RowLockOptions_NOWAIT);
493+
break;
494+
case api::Lock_contention_value::SKIP_LOCKED:
495+
msg.set_locking_options(Mysqlx::Crud::Find_RowLockOptions_SKIP_LOCKED);
496+
break;
497+
case api::Lock_contention_value::DEFAULT:
498+
default: // do nothing
499+
break;
500+
}
501+
489502
}
490503

491504

cdk/protocol/mysqlx/rset.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ Op_rcv::Next_msg Rcv_result_base::do_next_msg(msg_type_t type)
426426
the following messages:
427427
428428
- Row - next row from the row-set, we continue reading rows until we
429-
see <more>;
429+
see <more>;
430430
431431
- FetchDoneXXX - these messages start <more> sequence; they are consumed
432-
as part of this stage and the next stage starts.
432+
as part of this stage and the next stage starts.
433433
*/
434434

435435
switch (type)
@@ -440,6 +440,9 @@ Op_rcv::Next_msg Rcv_result_base::do_next_msg(msg_type_t type)
440440
break;
441441
case msg_type::FetchDoneMoreResultsets:
442442
m_next_state = MDATA; // proceed to next result-set
443+
444+
445+
443446
break;
444447
default: return UNEXPECTED;
445448
};

common/op_impl.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,10 @@ class Op_select : public Base
868868
string m_where_expr;
869869
bool m_where_set = false;
870870
std::unique_ptr<parser::Expression_parser> m_expr;
871-
cdk::Lock_mode_value m_lock_mode = cdk::api::Lock_mode::NONE;
871+
cdk::Lock_mode_value m_lock_mode = cdk::api::Lock_mode::NONE;
872+
cdk::Lock_contention_value
873+
m_lock_contention = cdk::api::Lock_contention::DEFAULT;
874+
872875

873876
// Note: we do not copy m_expr to avoid invoking copy ctor
874877
// for Expression_parser
@@ -877,6 +880,8 @@ class Op_select : public Base
877880
: Base(other)
878881
, m_where_expr(other.m_where_expr)
879882
, m_where_set(other.m_where_set)
883+
, m_lock_mode(other.m_lock_mode)
884+
, m_lock_contention(other.m_lock_contention)
880885
{}
881886

882887
public:
@@ -890,16 +895,18 @@ class Op_select : public Base
890895
m_where_set = true;
891896
}
892897

893-
void set_lock_mode(Lock_mode lm) override
898+
void set_lock_mode(Lock_mode lm, Lock_contention contention) override
894899
{
895900
// Note: assumes the cdk::Lock_mode enum uses the same values as
896901
// common::Select_if::Lock_mode.
897902
m_lock_mode = cdk::Lock_mode_value(lm);
903+
m_lock_contention = cdk::Lock_contention_value(int(contention));
898904
}
899905

900906
void clear_lock_mode() override
901907
{
902908
m_lock_mode = cdk::api::Lock_mode::NONE;
909+
m_lock_contention = cdk::api::Lock_contention::DEFAULT;
903910
}
904911

905912
cdk::Expression* get_where() const
@@ -1852,7 +1859,8 @@ class Op_collection_find
18521859
get_having(),
18531860
get_limit(),
18541861
get_params(),
1855-
m_lock_mode
1862+
m_lock_mode,
1863+
m_lock_contention
18561864
));
18571865
}
18581866

@@ -2180,16 +2188,17 @@ class Op_table_select
21802188
{
21812189
return
21822190
new cdk::Reply(get_cdk_session().table_select(
2183-
m_table,
2184-
m_view, // view spec
2185-
get_where(),
2186-
get_tbl_proj(),
2187-
get_order_by(),
2188-
get_group_by(),
2189-
get_having(),
2190-
get_limit(),
2191-
get_params(),
2192-
m_lock_mode
2191+
m_table,
2192+
m_view, // view spec
2193+
get_where(),
2194+
get_tbl_proj(),
2195+
get_order_by(),
2196+
get_group_by(),
2197+
get_having(),
2198+
get_limit(),
2199+
get_params(),
2200+
m_lock_mode,
2201+
m_lock_contention
21932202
));
21942203
}
21952204

common/result.cc

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ bool Result_impl_base::next_result()
202202
m_mdata.reset();
203203
clear_cache();
204204
m_pending_rows = false;
205-
clear_diagnostics();
206205
m_inited = true;
207206

208207

@@ -241,8 +240,12 @@ const Row_data* Result_impl_base::get_row()
241240
{
242241
// TODO: Session parameter for cache prefetch size
243242

244-
if (!load_cache(1024))
243+
if (!load_cache(16))
244+
{
245+
if (m_reply->entry_count() > 0)
246+
m_reply->get_error().rethrow();
245247
return nullptr;
248+
}
246249

247250
assert(!m_row_cache.empty());
248251

@@ -295,11 +298,11 @@ bool Result_impl_base::load_cache(row_count_t prefetch_size)
295298
Cleanup after reading all rows.
296299
*/
297300

298-
if (!m_pending_rows)
301+
if (!m_pending_rows || m_reply->entry_count() > 0)
299302
{
300303
m_cursor->close();
301304
m_sess->deregister_result(this);
302-
load_diagnostics();
305+
m_pending_rows = false;
303306
}
304307

305308
return !m_row_cache.empty();
@@ -337,43 +340,3 @@ void Result_impl_base::end_of_data()
337340
{
338341
m_pending_rows = false;
339342
}
340-
341-
// Handle diagnostic information.
342-
343-
344-
void Result_impl_base::load_diagnostics()
345-
{
346-
assert(m_reply);
347-
348-
/*
349-
Flag m_all_warnings tells if all warnings for this result have
350-
been collected in m_warnings. If this is the case then there is
351-
nothing to do.
352-
353-
Otherwise we copy currently available warnings to m_warnings and
354-
check if complete reply has been processed (m_reply->has_results()
355-
returns false). In that case we can set m_all_warnings to true,
356-
because we know that no more warnings will be reported. Otherwise
357-
the flag remains false and we will re-load warnings on a next call.
358-
This way newly reported warnings (if any) will land in m_warnings
359-
list.
360-
361-
Note: A better handling of warnings would be with asynchronous
362-
notifications about new warnings which would be appended to m_warnings
363-
list. But this is not yet implemented in CDK.
364-
*/
365-
366-
if (m_diag_ready)
367-
return;
368-
369-
if (!m_reply->has_results())
370-
m_diag_ready = true;
371-
372-
Diagnostic_arena::clear();
373-
374-
for (auto &it = m_reply->get_entries(cdk::api::Severity::WARNING); it.next();)
375-
{
376-
auto &entry = it.entry();
377-
add_entry(entry.severity(), entry.get_error().clone());
378-
}
379-
}

0 commit comments

Comments
 (0)