Skip to content

Commit

Permalink
[#59] Fix a couple of bugs in TIME2LONG error code paths; Change ydb_…
Browse files Browse the repository at this point in the history
…timer_start/ydb_hiber_start/ydb_hiber_start_wait_any to return int (instead of void) as they can return YDB_ERR_TIME2LONG
  • Loading branch information
nars1 committed Mar 27, 2018
1 parent 9df07a3 commit dac87e5
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion sr_port/ydberrors.msg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MISSINGVARNAMES <At least one variable name must be specified>/error/fao=0
TOOMANYVARNAMES <Number of varnames specified exceeds maximum (!UL)>/error/fao=1
INVNAMECOUNT <Invalid value for namecount parameter in a !AD call>/error/fao=2
MISSINGVARNAME <Required varname not specified>/error/fao=0
TIME2LONG <Specified time value exceeds supported maximum (!UL)>/error/fao=1
TIME2LONG <Specified time value [0x!16@XQ] exceeds supported maximum [0x!16@XQ]>/error/fao=2
VARNAME2LONG <Variable name length exceeds maximum allowed (!UL)>/error/fao=1
FATALERROR1 <Fatal error raised. Generating core and terminating process. Error: !AD>/error/fao=2
FATALERROR2 <Fatal error raised. Bypassing core generation and terminating process. Error: !AD>/error/fao=2
Expand Down
2 changes: 1 addition & 1 deletion sr_port/ydberrors_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LITDEF err_msg ydberrors[] = {
{ "TOOMANYVARNAMES", "Number of varnames specified exceeds maximum (!UL)", 1 },
{ "INVNAMECOUNT", "Invalid value for namecount parameter in a !AD call", 2 },
{ "MISSINGVARNAME", "Required varname not specified", 0 },
{ "TIME2LONG", "Specified time value exceeds supported maximum (!UL)", 1 },
{ "TIME2LONG", "Specified time value [0x!16@XQ] exceeds supported maximum [0x!16@XQ]", 2 },
{ "VARNAME2LONG", "Variable name length exceeds maximum allowed (!UL)", 1 },
{ "FATALERROR1", "Fatal error raised. Generating core and terminating process. Error: !AD", 2 },
{ "FATALERROR2", "Fatal error raised. Bypassing core generation and terminating process. Error: !AD", 2 },
Expand Down
6 changes: 3 additions & 3 deletions sr_unix/libyottadb.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ void ydb_zstatus(char* msg, int len);

/* Utility entry points accessable in libyottadb.so */
int ydb_file_name_to_id(ydb_string_t *filename, ydb_fileid_ptr_t *fileid);
void ydb_hiber_start(unsigned long long sleep_nsec);
void ydb_hiber_start_wait_any(unsigned long long sleep_nsec);
void ydb_timer_start(int timer_id, unsigned long long limit_nsec, ydb_funcptr_retvoid_t handler, unsigned int hdata_len,
int ydb_hiber_start(unsigned long long sleep_nsec);
int ydb_hiber_start_wait_any(unsigned long long sleep_nsec);
int ydb_timer_start(int timer_id, unsigned long long limit_nsec, ydb_funcptr_retvoid_t handler, unsigned int hdata_len,
void *hdata);
void ydb_timer_cancel(int timer_id);
int ydb_file_is_identical(ydb_fileid_ptr_t fileid1, ydb_fileid_ptr_t fileid2);
Expand Down
14 changes: 14 additions & 0 deletions sr_unix/libyottadb_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,20 @@ MBSTART { \
*/
#define IS_SIMPLEAPI_MODE (frame_pointer->type & SFT_CI)

#define ISSUE_TIME2LONG_ERROR_IF_NEEDED(INPUT_TIME_IN_NANOSECONDS) \
MBSTART { \
unsigned long long max_time_nsec; \
\
assert(SIZEOF(unsigned long long) == SIZEOF(INPUT_TIME_IN_NANOSECONDS)); \
assert(MAXPOSINT4 == (YDB_MAX_TIME_NSEC / NANOSECS_IN_MSEC)); \
if (YDB_MAX_TIME_NSEC < INPUT_TIME_IN_NANOSECONDS) \
{ \
max_time_nsec = YDB_MAX_TIME_NSEC; \
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_TIME2LONG, 2, \
(unsigned long long *)&INPUT_TIME_IN_NANOSECONDS, &max_time_nsec); \
} \
} MBEND

void sapi_return_subscr_nodes(int *ret_subs_used, ydb_buffer_t *ret_subsarray, char *ydb_caller_fn);
void sapi_save_targ_key_subscr_nodes(void);

Expand Down
24 changes: 12 additions & 12 deletions sr_unix/ydb_hiber_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@
#include "error.h"
#include "send_msg.h"
#include "libydberrors.h"
#include "libyottadb_int.h"

/* Simple YottaDB wrapper for gtm_hiber_start() */
void ydb_hiber_start(unsigned long long sleep_nsec)
int ydb_hiber_start(unsigned long long sleep_nsec)
{
int timeoutms;
unsigned long long timeout_msec;
int sleepms;
unsigned long long sleep_msec;
boolean_t error_encountered;
DCL_THREADGBL_ACCESS;

SETUP_THREADGBL_ACCESS;
if (process_exiting)
{ /* YDB runtime environment not setup/available, no driving of errors */
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CALLINAFTERXIT);
return;
return YDB_OK;
}
ESTABLISH_NORET(ydb_simpleapi_ch, error_encountered);
if (error_encountered)
{ /* Some error occurred - just return to the caller ($ZSTATUS is set) */
REVERT;
return;
return -(TREF(ydb_error_code));
}
if (YDB_MAX_TIME_NSEC < sleep_nsec)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_TIME2LONG, 1, YDB_MAX_TIME_NSEC);
timeout_msec = (sleep_nsec / NANOSECS_IN_MSEC);
assert(MAXPOSINT4 > timeout_msec); /* Or else a TIME2LONG error would have been issued above */
timeoutms = (int)timeout_msec;
gtm_hiber_start(timeoutms);
ISSUE_TIME2LONG_ERROR_IF_NEEDED(sleep_nsec);
assert(MAXPOSINT4 >= (sleep_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
sleep_msec = (sleep_nsec / NANOSECS_IN_MSEC);
sleepms = (int)sleep_msec;
gtm_hiber_start(sleepms);
REVERT;
return;
return YDB_OK;
}
24 changes: 12 additions & 12 deletions sr_unix/ydb_hiber_start_wait_any.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@
#include "error.h"
#include "send_msg.h"
#include "libydberrors.h"
#include "libyottadb_int.h"

/* Simple YottaDB wrapper for gtm_hiber_start_wait_any() */
void ydb_hiber_start_wait_any(unsigned long long sleep_nsec)
int ydb_hiber_start_wait_any(unsigned long long sleep_nsec)
{
int timeoutms;
unsigned long long timeout_msec;
int sleepms;
unsigned long long sleep_msec, max_time_nsec;
boolean_t error_encountered;
DCL_THREADGBL_ACCESS;

SETUP_THREADGBL_ACCESS;
if (process_exiting)
{ /* YDB runtime environment not setup/available, no driving of errors */
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CALLINAFTERXIT);
return;
return YDB_OK;
}
ESTABLISH_NORET(ydb_simpleapi_ch, error_encountered);
if (error_encountered)
{ /* Some error occurred - just return to the caller ($ZSTATUS is set) */
REVERT;
return;
return -(TREF(ydb_error_code));
}
if (YDB_MAX_TIME_NSEC < sleep_nsec)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_TIME2LONG, 1, YDB_MAX_TIME_NSEC);
timeout_msec = (sleep_nsec / NANOSECS_IN_MSEC);
assert(MAXPOSINT4 > timeout_msec); /* Or else a TIME2LONG error would have been issued above */
timeoutms = (int)timeout_msec;
hiber_start_wait_any(timeoutms);
ISSUE_TIME2LONG_ERROR_IF_NEEDED(sleep_nsec);
assert(MAXPOSINT4 >= (sleep_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
sleep_msec = (sleep_nsec / NANOSECS_IN_MSEC);
sleepms = (int)sleep_msec;
hiber_start_wait_any(sleepms);
REVERT;
return;
return YDB_OK;
}
6 changes: 2 additions & 4 deletions sr_unix/ydb_lock_incr_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ int ydb_lock_incr_s(unsigned long long timeout_nsec, ydb_buffer_t *varname, int
/* Check if an outofband action that might care about has popped up */
if (outofband)
outofband_action(FALSE);
assert(MAXPOSINT4 == (YDB_MAX_TIME_NSEC / NANOSECS_IN_MSEC));
if (YDB_MAX_TIME_NSEC < timeout_nsec)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_TIME2LONG, 1, YDB_MAX_TIME_NSEC);
ISSUE_TIME2LONG_ERROR_IF_NEEDED(timeout_nsec);
/* Setup and validate the varname */
VALIDATE_VARNAME(varname, var_type, var_svn_index, FALSE);
/* ISV references are not supported for this call */
Expand All @@ -89,7 +87,7 @@ int ydb_lock_incr_s(unsigned long long timeout_nsec, ydb_buffer_t *varname, int
/* At this point, the private lock block has been created. Remaining task before calling "op_incrlock" is to
* convert the timeout value from nanoseconds to seconds
*/
assert(MAXPOSINT4 > (timeout_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
assert(MAXPOSINT4 >= (timeout_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
timeout_sec = (timeout_nsec / NANOSECS_IN_SEC);
i2mval(&timeout_mval, (int)timeout_sec);
lock_rc = op_incrlock(&timeout_mval);
Expand Down
5 changes: 2 additions & 3 deletions sr_unix/ydb_lock_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ int ydb_lock_s(unsigned long long timeout_nsec, int namecount, ...)
/* Check if an outofband action that might care about has popped up */
if (outofband)
outofband_action(FALSE);
if (YDB_MAX_TIME_NSEC < timeout_nsec)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_TIME2LONG, 1, YDB_MAX_TIME_NSEC);
ISSUE_TIME2LONG_ERROR_IF_NEEDED(timeout_nsec);
if (0 > namecount)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_INVNAMECOUNT, 2, RTS_ERROR_LITERAL("ydb_lock_s()"));
/* Need to validate all parms before we can do the unlock of all locks held by us */
Expand Down Expand Up @@ -152,7 +151,7 @@ int ydb_lock_s(unsigned long long timeout_nsec, int namecount, ...)
/* At this point, all of the private lock blocks have been created. Remaining task before calling "op_lock2" is to
* convert the timeout value from microseconds to seconds.
*/
assert(MAXPOSINT4 > (timeout_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
assert(MAXPOSINT4 >= (timeout_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
timeout_sec = (timeout_nsec / NANOSECS_IN_SEC);
i2mval(&timeout_mval, (int)timeout_sec);
/* The generated code typically calls "op_lock" but that routine just calls "op_lock2" */
Expand Down
14 changes: 7 additions & 7 deletions sr_unix/ydb_timer_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#include "error.h"
#include "send_msg.h"
#include "libydberrors.h"
#include "libyottadb_int.h"

/* Simple YottaDB wrapper for gtm_start_timer() */
void ydb_timer_start(int timer_id, unsigned long long limit_nsec, ydb_funcptr_retvoid_t handler, unsigned int hdata_len,
int ydb_timer_start(int timer_id, unsigned long long limit_nsec, ydb_funcptr_retvoid_t handler, unsigned int hdata_len,
void *hdata)
{
int timeoutms;
Expand All @@ -30,20 +31,19 @@ void ydb_timer_start(int timer_id, unsigned long long limit_nsec, ydb_funcptr_re
if (process_exiting)
{ /* YDB runtime environment not setup/available, no driving of errors */
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CALLINAFTERXIT);
return;
return YDB_OK;
}
ESTABLISH_NORET(ydb_simpleapi_ch, error_encountered);
if (error_encountered)
{ /* Some error occurred - just return to the caller ($ZSTATUS is set) */
REVERT;
return;
return -(TREF(ydb_error_code));
}
if (YDB_MAX_TIME_NSEC < limit_nsec)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_TIME2LONG, 1, YDB_MAX_TIME_NSEC);
ISSUE_TIME2LONG_ERROR_IF_NEEDED(limit_nsec);
assert(MAXPOSINT4 >= (limit_nsec / NANOSECS_IN_MSEC)); /* Or else a TIME2LONG error would have been issued above */
timeout_msec = (limit_nsec / NANOSECS_IN_MSEC);
assert(MAXPOSINT4 > timeout_msec); /* Or else a TIME2LONG error would have been issued above */
timeoutms = (int)timeout_msec;
gtm_start_timer(timer_id, timeoutms, handler, hdata_len, hdata);
REVERT;
return;
return YDB_OK;
}

0 comments on commit dac87e5

Please sign in to comment.