Ejemplo n.º 1
0
int IndexDbLevelDb::addFilesToFileList(leveldb::DB* db)
{
    char buf[1024];
    int startId = 0;
    string valStr;
    string keyFileCount = "file_count";
    int rv = dbRead(valStr, db, keyFileCount);
    if(rv < 0) {
        // key not found 
        dbWrite(db, keyFileCount, "1");
        startId = 0;
    }
    else if(rv == 0) {
        char* errp = NULL;
        startId = strtol(valStr.c_str(), &errp, 16);
        assert(*errp == '\0');
    }
    else {
        printf("ERROR: db info\n");
    }

    int id = startId;
    for(const auto& itr : m_fileContextMap) {
        string fn = itr.first;
        string key = TABLE_NAME_FILE_LIST "|" + fn;
        int rv = dbRead(valStr, db, key);
        string fid;
        if(rv < 0) {
            snprintf(buf, sizeof(buf), "%x", id);
            fid = string(buf);
            dbWrite(db, key, m_compileUnitId + "," + fid);
            id++;
            dbWrite(db, TABLE_NAME_GLOBAL_FILE_ID_TO_CU_ID "|" + fid, m_compileUnitId);
        }
        else {
            // get fid
            size_t pos = valStr.find(",");
            assert(pos != string::npos);
            fid = valStr.substr(pos+1, valStr.size()-1);
        }
        m_fileContextMap[fn].m_dbId = fid;

        if(fn == m_compileUnit) {
            m_cuDbId = fid;
        }
    }
    snprintf(buf, sizeof(buf), "%x", id);
    dbWrite(db, keyFileCount, buf);
    return 0;
}
Ejemplo n.º 2
0
bool CTxWPool::Init(){
    tgroup = NULL;
    if(!dbRead()){
        dbWrite();
    }
    return true;
}
Ejemplo n.º 3
0
int IndexDbLevelDb::writeUsrDb(const map<string, SiMap>& usrFidMap, leveldb::DB* dbUsrDb, leveldb::WriteBatch& wb_usrdb, const string& dbName)
{
    // lookup map
    for(const auto& itr : usrFidMap) {
        const string& usr = itr.first;
        if(usr != "") {
            SiMap file_list_map = itr.second;
#ifdef USE_USR2FILE_TABLE2
            for(const auto& itr_str : file_list_map) {
                wb_usrdb.Put(dbName + "|" + usr + "|" + itr_str.first, "1");
            }
#else
            // check if already registered
            string value;
            int rv = dbRead(value, dbUsrDb, dbName + "|" + usr);
            if(rv == 0) {
                const string delim = ",";
                list<string> old_list;
                boost::split(old_list, value, boost::is_any_of(delim));
                for(const auto& itr_old : old_list) {
                    file_list_map[itr_old] = 0;
                }
            }
            string file_list_string = "";
            for(const auto& itr_str : file_list_map) {
                file_list_string.append(itr_str.first+",");
            }
            file_list_string = file_list_string.substr(0, file_list_string.size()-1);
            wb_usrdb.Put(dbName + "|" + usr, file_list_string);
#endif
        }
    }
    return 0;
}
Ejemplo n.º 4
0
    TEST(DConcurrency, DBReadTakesS) {
        LockerImpl ls;

        Lock::DBRead dbRead(&ls, "db");

        const ResourceId resIdDb(RESOURCE_DATABASE, string("db"));
        ASSERT(ls.getLockMode(resIdDb) == MODE_S);
    }
Ejemplo n.º 5
0
int main( int argc , char **argv )
{
		parseOpts( argc, argv );
		
    // Nuke +1 1012: Loop counter
    int counter1 = 0;
    
    int counter2 = 0;
    
    int counter3 = 0;
    
    int counter4 = 0;

    signal(SIGUSR1, sigusr1);

    log_rotate_interval = 3600 * 24 * 7;

    Lock_Init();	// Arminius 7.17 memory lock

		UNlockM_Init();
    
    if(readConfig( "acserv.cf" )<0){
        log( "ÎÞ·¨ÔÚµ±Ç°Ä¿Â¼Àï¶ÁÈ¡ acserv.cf .\n" );
        exit(1);
    }

#ifdef _SASQL
    sasql_init();
#endif	
    log( "¶ÁÈ¡Êý¾ÝĿ¼\n" );
    dbRead( dbdir );
#ifdef	_FAMILY
    log("¶ÁÈ¡ ¼Ò×åׯ԰\n");
    readFMSMemo(fmsmemodir);
    log("¶ÁÈ¡ ¼Ò×åÁôÑÔ\n");
    readFMPoint(fmpointdir);
    log("¶ÁÈ¡ ¼Ò×åĿ¼\n");
    readFamily(familydir);
#endif
    log( "×¼±¸ µµ°¸Ä¿Â¼\n" );
    prepareDirectories( chardir );
    log( "×¼±¸ ÈÕ־Ŀ¼\n" );
    prepareDirectories( logdir );
    log( "×¼±¸ ÓʼþĿ¼\n" );
    prepareDirectories( maildir );

#ifdef _SLEEP_CHAR
    prepareDirectories( sleepchardir );
    log( "×¼±¸ ˯Ãßµµ°¸Ä¿Â¼\n" );
#endif

    /* Ð×ÒýÔÈ»¯Ô¶ª¡õ»ïë  Ðijð¸ê */
    if( readMail(maildir) < 0 ){
        log( "²»Äܳõʼ»¯Óʼþ\n" );
        exit(1);
		}

    /* TCPSTRUCT ëâÙÓå¼À */
    {
        int tcpr;
        if( ( tcpr = tcpstruct_init( NULL , port , 0 ,
						CHARDATASIZE * 16 * MAXCONNECTION , 1 /* DEBUG */ ) ) < 0 ){
            log( "²»ÄÜ¿ªÆôTCP: %d\n", tcpr );
            return 1;
        }
    }
    saacproto_InitServer( netWrite , CHARDATASIZE );

    {
        struct sigaction s,os;
        
        bzero( &s, sizeof(s));
        s.sa_handler = sighandle;
        s.sa_flags = SA_NOMASK;
        sigaction( SIGTERM,  &s, &os );

        bzero( &s, sizeof(s));
        s.sa_handler = sighandle;
        s.sa_flags = SA_NOMASK;
        sigaction( SIGINT,  &s, &os );

        bzero( &s, sizeof( s ));
        s.sa_handler = SIG_IGN;
        s.sa_flags = SA_NOMASK;
        sigaction( SIGPIPE, &s, &os );

    }

#ifdef _AC_SEND_FM_PK		 // WON ADD ׯ԰¶ÔÕ½ÁÐ±í´¢´æÔÚAC
	load_fm_pk_list();
#endif

#ifdef _ACFMPK_LIST
	FMPK_LoadList();
#endif
#ifdef _ALLDOMAN
	LOAD_herolist();  // Syu ADD ÅÅÐаñNPC
#endif

#ifdef _ANGEL_SUMMON
	initMissionTable();
#endif

#ifdef _VIP
		log( "\n·þÎñ¶Ë°æ±¾: <%s »áÔ±°æ>\n" , SERVER_VERSION );
#else
		log( "\n·þÎñ¶Ë°æ±¾: <%s ÆÕͨ°æ>\n" , SERVER_VERSION );
#endif
		log( "\n·þÎñ¶Ë±àÒëÍê³Éʱ¼ä:%s %s by 17CSA¹¤×÷ÊÒ\n" , __DATE__ , __TIME__ );
		
    log( "\n¿ªÊ¼¹¤×÷...\n" );

    signal(SIGUSR1,sigusr1);	// Arminius 7.20 memory lock
	int itime=0;
	while(1){
		itime++;
		if(itime>cpuuse){
			itime=0;
			usleep(1);
		}
    int newti,i;
    static time_t main_loop_time;
		
		sys_time = time(NULL);

		if( main_loop_time != sys_time){
            main_loop_time = time(NULL);
            counter1++;
            counter2++;
            counter3++;
            counter4++;
			//andy add 2002/06/20
			UNlockM_UnlockPlayer();

#ifdef _ANGEL_SUMMON
			checkMissionTimelimit();
#endif
            // Nuke *1 1012
            if( counter1 > Total_Charlist ){
            		counter1=0;
                char *c = ctime( &main_loop_time );
                if( c ){
                    struct timeval st,et;
                    log( "\nTIME:%s\n",c );
                    gettimeofday( &st,NULL);
                    dbFlush(dbdir);
                    gettimeofday( &et,NULL);
                    log( "Flushed db(%fsec)\n", time_diff(et,st) );
                    log( "µµ°¸±íÁÐ×ÜÊý:%d NG:%d\n",
                         total_ok_charlist, total_ng_charlist );
                }
            }
            // Nuke **1 1012
            //if( ( counter % 600 ) == 0 ){
            if( counter2 > Expired_mail ){
            		counter2=0;
                struct timeval st,et;
                gettimeofday( &st,NULL);
                expireMail();
                gettimeofday( &et,NULL);
                log( "¹ýÆÚÓʼþ(%fsec)\n", time_diff(et,st) );
            }
#ifdef	_FAMILY
            //if ((counter % 300) == 0) // 300( -> 60)
      if( counter4 > Write_Family ) // 300( -> 60)
      {
      	  counter4=0;
         	struct timeval st, et;
         	gettimeofday(&st, NULL);
         	writeFamily(familydir);
         	writeFMPoint(fmpointdir);
         	writeFMSMemo(fmsmemodir);
         	gettimeofday(&et, NULL);
         	log("¼Ç¼¼Ò×å(%fsec)\n", time_diff(et, st));
      }
#endif
        }
    newti = tcpstruct_accept1();
    if( newti >= 0 ){
			log( "ͬÒâ: %d\n" , newti );
			gs[newti].use = 1;
    }

        for(i=0;i<MAXCONNECTION;i++){
//        	char buf[CHARDATASIZE * 16;
            char buf[CHARDATASIZE];
            int l;
            l = tcpstruct_readline_chop( i , buf , sizeof( buf )- 1);
						{
                if( !gs[i].use )continue;
                if( l > 0 ){
									char debugfun[256];
                    buf[l]=0;
                    if( saacproto_ServerDispatchMessage( i , buf, debugfun)<0){
                        // Nuke start
                        //tcpstruct_close(i);// avoid the shutdown the gmsv ttom
                        log( "GMSV(%s) ÏûÏ¢:%s\n", gs[i].name, debugfun);
                        FILE *fp;
                        if( (fp=fopen( "badgmsv.txt", "a+")) != NULL ){
													fprintf( fp, "GMSV(%s) ÏûÏ¢:%s\n", gs[i].name, debugfun);
													fclose( fp);
												}
                    }
                } else if( l == TCPSTRUCT_ETOOLONG ){
                    log( "ºÜ³¤:%d ·þÎñÆ÷Ãû::%s\n", i , gs[i].name );
                    FILE *fp;
                        if( (fp=fopen( "badgmsv.txt", "a+")) != NULL ){
													fprintf( fp, "ºÜ³¤:%d ·þÎñÆ÷Ãû::%s\n", i , gs[i].name);
													fclose( fp);
												}
                    logout_game_server( i );
                } else if( l < 0 ){
                    log( "¹Ø±Õ:%d ·þÎñÆ÷Ãû:%s\n", i , gs[i].name );
                    FILE *fp;
                        if( (fp=fopen( "badgmsv.txt", "a+")) != NULL ){
													fprintf( fp, "¹Ø±Õ:%d ·þÎñÆ÷Ãû:%s\n", i , gs[i].name);
													fclose( fp);
												}
                    logout_game_server(i);
                } else if( l == 0 ){
                    ;
                }
            }
        }
        {
            static struct timeval tv_loop_store ;
            struct timeval now;
            double dif;
            gettimeofday( &now , NULL );
            dif = time_diff( now, tv_loop_store );
            if( dif > 0.5 ){ // CoolFish 0.1 -> 0.5 2001/5/19
                //log( "Sl:%f" , dif );
            }
            tv_loop_store = now;
        }

        /* ·¥¡õÊСõ¼°ÕýÄÌةʧËüÐþëƩÍÍÔ£Û
           ÕýÄÌةʧËüÐþØÆÐ×ÈÕ·òºëë·ÖØÆ»¯·¥¡õÊСõëڽØÆ»¯ØÆÒýµ¤£Û
           Æ¥±Ø¡õØ©ÈÓ¡õÌï¡õ±å  ±Î¶Á±å·´É§ôÅÔÊÔ           */
    }
    return 0;       
}
Ejemplo n.º 6
0
int main( int argc , char **argv )
{
		parseOpts( argc, argv );
		
    // Nuke +1 1012: Loop counter
    int counter1 = 0;
    
    int counter2 = 0;
    
    int counter3 = 0;
    
    int counter4 = 0;

    signal(SIGUSR1, sigusr1);

    log_rotate_interval = 3600 * 24 * 7;

    Lock_Init();	// Arminius 7.17 memory lock

		UNlockM_Init();
    
    if(readConfig( "acserv.cf" )<0){
        log( "�޷��ڵ�ǰĿ¼���ȡ acserv.cf .\n" );
        exit(1);
    }

#ifdef _SASQL
    sasql_init();
#endif	
    log( "��ȡ����Ŀ¼\n" );
    dbRead( dbdir );
#ifdef	_FAMILY
    log("��ȡ ����ׯ԰\n");
    readFMSMemo(fmsmemodir);
    log("��ȡ ��������\n");
    readFMPoint(fmpointdir);
    log("��ȡ ����Ŀ¼\n");
    readFamily(familydir);
#endif
    log( "׼�� ����Ŀ¼\n" );
    prepareDirectories( chardir );
    log( "׼�� ��־Ŀ¼\n" );
    prepareDirectories( logdir );
    log( "׼�� �ʼ�Ŀ¼\n" );
    prepareDirectories( maildir );

#ifdef _SLEEP_CHAR
    prepareDirectories( sleepchardir );
    log( "׼�� ˯�ߵ���Ŀ¼\n" );
#endif

    /* �����Ȼ��¶�����ë  �ij�� */
    if( readMail(maildir) < 0 ){
        log( "���ܳ�ʼ���ʼ�\n" );
        exit(1);
		}

    /* TCPSTRUCT ���� */
    {
        int tcpr;
        if( ( tcpr = tcpstruct_init( NULL , port , 0 ,
						CHARDATASIZE * 16 * MAXCONNECTION , 1 /* DEBUG */ ) ) < 0 ){
            log( "���ܿ���TCP: %d\n", tcpr );
            return 1;
        }
    }
    saacproto_InitServer( netWrite , CHARDATASIZE );

    {
        struct sigaction s,os;
        
        bzero( &s, sizeof(s));
        s.sa_handler = sighandle;
        s.sa_flags = SA_NOMASK;
        sigaction( SIGTERM,  &s, &os );

        bzero( &s, sizeof(s));
        s.sa_handler = sighandle;
        s.sa_flags = SA_NOMASK;
        sigaction( SIGINT,  &s, &os );

        bzero( &s, sizeof( s ));
        s.sa_handler = SIG_IGN;
        s.sa_flags = SA_NOMASK;
        sigaction( SIGPIPE, &s, &os );

    }

#ifdef _AC_SEND_FM_PK		 // WON ADD ׯ԰��ս�б�����AC
	load_fm_pk_list();
#endif

#ifdef _ACFMPK_LIST
	FMPK_LoadList();
#endif
#ifdef _ALLDOMAN
	LOAD_herolist();  // Syu ADD ���а�NPC
#endif

#ifdef _VIP
		log( "\n����˰汾: <%s ��Ա��>\n" , SERVER_VERSION );
#else
		log( "\n����˰汾: <%s ��ͨ��>\n" , SERVER_VERSION );
#endif
		log( "\n����˱������ʱ��:%s %s by ��zoro������\n" , __DATE__ , __TIME__ );
		
    log( "\n��ʼ����...\n" );

    signal(SIGUSR1,sigusr1);	// Arminius 7.20 memory lock
	int itime=0;
	while(1){
		itime++;
		if(itime>cpuuse){
			itime=0;
			usleep(1);
		}
    int newti,i;
    static time_t main_loop_time;
		
		sys_time = time(NULL);

		if( main_loop_time != sys_time){
            main_loop_time = time(NULL);
            counter1++;
            counter2++;
            counter3++;
            counter4++;
			//andy add 2002/06/20
			UNlockM_UnlockPlayer();

#ifdef _ANGEL_SUMMON
			checkMissionTimelimit();
#endif
            // Nuke *1 1012
            if( counter1 > Total_Charlist ){
            		counter1=0;
                char *c = ctime( &main_loop_time );
                if( c ){
                    struct timeval st,et;
                    log( "\nTIME:%s\n",c );
                    gettimeofday( &st,NULL);
                    dbFlush(dbdir);
                    gettimeofday( &et,NULL);
                    log( "Flushed db(%fsec)\n", time_diff(et,st) );
                    log( "������������:%d NG:%d\n",
                         total_ok_charlist, total_ng_charlist );
                }
            }
            // Nuke **1 1012
            //if( ( counter % 600 ) == 0 ){
            if( counter2 > Expired_mail ){
            		counter2=0;
                struct timeval st,et;
                gettimeofday( &st,NULL);
                expireMail();
                gettimeofday( &et,NULL);
                log( "�����ʼ�(%fsec)\n", time_diff(et,st) );
            }
#ifdef	_FAMILY
            //if ((counter % 300) == 0) // 300( -> 60)
      if( counter4 > Write_Family ) // 300( -> 60)
      {
      	  counter4=0;
         	struct timeval st, et;
         	gettimeofday(&st, NULL);
         	writeFamily(familydir);
         	writeFMPoint(fmpointdir);
         	writeFMSMemo(fmsmemodir);
         	gettimeofday(&et, NULL);
         	log("��¼����(%fsec)\n", time_diff(et, st));
      }
#endif
        }
    newti = tcpstruct_accept1();
    if( newti >= 0 ){
			log( "ͬ��: %d\n" , newti );
			gs[newti].use = 1;
    }

        for(i=0;i<MAXCONNECTION;i++){
//        	char buf[CHARDATASIZE * 16;
            char buf[CHARDATASIZE];
            int l;
            l = tcpstruct_readline_chop( i , buf , sizeof( buf )- 1);
						{
                if( !gs[i].use )continue;
                if( l > 0 ){
									char debugfun[256];
                    buf[l]=0;
                    if( saacproto_ServerDispatchMessage( i , buf, debugfun)<0){
                        // Nuke start
                        tcpstruct_close(i);// avoid the shutdown the gmsv ttom
                        log( "GMSV(%s) ��Ϣ:%s\n", gs[i].name, debugfun);
                    }
                } else if( l == TCPSTRUCT_ETOOLONG ){
                    log( "�ܳ�:%d ��������::%s\n", i , gs[i].name );
                    logout_game_server( i );
                } else if( l < 0 ){
                    log( "�ر�:%d ��������:%s\n", i , gs[i].name );
                    logout_game_server(i);
                } else if( l == 0 ){
                    ;
                }
            }
        }
        {
            static struct timeval tv_loop_store ;
            struct timeval now;
            double dif;
            gettimeofday( &now , NULL );
            dif = time_diff( now, tv_loop_store );
            if( dif > 0.5 ){ // CoolFish 0.1 -> 0.5 2001/5/19
                //log( "Sl:%f" , dif );
            }
            tv_loop_store = now;
        }

        /* �����С�������ةʧ����ëƩ���£�
           ����ةʧ���������շ��ë���ƻ������С�ëڽ�ƻ���������
           ƥ�ء�ة�ӡ������  �ζ��巴ɧ������           */
    }
    return 0;       
}
Ejemplo n.º 7
0
int IndexDbLevelDb::initialize(const string& out_dir, const string& src_file_name, const string& excludeList, bool isRebuild, const char* curDir, int argc, const char** argv)
{
    leveldb::DB* dbCommon = NULL;
    m_defaultOptions.create_if_missing = true;
    //m_defaultOptions.compression = leveldb::kNoCompression;
    m_defaultOptions.compression = leveldb::kSnappyCompression;
    m_defaultOptions.block_cache = leveldb::NewLRUCache(128 * 1024 * 1024); 
    m_defaultOptions.filter_policy = leveldb::NewBloomFilterPolicy(10);

    const char* cwd = getcwd(m_CharBuff0, sizeof(m_CharBuff0));
    assert(cwd != 0);
    m_currentDirectory = m_CharBuff0;

    // build options
    snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%d", isRebuild);
    m_buildOpt = string(curDir) + "|" + excludeList + "|" + m_CharBuff0 + "|";
    for(int i = 0; i < argc; i++) {
        m_buildOpt += " " + string(argv[i]);
    }

    m_dbDir = out_dir;
    m_compileUnit = src_file_name;

#ifdef TIMER
    m_timers = new boost::timer::cpu_timer[k_timerNum];
    for(int i = 0; i < k_timerNum; i++) {
        m_timers[i].stop();
    }
#endif

    if(makeDirectory(m_dbDir.c_str())) {
        return -1; 
    }

    //
    // update file list
    //
    leveldb::Status status;
    m_commonDbDir = out_dir + "/common";
    if (dbTryOpen(dbCommon, m_commonDbDir) < 0) {
        fprintf(stderr, "Open fail.: %s\n", m_commonDbDir.c_str());
        return -1;
    }
    assert(dbCommon != NULL);
    string value;
    string keyFile = m_compileUnit;
    int rv = 0;
    // check if already registered
    rv = dbRead(value, dbCommon, TABLE_NAME_CU_NAME_TO_ID "|" + m_compileUnit);
    if(rv < 0) {
        // not found
        // add file
        string keyFileCount = "compile_unit_count";
        rv = dbRead(value, dbCommon, keyFileCount);
        if(rv < 0) {
            // key not found 
            dbWrite(dbCommon, keyFileCount, "1");
            m_compileUnitId = "0";
        }
        else if(rv == 0) {
            char buf[1024];
            m_compileUnitId = value;
            char* errp = NULL;
            int id = strtol(m_compileUnitId.c_str(), &errp, 16);
            assert(*errp == '\0');
            snprintf(buf, sizeof(buf), "%x", id+1);
            dbWrite(dbCommon, keyFileCount, buf);
        }
        else {
            printf("ERROR: db info\n");
        }
        dbWrite(dbCommon, TABLE_NAME_CU_NAME_TO_ID "|" + m_compileUnit, m_compileUnitId);
    }
    else if(rv == 0) {
        // alread exists
        m_compileUnitId = value;
    }
    dbClose(dbCommon);

    // open database for this compile unit
    assert(!m_compileUnitId.empty());

    // list of files already processed
    if(!isRebuild) {
        leveldb::WriteBatch wb_common;
        leveldb::DB* db_common;
        int rv = dbTryOpen(db_common, m_commonDbDir);
        if(rv < 0) {
            printf("ERROR: common db open: %s\n", m_commonDbDir.c_str());
            return -1;
        }
        leveldb::Iterator* it = db_common->NewIterator(leveldb::ReadOptions());
        for (it->SeekToFirst(); it->Valid(); it->Next()) {
            //cout << it->key().ToString() << ": "  << it->value().ToString() << endl;
            const string& key = it->key().ToString();
            if(key.find(TABLE_NAME_FILE_LIST "|") == 0) {
                m_finishedFiles[key.substr(2)] = it->value().ToString();
                //cout << key.substr(2) << endl;
            }
        }
        dbClose(db_common);
    }
    else {
        m_isRebuild = true;
    }
    return 0;
}