Skip to content

Commit

Permalink
[#59] 5 more TODOs complete
Browse files Browse the repository at this point in the history
21. [DONE] Add condition handlers to utility routines.

22. [DONE] Add check for process_exiting to utility routines to prevent
    calls after YottaDB closes down (ydb_exit driven).

23. [DONE] Make TPTIMEOUT work. Added outofband checking to each
    simpleAPI call and blocked the other 3 (maybe 4) outofband
    types if the environment is simpleAPI (current frame is simpleAPI
    base frame). Also allow ^C (in outofband processing) to exit for
    simpleAPI mode.

26. [DONE] Change ydb_exit() where it checks that it is not running an
    external call that check should be bypassed when the process is
    exiting (process_exiting is set).

28. [DONE] Change YDB_MAX_STR from (1 * 1000 * 1000) to (1 * 1024 * 1024).
  • Loading branch information
estess authored and nars1 committed Mar 27, 2018
1 parent d333bac commit 6cb15fa
Show file tree
Hide file tree
Showing 36 changed files with 426 additions and 107 deletions.
8 changes: 4 additions & 4 deletions sr_linux/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,33 @@ set(gtm_dep "${YDB_BINARY_DIR}/ydbexe_symbols.export")

set(libyottadb_link "-Wl,-u,ydb_ci -Wl,-u,gtm_filename_to_id -Wl,-u,gtm_is_main_thread")
set(libyottadb_link "${libyottadb_link} -Wl,-u,accumulate -Wl,-u,is_big_endian -Wl,-u,to_ulong")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_cancel_timer")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_child_init")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_data_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_delete_excl_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_delete_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_file_id_free")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_file_is_identical")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_file_name_to_id")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_fork_n_core")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_free")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_get_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_hiber_start")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_hiber_start_wait_any")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_incr_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_is_file_identical")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_is_main_thread")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_lock_decr_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_lock_incr_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_lock_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_malloc")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_node_next_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_node_previous_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_set_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_start_timer")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_stdout_stderr_adjust")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_str2zwr_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_subscript_next_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_subscript_previous_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_thread_is_main")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_timer_cancel")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_timer_start")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_tp_s")
set(libyottadb_link "${libyottadb_link} -Wl,-u,ydb_zwr2str_s")
set(libyottadb_link "${libyottadb_link} -Wl,--version-script,\"${YDB_BINARY_DIR}/yottadb_symbols.export\"")
Expand Down
35 changes: 23 additions & 12 deletions sr_port/outofband_action.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/****************************************************************
* *
* Copyright 2001, 2014 Fidelity Information Services, Inc *
* Copyright 2001, 2014 Fidelity Information Services, Inc *
* *
* Copyright (c) 2017-2018 YottaDB LLC. and/or its subsidiaries.*
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
Expand All @@ -12,10 +15,12 @@
#include "mdef.h"

#include "gtm_stdio.h"

#include "io.h"
#include <rtnhdr.h>
#include "rtnhdr.h"
#include "stack_frame.h"
#include "outofband.h"
#include "libyottadb_int.h"

GBLREF io_pair io_std_device;
GBLREF stack_frame *frame_pointer;
Expand All @@ -41,24 +46,30 @@ void outofband_action(boolean_t lnfetch_or_start)
}
switch(outofband)
{
case (ctrly):
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CTRLY);
case (ctrly): /* This signal is ignored in simpleAPI */
if (!(IS_SIMPLEAPI_MODE))
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CTRLY);
break;
case (ctrlc):
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CTRLC);
if (!(IS_SIMPLEAPI_MODE))
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_CTRLC);
else
exit(ERR_CTRLC);
break;
case (ctrap):
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_CTRAP, 1, ctrap_action_is);
case (ctrap): /* This signal is ignored in simpleAPI */
if (!(IS_SIMPLEAPI_MODE))
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_CTRAP, 1, ctrap_action_is);
break;
case (tptimeout):
/*
* Currently following is nothing but an rts_error.
* Function pointer is used flexibility.
/* Currently following is nothing but an rts_error. Function pointer is used flexibility.
*
* Note this is the only outofband currently allowed for simpleAPI functions.
*/
(*tp_timeout_action_ptr)();
break;
case (jobinterrupt):
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_JOBINTRRQST);
case (jobinterrupt): /* This signal is ignored in simpleAPI */
if (!(IS_SIMPLEAPI_MODE))
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_JOBINTRRQST);
break;
default:
assertpro(FALSE);
Expand Down
30 changes: 21 additions & 9 deletions sr_unix/gtm_unique_file_util.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/****************************************************************
* *
* Copyright 2009, 2014 Fidelity Information Services, Inc *
* Copyright 2009, 2014 Fidelity Information Services, Inc *
* *
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
Expand All @@ -16,32 +19,41 @@
#include "iosp.h" /* for SS_NORMAL */

/* Checks whether the two fileids passed are identical */
xc_status_t gtm_is_file_identical(xc_fileid_ptr_t fileid1, xc_fileid_ptr_t fileid2)
ydb_status_t gtm_is_file_identical(ydb_fileid_ptr_t fileid1, ydb_fileid_ptr_t fileid2)
{
if (!fileid1 || (!fileid2)) return FALSE;
if (!fileid1 || (!fileid2))
return FALSE;
return is_gdid_identical((gd_id_ptr_t) fileid1, (gd_id_ptr_t) fileid2);
}

/* Converts given filename to unique file id. Uses filename_to_id internally for getting the unique id. Note that,
* the allocation of the fileid structure is done here and the caller needs to worry only about free'ing the
* allocated pointer via gtm_xcfileid_free. */
xc_status_t gtm_filename_to_id(xc_string_t *filename, xc_fileid_ptr_t *fileid)
ydb_status_t gtm_filename_to_id(ydb_string_t *filename, ydb_fileid_ptr_t *fileid)
{
int actstatus;
boolean_t status;
gd_id_ptr_t tmp_fileid;

if (!filename)
return FALSE;
assert(fileid && !*fileid);
tmp_fileid = (gd_id_ptr_t)malloc(SIZEOF(gd_id));
status = (SS_NORMAL == filename_to_id(tmp_fileid, filename->address));
*fileid = (xc_fileid_ptr_t)tmp_fileid;
return status;
actstatus = filename_to_id(tmp_fileid, filename->address);
status = (SS_NORMAL == actstatus);
if (status)
*fileid = (ydb_fileid_ptr_t)tmp_fileid;
else
{ /* There was an error */
free(tmp_fileid);
*fileid = NULL;
}
return status ? YDB_OK : actstatus;
}

/* Allocation of xc_fileid_ptr_t happens in gtm_filename_to_id. During the close time, encryption library needs to free these
/* Allocation of ydb_fileid_ptr_t happens in gtm_filename_to_id. During the close time, encryption library needs to free these
* externally allocated resources and this is done through this function. */
void gtm_xcfileid_free(xc_fileid_ptr_t fileid)
void gtm_xcfileid_free(ydb_fileid_ptr_t fileid)
{
if (NULL != fileid)
free(fileid);
Expand Down
5 changes: 3 additions & 2 deletions sr_unix/gtmci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,9 @@ int ydb_exit()
return 0; /* GT.M environment not setup yet - quietly return */
ESTABLISH_RET(gtmci_ch, mumps_status);
assert(NULL != frame_pointer);
/* Do not allow ydb_exit() to be invoked from external calls */
if (!(SFT_CI & frame_pointer->type) || !(MUMPS_CALLIN & invocation_mode) || (1 < TREF(gtmci_nested_level)))
/* Do not allow ydb_exit() to be invoked from external calls (unless process_exiting) */
if (process_exiting || (!(SFT_CI & frame_pointer->type) || !(MUMPS_CALLIN & invocation_mode)
|| (1 < TREF(gtmci_nested_level))))
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_INVYDBEXIT);
/* Now get rid of the whole M stack - end of GT.M environment */
while (NULL != frame_pointer)
Expand Down
29 changes: 14 additions & 15 deletions sr_unix/libyottadb.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum ydb_error_severity
#define YDB_MAX_IDENT 31 /* Maximum size of global/local name (not including '^') */
#define YDB_MAX_NAMES 255 /* Maximum number of variable names can be specified in a single ydb_*_s() call */
/* Note YDB_MAX_NAMES may be temporary and currently only relates to ydb_delete_excl_s() and ydb_tp_s() */
#define YDB_MAX_STR (1 * 1000 * 1000) /* Maximum YottaDB string length */
#define YDB_MAX_STR (1 * 1024 * 1024) /* Maximum YottaDB string length */
#define YDB_MAX_SUBS 31 /* Maximum subscripts currently supported */
#define YDB_MAX_LOCKTIME (0x7fffffffllu * 1000llu * 1000llu) /* Max lock time in (long long) nanoseconds */

Expand Down Expand Up @@ -248,20 +248,19 @@ ydb_status_t ydb_cij(const char *c_rtn_name, char **arg_blob, int count, int *ar
void ydb_zstatus(char* msg, int len);

/* Utility entry points accessable in libyottadb.so */
ydb_status_t ydb_file_name_to_id(ydb_string_t *filename, ydb_fileid_ptr_t *fileid);
void ydb_hiber_start(unsigned long long mssleep);
void ydb_hiber_start_wait_any(unsigned long long mssleep);
void ydb_start_timer(ydb_tid_t tid, unsigned long long time_to_expir, void (*handler)(), ydb_int_t hdata_len,
void *hdata);
void ydb_cancel_timer(ydb_tid_t tid);
ydb_status_t ydb_is_file_identical(ydb_fileid_ptr_t fileid1, ydb_fileid_ptr_t fileid2);
void ydb_file_id_free(ydb_fileid_ptr_t fileid);
int ydb_is_main_thread(void);
void *ydb_malloc(size_t);
void ydb_free(void *);
void ydb_fork_n_core(void);
int ydb_child_init(void *param);
int ydb_stdout_stderr_adjust(void);
int ydb_file_name_to_id(ydb_string_t *filename, ydb_fileid_ptr_t *fileid);
void ydb_hiber_start(unsigned long long mssleep);
void ydb_hiber_start_wait_any(unsigned long long mssleep);
void ydb_timer_start(ydb_tid_t tid, unsigned long long time_to_expir, void (*handler)(), ydb_int_t hdata_len, void *hdata);
void ydb_timer_cancel(ydb_tid_t tid);
int ydb_file_is_identical(ydb_fileid_ptr_t fileid1, ydb_fileid_ptr_t fileid2);
int ydb_file_id_free(ydb_fileid_ptr_t fileid);
int ydb_thread_is_main(void);
void *ydb_malloc(size_t);
void ydb_free(void *);
void ydb_fork_n_core(void);
int ydb_child_init(void *param);
int ydb_stdout_stderr_adjust(void);

typedef int (*ydb_tpfnptr_t)(void *tpfnparm);

Expand Down
12 changes: 5 additions & 7 deletions sr_unix/libyottadb_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ MBSTART { \
SETUP_THREADGBL_ACCESS; \
} \
/* If we detect a problem here, the routine has not yet established the condition handler to take \
* care of these issues so we invoke it directly. \
* care of these issues so we invoke it directly. Veryify routines are not nesting. \
*/ \
if ((LYDB_RTN_NONE != TREF(libyottadb_active_rtn)) && (LYDB_SIMPLEAPI == lydbrtnpkg[ROUTINE])) \
{ \
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_SIMPLEAPINEST, 4, \
RTS_ERROR_TEXT(lydbrtnnames[TREF(libyottadb_active_rtn)]), \
RTS_ERROR_TEXT(lydbrtnnames[ROUTINE])); \
SET_ERROR_CONDITION(ERR_SIMPLEAPINEST); \
ydb_simpleapi_ch(ERR_SIMPLEAPINEST); \
assertpro(FALSE); \
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_SIMPLEAPINEST, 4, \
RTS_ERROR_TEXT(lydbrtnnames[TREF(libyottadb_active_rtn)]), \
RTS_ERROR_TEXT(lydbrtnnames[ROUTINE])); \
return YDB_ERR_SIMPLEAPINEST; \
} \
TREF(libyottadb_active_rtn) = ROUTINE; \
} MBEND
Expand Down
4 changes: 2 additions & 2 deletions sr_unix/sig_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void sig_init(void (*signal_handler)(), void (*ctrlc_handler)(), void (*suspsig_
*/
sigaction(sig, NULL, &check); /* Fetch current ^C handler */
if (SIG_DFL == check.sa_handler)
{ /* No handler defined - it gets a NULL handler instead */
sigaction(sig, &ignore, NULL);
{ /* No handler defined - it gets the passed in handler instead */
sigaction(sig, &ctrlc_action, NULL);
} /* else we leave the handler alone */
}
break;
Expand Down
8 changes: 7 additions & 1 deletion sr_unix/ydb_data_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
#include "gdsbt.h"
#include "gdsfhead.h"
#include "mvalconv.h"
#include "outofband.h"

LITREF mval literal_zero;
GBLREF volatile int4 outofband;

LITREF mval literal_zero;

/* Routine to return existance of given nodes and existence of descendants
*
Expand Down Expand Up @@ -70,6 +73,9 @@ int ydb_data_s(ydb_buffer_t *varname, int subs_used, ydb_buffer_t *subsarray, un
REVERT;
return ((ERR_TPRETRY == SIGNAL) ? YDB_TP_RESTART : -(TREF(ydb_error_code)));
}
/* Check if an outofband action that might care about has popped up */
if (outofband)
outofband_action(FALSE);
/* Do some validation */
VALIDATE_VARNAME(varname, data_type, data_svn_index, FALSE);
if (0 > subs_used)
Expand Down
6 changes: 6 additions & 0 deletions sr_unix/ydb_delete_excl_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "op.h"
#include "error.h"
#include "stringpool.h"
#include "outofband.h"

GBLREF volatile int4 outofband;

/* Routine to get local, global and ISV values
*
Expand Down Expand Up @@ -58,6 +61,9 @@ int ydb_delete_excl_s(int namecount, ydb_buffer_t *varnames)
REVERT;
return ((ERR_TPRETRY == SIGNAL) ? YDB_TP_RESTART : -(TREF(ydb_error_code)));
}
/* Check if an outofband action that might care about has popped up */
if (outofband)
outofband_action(FALSE);
if (0 >= namecount)
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_MISSINGVARNAMES);
if (YDB_MAX_NAMES < namecount)
Expand Down
6 changes: 6 additions & 0 deletions sr_unix/ydb_delete_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "gdsbt.h"
#include "gdsfhead.h"
#include "mvalconv.h"
#include "outofband.h"

GBLREF volatile int4 outofband;

/* Routine to delete/kill an lvn/gvn.
*
Expand Down Expand Up @@ -70,6 +73,9 @@ int ydb_delete_s(ydb_buffer_t *varname, int subs_used, ydb_buffer_t *subsarray,
REVERT;
return ((ERR_TPRETRY == SIGNAL) ? YDB_TP_RESTART : -(TREF(ydb_error_code)));
}
/* Check if an outofband action that might care about has popped up */
if (outofband)
outofband_action(FALSE);
/* If the varname pointer is null, this implies a local var kill-all. Check for that before attempting to
* validate a name that may not be specified.
*/
Expand Down
22 changes: 21 additions & 1 deletion sr_unix/ydb_file_id_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,29 @@
#include "mdef.h"

#include "gtmxc_types.h"
#include "error.h"
#include "send_msg.h"
#include "libydberrors.h"

/* Simple YottaDB wrapper for the gtm_xcfileid_free() utility function */
void ydb_file_id_free(ydb_fileid_ptr_t fileid)
int ydb_file_id_free(ydb_fileid_ptr_t fileid)
{
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 YDB_ERR_CALLINAFTERXIT;
}
ESTABLISH_NORET(ydb_simpleapi_ch, error_encountered);
if (error_encountered)
{ /* Some error occurred - return the error code to the caller ($ZSTATUS is set) */
REVERT;
return -(TREF(ydb_error_code));
}
gtm_xcfileid_free(fileid);
REVERT;
return YDB_OK;
}
42 changes: 42 additions & 0 deletions sr_unix/ydb_file_is_identical.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************
* *
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/

#include "mdef.h"

#include "gtmxc_types.h"
#include "error.h"
#include "send_msg.h"
#include "libydberrors.h"

/* Simple YottaDB wrapper for the gtm_is_file_identical() utility function */
int ydb_file_is_identical(ydb_fileid_ptr_t fileid1, ydb_fileid_ptr_t fileid2)
{
boolean_t error_encountered;
int status;
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 YDB_ERR_CALLINAFTERXIT;
}
ESTABLISH_NORET(ydb_simpleapi_ch, error_encountered);
if (error_encountered)
{ /* Some error occurred - return the error code to the caller ($ZSTATUS is set) */
REVERT;
return -(TREF(ydb_error_code));
}
status = gtm_is_file_identical(fileid1, fileid2);
REVERT;
return status ? YDB_OK : -1;
}
Loading

0 comments on commit 6cb15fa

Please sign in to comment.