patch 4.0
This commit is contained in:
@ -10,53 +10,39 @@
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
#include "sql/engine/expr/ob_expr_func_sleep.h"
|
||||
#include "lib/timezone/ob_time_convert.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
namespace sql {
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprSleep::ObExprSleep(ObIAllocator& alloc)
|
||||
ObExprSleep::ObExprSleep(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_SLEEP, N_SYS_SLEEP, 1, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
ObExprSleep::~ObExprSleep()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprSleep::calc_result_type1(ObExprResType& type, ObExprResType& param, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprSleep::calc_result_type1(ObExprResType &type,
|
||||
ObExprResType ¶m,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
type.set_int();
|
||||
type.set_precision(common::ObAccuracy::DDL_DEFAULT_ACCURACY[common::ObIntType].precision_);
|
||||
type.set_scale(common::DEFAULT_SCALE_FOR_INTEGER);
|
||||
CK(OB_NOT_NULL(type_ctx.get_session()));
|
||||
if (OB_SUCC(ret) && type_ctx.get_session()->use_static_typing_engine()) {
|
||||
param.set_calc_type(ObNumberType);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSleep::calc_result1(ObObj& result, const ObObj& param, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
int ret = 0;
|
||||
int64_t usec = 0;
|
||||
number::ObNumber nmb;
|
||||
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
|
||||
EXPR_GET_NUMBER_V2(param, nmb);
|
||||
CK(OB_NOT_NULL(expr_ctx.calc_buf_));
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(get_usec(nmb, usec, *expr_ctx.calc_buf_))) {
|
||||
ret = OB_SUCCESS; // by design
|
||||
result.set_int(0);
|
||||
} else {
|
||||
result.set_int(0);
|
||||
ret = sleep(usec);
|
||||
}
|
||||
param.set_calc_type(ObNumberType);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -64,14 +50,14 @@ int ObExprSleep::calc_result1(ObObj& result, const ObObj& param, ObExprCtx& expr
|
||||
int ObExprSleep::sleep(int64_t usec)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// do not worry about the overflow of this addition
|
||||
// if it does happen, the usec_rem will be 0 inside the while loop
|
||||
// and the loop will be break
|
||||
//do not worry about the overflow of this addition
|
||||
//if it does happen, the usec_rem will be 0 inside the while loop
|
||||
//and the loop will be break
|
||||
int64_t dead_line = ObTimeUtility::current_time() + usec;
|
||||
int64_t usec_rem = usec;
|
||||
useconds_t usec_req = static_cast<useconds_t>(MIN(CHECK_INTERVAL_IN_US, usec_rem));
|
||||
while (usec_req > 0) {
|
||||
(void)usleep(usec_req);
|
||||
while(usec_req > 0) {
|
||||
(void)ob_usleep(usec_req);
|
||||
if (OB_FAIL(THIS_WORKER.check_status())) {
|
||||
break;
|
||||
} else {
|
||||
@ -79,18 +65,18 @@ int ObExprSleep::sleep(int64_t usec)
|
||||
usec_rem = current_time < dead_line ? dead_line - current_time : 0;
|
||||
usec_req = static_cast<useconds_t>(MIN(CHECK_INTERVAL_IN_US, usec_rem));
|
||||
}
|
||||
} // end while
|
||||
}//end while
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSleep::get_usec(const number::ObNumber& nmb, int64_t& value, ObIAllocator& alloc)
|
||||
int ObExprSleep::get_usec(const number::ObNumber &nmb, int64_t &value, ObIAllocator &alloc)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
value = 0;
|
||||
if (OB_SUCC(ret)) {
|
||||
number::ObNumber other;
|
||||
number::ObNumber res;
|
||||
// use nsecond to check range
|
||||
//use nsecond to check range
|
||||
const int64_t nsecs_per_sec = NSECS_PER_SEC;
|
||||
uint64_t tmp = 0;
|
||||
number::ObNumber tmp_nmb;
|
||||
@ -102,22 +88,23 @@ int ObExprSleep::get_usec(const number::ObNumber& nmb, int64_t& value, ObIAlloca
|
||||
LOG_WARN("round nmb failed", K(ret), K(tmp_nmb));
|
||||
} else if (tmp_nmb.mul(other, res, alloc)) {
|
||||
LOG_WARN("mul op failed", K(ret), K(other), K(tmp_nmb));
|
||||
} else if (!res.is_valid_uint64(tmp)) { // based on the behaviour of mysql.
|
||||
} else if (!res.is_valid_uint64(tmp)) { //based on the behaviour of mysql.
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("out of range", K(ret), K(res), K(tmp));
|
||||
} else {
|
||||
// use usecond to calc
|
||||
//use usecond to calc
|
||||
value = tmp / NSECS_PER_USEC;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSleep::eval_sleep(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res)
|
||||
int ObExprSleep::eval_sleep(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* sec = NULL;
|
||||
ObIAllocator& calc_alloc = ctx.get_reset_tmp_alloc();
|
||||
ObDatum *sec = NULL;
|
||||
ObEvalCtx::TempAllocGuard alloc_guard(ctx);
|
||||
ObIAllocator &calc_alloc = alloc_guard.get_allocator();
|
||||
int64_t usec = 0;
|
||||
if (OB_FAIL(expr.eval_param_value(ctx, sec))) {
|
||||
LOG_WARN("eval arg failed", K(ret));
|
||||
@ -131,7 +118,7 @@ int ObExprSleep::eval_sleep(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSleep::cg_expr(ObExprCGCtx& ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprSleep::cg_expr(ObExprCGCtx &ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(ctx);
|
||||
@ -141,5 +128,5 @@ int ObExprSleep::cg_expr(ObExprCGCtx& ctx, const ObRawExpr& raw_expr, ObExpr& rt
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
} //namespace sql
|
||||
} //namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user