⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachrpl.c

📁 extremeDB s sample code,useful for you
💻 C
字号:
/***************************************************************** *                                                               * *  attachrpl.c                                                  * *                                                               * * This file is a part of the eXtremeDB-HA Application Framework * *   It contains the realization of a thread that attaches       *   * replicas to master.                                           * *                                                              * ***************************************************************** *  Copyright (c) 2001-2006 McObject LLC                         *  *  All Rights Reserved                                          * *****************************************************************//* * ++ *  * PROJECT:   eXtremeDB-HA Application Framework * * SUBSYSTEM: HA support * * MODULE:    ATTACHRPL.C * * ABSTRACT:  Replica creation thread * * * VERSION:   1.0 * * HISTORY: *            1.0- 1 AD     01-Mar-2003 Created it was *                 2 AG     19-Mar-2003 Ported to Linux *                 3 SS     19-Jul-2003 Reconstructed * * -- */#define INCLUDE_SOCKETS#include  "app.h"extern  timer_unit    init_time;extern  int           master_number;extern  int           main_master;extern  long          stop_flag;extern  void ExitHandler(int errcode);/* * This structure describes timeouts that are necessary to set the finite times to functions * of attaching and detaching replicas and of transaction commits */static mco_connection_param_t master_conpar ={  TM_MASTER_COMMIT,     TM_ATTACH_REPLICA,  TM_DETACH_REPLICA,  TM_WAIT_FOR_DATA,  TM_SYNCH,  0               //replica_notifying#ifdef MCO_CFG_HA_2PHASE_COMMIT /* special commit interface */  ,0              // set Replica Fail Callback */#endif //MCO_CFG_HA_2PHASE_COMMIT};/*  * The thread opens a channel for listening the connections requests from replicas. * It is always waiting for the requests. For this purpose it calls the  function * *      mco_nw_attach_replica(). * *    This function is dependent on communication protocol therefore it is implemented in  * protocol dependent modules (appnwfio.c appnwpip.c appnwTCP.c appnwUDP.c). * *   Once the thread receives the request it creates the communication channel and calls * function mco_HA_attach_replica() in order to create copy of master's database on * replica side (also see mco_nw_attach_replica() and mco_nw_attach_master()). */THREAD_PROC_DEFINE(ListenToReplicas, p){  ha_h	              ha = (ha_h)p;     // HA instance handle  MCO_RET             ret;              // result code  int                 count;            // working cell  mco_db_h            dbh;  THREAD_PROC_MODE();  Printf( "Master: Thread ListenToReplicas() started\n");  ;  if((ret = mco_db_connect(ha->dbName, &dbh)) != MCO_S_OK) {    Printf( "Master: Can't connect to database error = %d\n", ret);    EXIT(-1);  }  strcpy(ha->endpoint, nw_MasterName);  sprintf(&ha->endpoint[strlen(ha->endpoint)-2],"%02d", ha->id*10);/* * The infinite cycle for listening connection requests from replicas and creating copies of  * the master's database */  for(;;)  {/* * mco_nw_attach_replica() - * Creates a communication channel and creates copy of master's database on replication side */    ret = mco_nw_attach_replica(                      dbh,                      ha->endpoint,                      &master_conpar,                      0,                      TM_ACCEPT_TIMEOUT,                      (PVOID)ha                      );    if ( ret )    {      if(ret != MCO_E_NW_TIMEOUT) {        Printf( "\nMaster: failed with error %d\n", ret );        switch(ret) {            case MCO_E_NW_KILLED_BY_REPLICA:              Printf("\n\n*** master is killed by replica ***\n");              stop_flag++;              return;            case MCO_E_NW_FATAL:            case MCO_E_NW_NOTSUPP:            case MCO_E_NW_BUSY:            case MCO_E_NW_NOMEM:            exit(-1);            default:    break;        }      }    }    else {      nw_channel_h ch;      count = mco_HA_get_number_of_replicas(ha->db)-1;  // show current number of replicas      ch = (nw_channel_h)mco_HA_get_io_channel(ha->db, (int2)(count));#if defined( CFG_TCP_SOCKET_CHANNEL ) || defined( CFG_UDP_SOCKET_CHANNEL )      printf("IP = %s\n", inet_ntoa(ch->sin.sin_addr));#endif //defined( CFG_TCP_SOCKET_CHANNEL ) || defined( CFG_UDP_SOCKET_CHANNEL )      Printf("*** attached (%d), time of initialization phase = %ld ms ***\n", count,init_time);    }  }}THREAD_PROC_FINISH_DEFINE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -