// ---------------------------------------------------------------------------- // // main - simpy attach to the seaquest env and initialize // // ---------------------------------------------------------------------------- int main(int pv_argc, char *pa_argv[]) { CALL_COMP_DOVERS(sp_wrapper, pv_argc, pa_argv); int error = msg_init_attach (&pv_argc, &pa_argv, false, NULL); if (!error) { error = msg_mon_process_startup2(false, false); // client sp_initialize(pv_argc, pa_argv ); } msg_mon_process_shutdown(); }
// // server main // int main(int pv_argc, char *pa_argv[]) { bool lv_done; int lv_ferr; int lv_lerr; BMS_SRE lv_sre; CALL_COMP_DOVERS(idtmsrv, pv_argc, pa_argv); do_init(pv_argc, pa_argv); lv_ferr = msg_mon_process_startup(true); // system messages assert(lv_ferr == XZFIL_ERR_OK); msg_mon_enable_mon_messages(true); lv_ferr = msg_mon_get_my_process_name(ga_name, sizeof(ga_name)); assert(lv_ferr == XZFIL_ERR_OK); do_shm(); lv_ferr = timer_start_cb(gv_time_refresh_delay, 0, 0, &gv_tleid, &timer_callback); assert(lv_ferr == XZFIL_ERR_OK); lv_done = false; while (!lv_done) { do { lv_lerr = XWAIT(LREQ, -1); lv_lerr = BMSG_LISTEN_((short *) &lv_sre, // sre 0, // listenopts 0); // listenertag } while (lv_lerr == XSRETYPE_NOWORK); if (lv_sre.sre_flags & XSRE_MON) { do_mon_msg(&lv_sre, &lv_done); } else { do_req(&lv_sre); } } if (gv_verbose) printf("server %s shutting down\n", ga_name); lv_ferr = msg_mon_process_shutdown(); assert(lv_ferr == XZFIL_ERR_OK); return 0; }
int main(int argc, char *argv[], char *envp[]) { INITSRVRTRC CEE_status sts = CEE_SUCCESS; SRVR_INIT_PARAM_Def initParam; DWORD processId; char tmpString[128]; char tmpString2[32]; char tmpString3[512]; CEECFG_Transport transport; CEECFG_TcpPortNumber portNumber; BOOL retcode; IDL_OBJECT_def srvrObjRef; CEECFG_TcpProcessName TcpProcessName; int TransportTrace = 0; CALL_COMP_DOVERS(ndcs,argc,argv); try { regZnodeName[0] = '\x0'; zkHost[0] = '\x0'; zkRootNode[0] = '\x0'; // Initialize seabed int sbResult; char buffer[FILENAME_MAX] = {0}; bzero(buffer, sizeof(buffer)); sbResult = file_init_attach(&argc, &argv, true, buffer); if(sbResult != XZFIL_ERR_OK){ exit(3); } sbResult = file_mon_process_startup(true); if(sbResult != XZFIL_ERR_OK){ exit(3); } msg_mon_enable_mon_messages(true); } catch(SB_Fatal_Excep sbfe) { exit(3); } sigset_t newset, oldset; sigemptyset(&newset); sigaddset(&newset,SIGQUIT); sigaddset(&newset,SIGTERM); sigprocmask(SIG_BLOCK,&newset,&oldset); processId = GetCurrentProcessId(); retcode = getInitParamSrvr(argc, argv, initParam, tmpString, tmpString3); retcode = TRUE; mxosrvr_init_seabed_trace_dll(); atexit(mxosrvr_atexit_function); // +++ Todo: Duplicating calls here. Should try to persist in srvrGlobal MS_Mon_Process_Info_Type proc_info; msg_mon_get_process_info_detail(NULL, &proc_info); myNid = proc_info.nid; myPid = proc_info.pid; myProcName = proc_info.process_name; char logNameSuffix[32]; sprintf( logNameSuffix, "_%d_%d.log", myNid, myPid ); CommonLogger::instance().initLog4cxx("log4cxx.trafodion.masterexe.config", logNameSuffix); if(retcode == FALSE ) { //LCOV_EXCL_START SendEventMsg( MSG_SET_SRVR_CONTEXT_FAILED, EVENTLOG_ERROR_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 2, tmpString, tmpString3); exit(0); //LCOV_EXCL_STOP } GTransport.initialize(); if(GTransport.error != 0 ) { //LCOV_EXCL_START SendEventMsg( MSG_SET_SRVR_CONTEXT_FAILED, EVENTLOG_ERROR_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, GTransport.error_message); exit(0); //LCOV_EXCL_STOP } chdir(GTransport.myPathname); initParam.srvrType = CORE_SRVR; //LCOV_EXCL_START if (initParam.debugFlag & SRVR_DEBUG_BREAK) { volatile int done = 0; while (!done) { sleep(10); } } //LCOV_EXCL_STOP char zkErrStr[2048]; stringstream zk_ip_port; // zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG); if( zkHost[0] == '\x0' && regZnodeName[0] == '\x0' ) { sprintf(zkErrStr, "***** Cannot get Zookeeper properties or registered znode info from startup params"); SendEventMsg( MSG_SET_SRVR_CONTEXT_FAILED, EVENTLOG_ERROR_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); // exit(1); } else { zk_ip_port << zkHost; sprintf(zkErrStr, "zk_ip_port is: %s", zk_ip_port.str().c_str()); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); } if (initParam.debugFlag & SRVR_DEBUG_BREAK) zkSessionTimeout = 600; zoo_deterministic_conn_order(1); // enable deterministic order zh = zookeeper_init(zk_ip_port.str().c_str(), watcher, zkSessionTimeout * 1000, &myid, 0, 0); if (zh == 0){ sprintf(zkErrStr, "***** zookeeper_init() failed for host:port %s",zk_ip_port.str().c_str()); SendEventMsg( MSG_SET_SRVR_CONTEXT_FAILED, EVENTLOG_ERROR_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); // exit(1); } bool found = false; int rc; stringstream ss; ss.str(""); ss << zkRootNode << "/dcs/master"; string dcsMaster(ss.str()); Stat stat; int startPortNum = 0, portRangeNum; char masterHostName[MAX_HOST_NAME_LEN]; char startPort[12], portRange[12], masterTS[24]; struct String_vector children; children.count = 0; children.data = NULL; // Get the instance ID from registered node char *tkn; char tmpStr[256]; strcpy( tmpStr, regZnodeName ); tkn = strtok(tmpStr, ":" ); if(tkn!=NULL) strcpy(hostname,tkn); tkn = strtok(NULL, ":" ); if( tkn != NULL ) strcpy( instanceId, tkn ); tkn = strtok(NULL, ":" ); if( tkn != NULL ) strcpy( childId, tkn ); else ; // +++ Todo handle error while(!found) { rc = zoo_exists(zh, dcsMaster.c_str(), 0, &stat); if( rc == ZNONODE ) continue; else if( rc == ZOK ) { rc = zoo_get_children(zh, dcsMaster.c_str(), 0, &children); if( children.count > 0 ) { char zknodeName[2048]; strcpy(zknodeName, children.data[0]); tkn = strtok(zknodeName, ":" ); if( tkn != NULL ) strcpy( masterHostName, tkn ); tkn = strtok(NULL, ":" ); if( tkn != NULL ) { strcpy( startPort, tkn ); startPortNum = atoi(tkn); } tkn = strtok(NULL, ":" ); if( tkn != NULL ) { strcpy( portRange, tkn ); portRangeNum = atoi(tkn); } tkn = strtok(NULL, ":" ); if( tkn != NULL ) strcpy( masterTS, tkn ); free_String_vector(&children); found = true; } else continue; } else // error { sprintf(zkErrStr, "***** zoo_exists() for %s failed with error %d",dcsMaster.c_str(), rc); SendEventMsg( MSG_SET_SRVR_CONTEXT_FAILED, EVENTLOG_ERROR_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); break; } } // Initialize initparam to defaults initParam.transport = CEE_TRANSPORT_TCP; // -T 3 initParam.majorVersion = 3; // -V 3 // Will need to remove $ZTC0 and NonStopODBC from below sprintf( initParam.asSrvrObjRef, "TCP:$ZTC0/%s:NonStopODBC", startPort); // -A TCP:$ZTC0/52500:NonStopODBC // Will need to remove this after we get rid off all existing AS related processing sprintf( initParam.ASProcessName, "$MXOAS" ); // -AS $MXOAS // Will need to remove this after we get rid off all existing WMS related processing sprintf( initParam.QSProcessName, "$ZWMGR" ); // -QS $ZWMGR // moved this here from begining of the function BUILD_OBJECTREF(initParam.asSrvrObjRef, srvrObjRef, "NonStopODBC", initParam.portNumber); ss.str(""); ss << zkRootNode << "/dcs/servers/registered"; string dcsRegistered(ss.str()); char realpath[1024]; bool zk_error = false; if( found ) { sprintf(zkErrStr, "Found master node in Zookeeper"); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); found = false; while(!found) { rc = zoo_exists(zh, dcsRegistered.c_str(), 0, &stat); if( rc == ZNONODE ) continue; else if( rc == ZOK ) { int i; //This section is the original port finding mechanism. //All servers (the herd) start looking for any available port //between starting port number+2 through port range max. //This is mainly for backward compatability for DcsServers //that don't pass PORTMAPTOSECS and PORTBINDTOSECS param if(portMapToSecs == -1 && portBindToSecs == -1) { for(i = startPortNum+2; i < startPortNum+portRangeNum; i++) { if (GTransport.m_listener->verifyPortAvailable("SRVR", i)) break; } if( i == startPortNum+portRangeNum ) { zk_error = true; sprintf(zkErrStr, "***** No ports free"); break; } } else { //This section is for new port map params, PORTMAPTOSECS and PORTBINDTOSECS, //passed in by DcsServer. DcsMaster writes the port map to data portion of //<username>/dcs/servers/registered znode. Wait PORTMAPTOSECS for port map //to appear in registered znode. When it appears read it and scan looking for //match of instance and child Id. long retryTimeout = 500;//.5 second long long timeout = JULIANTIMESTAMP(); bool isPortsMapped = false; char *zkData = new char[1000000]; int zkDataLen = 1000000; while(! isPortsMapped) { memset(zkData,0,1000000); rc = zoo_get(zh, dcsRegistered.c_str(), false, zkData, &zkDataLen, &stat); if( rc == ZOK && zkDataLen > 0 ) { sprintf(zkErrStr, "DCS port map = %s", zkData); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); int myInstanceId = atoi(instanceId); int myChildId = atoi(childId); sprintf(zkErrStr, "Searching for my id (%d:%d) in port map",myInstanceId,myChildId); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); char portMapInstanceId[8]; char portMapChildId[8]; char portMapPortNum[8]; char* saveptr; char* token = strtok_r (zkData,":",&saveptr); while (token != NULL) { if( token != NULL )//instance Id strcpy( portMapInstanceId, token ); token = strtok_r(NULL, ":",&saveptr); if( token != NULL )//child id strcpy( portMapChildId, token ); token = strtok_r(NULL, ":",&saveptr); if( token != NULL )//port number strcpy( portMapPortNum, token ); int currPortMapInstanceId = atoi(portMapInstanceId); int currPortMapChildId = atoi(portMapChildId); int currPortMapPortNum = atoi(portMapPortNum); if(myInstanceId == currPortMapInstanceId && myChildId == currPortMapChildId) { i = currPortMapPortNum; sprintf(zkErrStr, "Found my port number = %d in port map", i); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); break; } else { token = strtok_r (NULL, ":",&saveptr); } } timeout = JULIANTIMESTAMP(); bool isAvailable = false; while ( isAvailable == false ) { if (GTransport.m_listener->verifyPortAvailable("SRVR", i)) { isAvailable = true; } else { if((JULIANTIMESTAMP() - timeout) > (portBindToSecs * 1000000)) { sprintf(zkErrStr, "Port bind timeout...exiting"); zk_error = true; break; } else { sprintf(zkErrStr, "Port = %d is already in use...retrying", i); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); DELAY(retryTimeout); } } } isPortsMapped = true; } else { if((JULIANTIMESTAMP() - timeout) > (portMapToSecs * 1000000)) { sprintf(zkErrStr, "Port map read timeout...exiting"); zk_error = true; break; } else { sprintf(zkErrStr, "Waiting for port map"); SendEventMsg(MSG_SERVER_TRACE_INFO, EVENTLOG_INFORMATION_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); DELAY(retryTimeout); rc = zoo_exists(zh, dcsRegistered.c_str(), 0, &stat); } } } delete[] zkData; } initParam.portNumber = i; stringstream newpath; newpath.str(""); newpath << dcsRegistered.c_str() << "/" << regZnodeName; // dcsRegisteredNode.str(""); // dcsRegisteredNode << dcsRegistered.c_str() << "/" << regZnodeName; dcsRegisteredNode = newpath.str(); ss.str(""); ss << myPid; string pid(ss.str()); ss.str(""); ss << "STARTING" << ":" << JULIANTIMESTAMP() << ":" << ":" // Dialogue ID << myNid << ":" << myPid << ":" << myProcName.c_str() << ":" // Server IP address << ":" // Server Port << ":" // Client computer name << ":" // Client address << ":" // Client port << ":" // Client Appl name << ":"; regSrvrData = ss.str(); rc = zoo_create(zh, dcsRegisteredNode.c_str(), regSrvrData.c_str(), regSrvrData.length(), &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, realpath, sizeof(realpath)-1); if( rc != ZOK ) { zk_error = true; sprintf(zkErrStr, "***** zoo_create() failed with error %d", rc); break; } found = true; } else // error { zk_error = true; sprintf(zkErrStr, "***** zoo_exists() for %s failed with error %d",dcsRegistered.c_str(), rc); break; } } } if( zk_error ) { SendEventMsg( MSG_SET_SRVR_CONTEXT_FAILED, EVENTLOG_ERROR_TYPE, processId, ODBCMX_SERVER, srvrObjRef, 1, zkErrStr); exit(1); } //LCOV_EXCL_START // when a server dies, the MXOAS sends message to CFG. CFG creates the MXOSRVR process // and passess only one command line atribute: -SQL CLEANUP OBSOLETE VOLATILE TABLES // It is for cleanup resources (volatile tables). // Newly created MXOSRVR process executes CLEANUP OBSOLETE VOLATILE TABLES and exits. // (This process is not managed by AS!. It is only a helper. if (initParam.sql != NULL) { if (strncmp(initParam.sql, "SELECT COUNT", 12) == 0) { //You can specify a completion code with any positive value in a PROCESS_STOP_. //Negative completion codes are reserved for HP use. //Therefore negative codes will return as 1000 + abs(completionCode) short completionCode = -1; completionCode = SQL_EXECDIRECT_FETCH(&initParam); if (completionCode < 0) completionCode = 1000 + abs(completionCode); #ifdef NSK_PLATFORM PROCESS_STOP_(,,,completionCode,,,,); #else /* * TODO: * need to revisit this logic to return a value via exit code * */ #endif } else {