//加载sync的主机 int CwxMcConfig::loadSyncHost(string const& strSyncHostFile){ CwxIniParse cnf; string value; string strErrMsg; m_syncHosts.m_hosts.clear(); //解析配置文件 if (false == cnf.load(strSyncHostFile)) { CwxCommon::snprintf(m_szErrMsg, 2047, "Failure to Load conf file:%s. err:%s", strSyncHostFile.c_str(), cnf.getErrMsg()); return -1; } //load sync_host list<pair<string, string> > hosts; if (!cnf.getAttr("host", hosts) || !hosts.size()){ snprintf(m_szErrMsg, 2047, "Must set [host]."); return -1; } list<pair<string, string> >::iterator iter = hosts.begin(); list<string> items; list<string>::iterator item_iter; CwxMcConfigHost hostInfo; while(iter != hosts.end()){ CwxCommon::split(iter->second, items, ':'); if (items.size() != 4){ snprintf(m_szErrMsg, 2047, "[host:%s]'s value[%s] is invalid, must be [port:user:passwd:limit].", iter->first.c_str(), iter->second.c_str()); return -1; } hostInfo.m_host = iter->first; item_iter = items.begin(); hostInfo.m_port = strtoul(item_iter->c_str(), NULL, 10); ++item_iter; hostInfo.m_user = *item_iter; ++item_iter; hostInfo.m_passwd = *item_iter; ++item_iter; hostInfo.m_limit = strtoul(item_iter->c_str(), NULL, 10); if (m_syncHosts.m_hosts.find(hostInfo.m_host) != m_syncHosts.m_hosts.end()) { snprintf(m_szErrMsg, 2047, "[host name:%s] is duplicate.", hostInfo.m_host.c_str()); return -1; } m_syncHosts.m_hosts[hostInfo.m_host] = hostInfo; ++iter; } return 0; }
int CwxMqImportConfig::loadConfig(string const & strConfFile) { CwxIniParse cnf; string value; //解析配置文件 if (false == cnf.load(strConfFile)) { CwxCommon::snprintf(m_szError, 2047, "Failure to Load conf file:%s. err:%s", strConfFile.c_str(), cnf.getErrMsg()); return -1; } //load import:home if (!cnf.getAttr("import", "home", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:home]."); return -1; } if ('/' != value[value.length() - 1]) value += "/"; m_strWorkDir = value; //load import:listen if (!cnf.getAttr("import", "listen", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:listen]."); return -1; } if (!mqParseHostPort(value, m_listen)) { snprintf(m_szError, 2047, "import:listen must be [host:port], [%s] is invalid.", value.c_str()); return -1; } //load import:unix if (!cnf.getAttr("import", "unix", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:unix]."); return -1; } m_strUnixPathFile = value; //load import:user if (!cnf.getAttr("import", "user", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:user]."); return -1; } m_strUser = value; //load import:passwd if (!cnf.getAttr("import", "passwd", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:passwd]."); return -1; } m_strPasswd = value; //load import:conn_type if (!cnf.getAttr("import", "conn_type", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:conn_type]."); return -1; } m_bTcp = (value == "tcp" ? true : false); //load import:conn_num if (!cnf.getAttr("import", "conn_num", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:conn_num]."); return -1; } m_unConnNum = strtoul(value.c_str(), NULL, 10); if (!m_unConnNum) m_unConnNum = 1; //load import:conn_lasting if (!cnf.getAttr("import", "conn_lasting", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:conn_lasting]."); return -1; } m_bLasting = (value == "1" ? true : false); //load import:data_group if (!cnf.getAttr("import", "data_group", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:data_group]."); return -1; } m_uiGroup = strtoul(value.c_str(), NULL, 10); //load import:data_size if (!cnf.getAttr("import", "data_size", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:data_size]."); return -1; } m_unDataSize = strtoul(value.c_str(), NULL, 10); return 0; }
int CwxMcConfig::loadConfig(string const & strConfFile) { CwxIniParse cnf; string value; string strErrMsg; //解析配置文件 if (false == cnf.load(strConfFile)) { CwxCommon::snprintf(m_szErrMsg, 2047, "Failure to Load conf file:%s. err:%s", strConfFile.c_str(), cnf.getErrMsg()); return -1; } //load cmn:home if (!cnf.getAttr("cmn", "home", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [cmn:home]."); return -1; } if ('/' != value[value.length() - 1]) value += "/"; m_common.m_strWorkDir = value; //load cmn:monitor if (!cnf.getAttr("cmn", "monitor", value) || !value.length()) { m_common.m_monitor.reset(); } else { if (!mqParseHostPort(value, m_common.m_monitor)) { snprintf(m_szErrMsg, 2047, "cmn:monitor must be [host:port], [%s] is invalid.", value.c_str()); return -1; } } //load store:path if (!cnf.getAttr("store", "path", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:path]."); return -1; } if ('/' != value[value.length() - 1]) value += "/"; m_store.m_strPath = value; //load store:file_max_mbyte if (!cnf.getAttr("store", "file_max_mbyte", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:file_max_mbyte]."); return -1; } m_store.m_uiLogMSize = strtoul(value.c_str(), NULL, 10); if (m_store.m_uiLogMSize < CwxMcConfigStore::MIN_LOG_MSIZE) { m_store.m_uiLogMSize = CwxMcConfigStore::MIN_LOG_MSIZE; } if (m_store.m_uiLogMSize > CwxMcConfigStore::MAX_LOG_MSIZE) { m_store.m_uiLogMSize = CwxMcConfigStore::MAX_LOG_MSIZE; } //load store:reserve_day if (!cnf.getAttr("store", "reserve_day", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:reserve_day]."); return -1; } m_store.m_uiReserveDay = strtoul(value.c_str(), NULL, 10); //load store:append_return if (!cnf.getAttr("store", "append_return", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:append_return]."); return -1; } if (value=="yes"){ m_store.m_bAppendReturn = true; }else if (value=="no"){ m_store.m_bAppendReturn = false; }else{ snprintf(m_szErrMsg, 2047, "Invalid [store:append_return]'s value[%s], must be yes/no.", value.c_str()); return -1; } //load store:record_prefix if (!cnf.getAttr("store", "record_prefix", value) || !value.length()) { m_store.m_strRecordPrefix.erase(); }else{ m_store.m_strRecordPrefix = value; } //load store:file_max_second if (!cnf.getAttr("store", "file_max_second", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:file_max_second]."); return -1; } m_store.m_uiSwitchSecond = strtoul(value.c_str(), NULL, 10); //load store:flush_log_num if (!cnf.getAttr("store", "flush_log_num", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:flush_log_num]."); return -1; } m_store.m_uiFlushNum = strtoul(value.c_str(), NULL, 10); if (m_store.m_uiFlushNum < 1) { m_store.m_uiFlushNum = 1; } //load store:flush_log_second if (!cnf.getAttr("store", "flush_log_second", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:flush_log_second]."); return -1; } m_store.m_uiFlushSecond = strtoul(value.c_str(), NULL, 10); if (m_store.m_uiFlushSecond < 1) { m_store.m_uiFlushSecond = 1; } //fetch mq if (!fetchHost(cnf, "mq", m_mq.m_mq)) return -1; //load mq:log_path if (!cnf.getAttr("mq", "name", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [mq:name]."); return -1; } m_mq.m_strName = value; //load mq:cache_msize if (!cnf.getAttr("mq", "cache_msize", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [mq:cache_msize]."); return -1; } m_mq.m_uiCacheMSize = strtoul(value.c_str(), NULL, 10); if (m_mq.m_uiCacheMSize < 1) { m_mq.m_uiCacheMSize = 1; } //load mq:cache_second if (!cnf.getAttr("mq", "cache_second", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [mq:cache_second]."); return -1; } m_mq.m_uiCacheTimeout = strtoul(value.c_str(), NULL, 10); //load sync //load sync:source if (!cnf.getAttr("sync", "source", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:source]."); return -1; } m_sync.m_strSource = value; //load sync:sock_buf_kbyte if (!cnf.getAttr("sync", "sock_buf_kbyte", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:sock_buf_kbyte]."); return -1; } m_sync.m_uiSockBufKByte = strtoul(value.c_str(), NULL, 10); //load sync:max_chunk_kbyte if (!cnf.getAttr("sync", "max_chunk_kbyte", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:max_chunk_kbyte]."); return -1; } m_sync.m_uiChunkKBye = strtoul(value.c_str(), NULL, 10); if (m_sync.m_uiChunkKBye > CWX_MQ_MAX_CHUNK_KSIZE) m_sync.m_uiChunkKBye = CWX_MQ_MAX_CHUNK_KSIZE; //load sync:sync_conn_num if (!cnf.getAttr("sync", "sync_conn_num", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:sync_conn_num]."); return -1; } m_sync.m_uiConnNum = strtoul(value.c_str(), NULL, 10); if (m_sync.m_uiConnNum < 1) m_sync.m_uiConnNum = 1; //load sync:zip if (!cnf.getAttr("sync", "zip", value) || !value.length()) { m_sync.m_bzip = false; } else { if (value == "yes") m_sync.m_bzip = true; else m_sync.m_bzip = false; } return 0; }
int UnistorBenchConfig::loadConfig(string const & strConfFile){ CwxIniParse parser; string value; //½âÎöÅäÖÃÎļþ if (false == parser.load(strConfFile)){ snprintf(m_szError, 2047, "Failure to Load conf file. err=%s", parser.getErrMsg()); return -1; } //load unistor_bench:home if (!parser.getAttr("unistor_bench", "home", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:home] for running path."); return -1; } if ('/' != value[value.length()-1]) value +="/"; m_strWorkDir = value; //load unistor_bench:listen if (!parser.getAttr("unistor_bench", "listen", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:listen]."); return -1; } if (!parseHostPort(value, m_listen)){ snprintf(m_szError, 2047, "[unistor_bench:listen] is invalid, it should be [ip:port] format."); return -1; } // load echo unistor_bench:conn_num if (!parser.getAttr("unistor_bench", "conn_num", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:conn_num]."); return -1; } m_unConnNum = strtoul(value.c_str(), NULL, 0); // load echo unistor_bench:conn_lasting if (!parser.getAttr("unistor_bench", "conn_lasting", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:conn_lasting]."); return -1; } m_bLasting = value=="1"?true:false; // load echo unistor_bench:data_opr if (!parser.getAttr("unistor_bench", "data_opr", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_opr]."); return -1; } m_strOpr =value; if ((m_strOpr != "import")&&(m_strOpr != "add")&&(m_strOpr != "set")&&(m_strOpr != "update")&&(m_strOpr != "delete")&&(m_strOpr != "get")){ snprintf(m_szError, 2047, "invalid data opr[%s] for [unistor_bench:data_opr], must be [add/set/update/delete/import/get", m_strOpr.c_str()); return -1; } // load echo unistor_bench:data_size if (!parser.getAttr("unistor_bench", "data_size", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_size]."); return -1; } m_uiDataSize =strtoul(value.c_str(), NULL, 0); if (m_uiDataSize > 1024*1024) m_uiDataSize = 1024*1024; // load echo unistor_bench:data_key_in_order if (!parser.getAttr("unistor_bench", "data_key_in_order", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_key_in_order]."); return -1; } m_bKeyOrder = value=="yes"?true:false; // load echo unistor_bench:data_get_order if (!parser.getAttr("unistor_bench", "data_get_order", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_get_order]."); return -1; } m_bGetOrder = value == "yes"?true:false; // load echo unistor_bench:data_base if (!parser.getAttr("unistor_bench", "data_base", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_base]."); return -1; } m_uiDataBase =strtoul(value.c_str(), NULL, 0); if (m_uiDataBase < 10000) m_uiDataBase = 10000; // load echo unistor_bench:data_mod if (!parser.getAttr("unistor_bench", "data_mod", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_mod]."); return -1; } m_uiDataMod =strtoul(value.c_str(), NULL, 0); // load echo unistor_bench:data_master if (!parser.getAttr("unistor_bench", "data_master", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_master]."); return -1; } m_bGetMaster = (value == "yes"?true:false); // load echo unistor_bench:cache if (!parser.getAttr("unistor_bench", "cache", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:cache]."); return -1; } m_bCache = (value == "yes"?true:false); // load echo unistor_bench:data_group if (!parser.getAttr("unistor_bench", "data_group", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_group]."); return -1; } m_uiKeyGroup = strtoul(value.c_str(), NULL, 0); if (0 == m_uiKeyGroup) m_uiKeyGroup = 1; // load echo unistor_bench:data_group_index if (!parser.getAttr("unistor_bench", "data_group_index", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_group_index]."); return -1; } m_uiKeyIndex = strtoul(value.c_str(), NULL, 0); if (m_uiKeyIndex >= m_uiKeyGroup) m_uiKeyIndex = m_uiKeyGroup - 1; // load echo unistor_bench:expire if (!parser.getAttr("unistor_bench", "expire", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:expire]."); return -1; } m_uiExpire =strtoul(value.c_str(), NULL, 0); // load echo unistor_bench:user if (!parser.getAttr("unistor_bench", "user", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:user]."); return -1; } m_strUser = value; // load echo unistor_bench:passwd if (!parser.getAttr("unistor_bench", "passwd", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:passwd]."); return -1; } m_strPasswd = value; return 0; }