Skip to content

Commit

Permalink
[CBRD-24511] Change java_stored_procedure_uds param's behavior (#3872) (
Browse files Browse the repository at this point in the history
  • Loading branch information
hgryoo authored Oct 18, 2022
1 parent 3367303 commit 464ebac
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/communication/network_interface_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8745,7 +8745,7 @@ jsp_get_server_port (void)
#else /* CS_MODE */
int port;
THREAD_ENTRY *thread_p = enter_server ();
port = jsp_server_port ();
port = jsp_server_port_from_info ();
exit_server (*thread_p);
return port;
#endif /* !CS_MODE */
Expand Down
2 changes: 1 addition & 1 deletion src/communication/network_interface_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7964,7 +7964,7 @@ sjsp_get_server_port (THREAD_ENTRY * thread_p, unsigned int rid, char *request,
OR_ALIGNED_BUF (OR_INT_SIZE) a_reply;
char *reply = OR_ALIGNED_BUF_START (a_reply);

(void) or_pack_int (reply, jsp_server_port ());
(void) or_pack_int (reply, jsp_server_port_from_info ());
css_send_data_to_client (thread_p->conn_entry, rid, reply, OR_ALIGNED_BUF_SIZE (a_reply));
}

Expand Down
45 changes: 25 additions & 20 deletions src/executables/javasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ main (int argc, char *argv[])
}

/* try to create info dir and get absolute path for info file; $CUBRID/var/javasp_<db_name>.info */
JAVASP_SERVER_INFO jsp_info = {-1, -1};
JAVASP_SERVER_INFO jsp_info = JAVASP_SERVER_INFO_INITIALIZER;
status = javasp_get_server_info (db_name, jsp_info);
if (status != NO_ERROR && command.compare ("start") != 0)
{
Expand Down Expand Up @@ -178,7 +178,7 @@ main (int argc, char *argv[])
}

// check process is running
if (jsp_info.pid == -1 || javasp_is_terminated_process (jsp_info.pid) == true)
if (jsp_info.pid == JAVASP_PID_DISABLED || javasp_is_terminated_process (jsp_info.pid) == true)
{
// NO_CONNECTION
javasp_reset_info (db_name.c_str ());
Expand Down Expand Up @@ -284,27 +284,24 @@ static int
javasp_start_server (const JAVASP_SERVER_INFO jsp_info, const std::string &db_name, const std::string &path)
{
int status = NO_ERROR;
int check_port = -1;
int prm_port = prm_get_integer_value (PRM_ID_JAVA_STORED_PROCEDURE_PORT);

/* trying to start javasp server for new port */
if (prm_port != jsp_info.port)
{
/* check javasp server is running with previously configured port number */
check_port = jsp_info.port;
}
else
{
/* check javasp server is running for the port number written in configuration file */
check_port = prm_port;
}

if (javasp_is_running (check_port, db_name))
if (jsp_info.pid != JAVASP_PID_DISABLED && javasp_is_running (jsp_info.port, db_name))
{
status = ER_GENERIC_ERROR;
}
else
{
int prm_port = -1;
const bool is_uds_mode = prm_get_bool_value (PRM_ID_JAVA_STORED_PROCEDURE_UDS);
if (is_uds_mode)
{
prm_port = JAVASP_PORT_UDS_MODE;
}
else
{
prm_port = prm_get_integer_value (PRM_ID_JAVA_STORED_PROCEDURE_PORT);
}

#if !defined(WINDOWS)
/* create a new session */
setsid ();
Expand All @@ -314,7 +311,8 @@ javasp_start_server (const JAVASP_SERVER_INFO jsp_info, const std::string &db_na

if (status == NO_ERROR)
{
JAVASP_SERVER_INFO jsp_new_info { getpid(), jsp_server_port () };
int port_number = prm_get_bool_value (PRM_ID_JAVA_STORED_PROCEDURE_UDS) ? JAVASP_PORT_UDS_MODE : jsp_server_port ();
JAVASP_SERVER_INFO jsp_new_info { getpid(), port_number };

javasp_unlink_info (db_name.c_str ());
if ((javasp_open_info_dir () && javasp_write_info (db_name.c_str (), jsp_new_info)))
Expand Down Expand Up @@ -523,8 +521,15 @@ javasp_ping_server (const int server_port, const char *db_name, char *buf)
static void
javasp_dump_status (FILE *fp, JAVASP_STATUS_INFO status_info)
{
fprintf (fp, "Java Stored Procedure Server (%s, pid %d, port %d)\n", status_info.db_name, status_info.pid,
status_info.port);
if (status_info.port == JAVASP_PORT_UDS_MODE)
{
fprintf (fp, "Java Stored Procedure Server (%s, pid %d, UDS)\n", status_info.db_name, status_info.pid);
}
else
{
fprintf (fp, "Java Stored Procedure Server (%s, pid %d, port %d)\n", status_info.db_name, status_info.pid,
status_info.port);
}
auto vm_args_len = status_info.vm_args.size();
if (vm_args_len > 0)
{
Expand Down
67 changes: 32 additions & 35 deletions src/jsp/com/cubrid/jsp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public class Server {

private static List<String> jvmArguments = null;

private static final int udsPortNumber = -1;
private int portNumber = 0;
private Thread tcpSocketListener = null;
private Thread udsSocketListener = null;
private Thread socketListener = null;
private AtomicBoolean shutdown;

private static Server serverInstance = null;
Expand All @@ -71,57 +71,54 @@ private Server(
udsPath = uPath;
shutdown = new AtomicBoolean(false);

if (OSValidator.IS_UNIX) {
final File socketFile = new File(udsPath);

if (socketFile.exists()) {
socketFile.delete();
}
ServerSocket serverSocket = null;
int port_number = Integer.parseInt(port);
try {
if (OSValidator.IS_UNIX && port_number == -1) {
final File socketFile = new File(udsPath);
if (socketFile.exists()) {
socketFile.delete();
}

try {
AFUNIXSocketAddress sockAddr = AFUNIXSocketAddress.of(socketFile);
AFUNIXServerSocket udsServerSocket = AFUNIXServerSocket.bindOn(sockAddr);
udsSocketListener = new ListenerThread(udsServerSocket);
} catch (Exception e) {
log(e);
e.printStackTrace();
System.exit(1);
serverSocket = AFUNIXServerSocket.bindOn(sockAddr);
portNumber = udsPortNumber;
} else {
serverSocket = new ServerSocket(port_number);
portNumber = serverSocket.getLocalPort();
}
}

int port_number = Integer.parseInt(port);
try {
ServerSocket tcpServerSocket = new ServerSocket(port_number);
tcpSocketListener = new ListenerThread(tcpServerSocket);
portNumber = tcpServerSocket.getLocalPort();
} catch (Exception e) {
log(e);
e.printStackTrace();
System.exit(1);
}

Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
System.setSecurityManager(new SpSecurityManager());
System.setProperty("cubrid.server.version", version);
if (serverSocket != null) {
socketListener = new ListenerThread(serverSocket);

getJVMArguments(); /* store jvm options */
Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
System.setSecurityManager(new SpSecurityManager());
System.setProperty("cubrid.server.version", version);

getJVMArguments(); /* store jvm options */
} else {
/* error, serverSocket is not properly initialized */
System.exit(1);
}
}

private void startSocketListener() {
if (udsSocketListener != null) {
udsSocketListener.setDaemon(true);
udsSocketListener.start();
if (socketListener != null) {
socketListener.setDaemon(true);
socketListener.start();
}
tcpSocketListener.setDaemon(true);
tcpSocketListener.start();
}

private void stopSocketListener() {
if (udsSocketListener != null) {
udsSocketListener.interrupt();
udsSocketListener = null;
if (socketListener != null) {
socketListener.interrupt();
socketListener = null;
}
tcpSocketListener.interrupt();
}

public int getPortNumber() {
Expand Down
10 changes: 5 additions & 5 deletions src/jsp/jsp_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Note:
*/

#include "jsp_comm.h"

#include "config.h"

#include <assert.h>
Expand All @@ -43,8 +45,7 @@
#include <windows.h>
#endif /* not WINDOWS */

#include "jsp_comm.h"

#include "jsp_file.h"
#include "connection_support.h"
#include "porting.h"
#include "error_manager.h"
Expand Down Expand Up @@ -78,12 +79,11 @@ jsp_connect_server (const char *db_name, int server_port)
#if defined (WINDOWS)
socket = jsp_connect_server_tcp (server_port);
#else
if (prm_get_bool_value (PRM_ID_JAVA_STORED_PROCEDURE_UDS) == true)
if (server_port == JAVASP_PORT_UDS_MODE)
{
socket = jsp_connect_server_uds (db_name);
}

if (socket == INVALID_SOCKET)
else
{
socket = jsp_connect_server_tcp (server_port);
}
Expand Down
4 changes: 1 addition & 3 deletions src/jsp/jsp_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ javasp_write_info (const char *db_name, JAVASP_SERVER_INFO info)
bool
javasp_reset_info (const char *db_name)
{
// *INDENT-OFF*
JAVASP_SERVER_INFO reset_info {-1, -1};
// *INDENT-ON*
JAVASP_SERVER_INFO reset_info = JAVASP_SERVER_INFO_INITIALIZER;
return javasp_write_info (db_name, reset_info);
}
7 changes: 7 additions & 0 deletions src/jsp/jsp_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ struct javasp_server_info
int port;
};

#define JAVASP_PID_DISABLED -1
#define JAVASP_PORT_DISABLED -2
#define JAVASP_PORT_UDS_MODE -1

#define JAVASP_SERVER_INFO_INITIALIZER \
{JAVASP_PID_DISABLED, JAVASP_PORT_DISABLED}

#ifdef __cplusplus
extern "C"
{
Expand Down
28 changes: 23 additions & 5 deletions src/jsp/jsp_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ jsp_start_server (const char *db_name, const char *path, int port)
char *loc_p, *locale;
char *jvm_opt_sysprm = NULL;
int debug_port = -1;
const bool is_uds_mode = (port == JAVASP_PORT_UDS_MODE);
{
if (jvm != NULL)
{
Expand All @@ -533,7 +534,7 @@ jsp_start_server (const char *db_name, const char *path, int port)

envroot = envvar_root ();

if (prm_get_bool_value (PRM_ID_JAVA_STORED_PROCEDURE_UDS) == true)
if (is_uds_mode)
{
uds_path = jsp_get_socket_file_path (db_name);
}
Expand Down Expand Up @@ -712,7 +713,7 @@ jsp_start_server (const char *db_name, const char *path, int port)
JVM_SetObjectArrayElement (env_p, args, 5, jstr_port);

sp_port = JVM_CallStaticIntMethod (env_p, cls, mid, args);
if (JVM_ExceptionOccurred (env_p) || sp_port == -1)
if (JVM_ExceptionOccurred (env_p))
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM, 1,
"Error occured while starting Java SP Server by CallStaticIntMethod()");
Expand All @@ -728,14 +729,31 @@ jsp_start_server (const char *db_name, const char *path, int port)

/*
* jsp_server_port
* return: if disable jsp function and return -1
* enable jsp function and return jsp server port
* return: if jsp is disabled return -2 (JAVASP_PORT_DISABLED)
* else if jsp is UDS mode return -1
* else return a port (TCP mode)
*
* Note:
*/

int
jsp_server_port (void)
{
return sp_port;
}

/*
* jsp_server_port_from_info
* return: if jsp is disabled return -2 (JAVASP_PORT_DISABLED)
* else if jsp is UDS mode return -1
* else return a port (TCP mode)
*
*
* Note:
*/

int
jsp_server_port_from_info (void)
{
#if defined (SA_MODE)
return sp_port;
Expand All @@ -745,7 +763,7 @@ jsp_server_port (void)
JAVASP_SERVER_INFO jsp_info {-1, -1};
// *INDENT-ON*
javasp_read_info (boot_db_name (), jsp_info);
return jsp_info.port;
return sp_port = jsp_info.port;
#endif
}

Expand Down
9 changes: 5 additions & 4 deletions src/jsp/jsp_sr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ extern "C"
{
#endif

extern int jsp_start_server (const char *server_name, const char *path, int port_number);
extern int jsp_server_port (void);
extern int jsp_jvm_is_loaded (void);
extern int jsp_start_server (const char *server_name, const char *path, int port_number);
extern int jsp_server_port (void);
extern int jsp_server_port_from_info (void);
extern int jsp_jvm_is_loaded (void);

#if defined(__cplusplus)
}
#endif

#endif /* _JSP_SR_H_ */
#endif /* _JSP_SR_H_ */
4 changes: 2 additions & 2 deletions src/method/method_connection_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ namespace cubmethod
if (conn->is_valid() == false)
{
jsp_disconnect_server (conn->m_socket); // disconnect connecting with ExecuteThread in invalid state
conn->m_socket = jsp_connect_server (boot_db_name (), jsp_server_port ());
conn->m_socket = jsp_connect_server (boot_db_name (), jsp_server_port_from_info ());
}

return conn;
}

// new connection
SOCKET socket = jsp_connect_server (boot_db_name (), jsp_server_port ());
SOCKET socket = jsp_connect_server (boot_db_name (), jsp_server_port_from_info ());
return new connection (this, socket);
}

Expand Down

0 comments on commit 464ebac

Please sign in to comment.