// Returns: // True - configuration file was read // False - configuration file was not read, either because an error occurred, or because the config file was previously // read and has not changed since then. bool ReplicaConfig::readConfigFile() { SNode s; if( LocalFS::stat(pathToConfigFile, s) < 0 || s.m_llTimeStamp == configFileTimestamp ) return false; configFileTimestamp = s.m_llTimeStamp; ConfParser parser; Param param; if (0 != parser.init(pathToConfigFile)) return false; while (parser.getNextParam(param) >= 0) { if ("REPLICATION_NUMBER" == param.m_strName) { for (vector<string>::iterator i = param.m_vstrValue.begin(); i != param.m_vstrValue.end(); ++ i) { string path; int num1, num2; if (parseItem(*i, path, num1, num2) >= 0) { string rp = Metadata::revisePath(path); if (rp.length() > 0) { configData.m_mReplicaNum[rp] = pair<int,int>(num1,num2); } } } } else if ("REPLICATION_DISTANCE" == param.m_strName) { for (vector<string>::iterator i = param.m_vstrValue.begin(); i != param.m_vstrValue.end(); ++ i) { string path; int dist; if (parseItem(*i, path, dist) >= 0) { string rp = Metadata::revisePath(path); if (rp.length() > 0) configData.m_mReplicaDist[rp] = dist; } } } else if ("REPLICATION_LOCATION" == param.m_strName) { for (vector<string>::iterator i = param.m_vstrValue.begin(); i != param.m_vstrValue.end(); ++ i) { string path; string loc; parseItem(*i, path, loc); string rp = Metadata::revisePath(path); vector<int> topo; Topology::parseTopo(loc.c_str(), topo); if ((rp.length() > 0) && !topo.empty()) configData.m_mRestrictedLoc[rp] = topo; } } else if ("REPLICATION_MAX_TRANS" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_iReplicationMaxTrans = atoi(param.m_vstrValue[0].c_str()); else cerr << "no value specified for REPLICATION_MAX_TRANS" << endl; } else if ("CHECK_REPLICA_ON_SAME_IP" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_bCheckReplicaOnSameIp = (param.m_vstrValue[0] == "TRUE" ); else cerr << "no value specified for CHECK_REPLICA_ON_SAME_IP" << endl; } else if ("PCT_SLAVES_TO_CONSIDER" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_iPctSlavesToConsider = atoi(param.m_vstrValue[0].c_str()); else cerr << "no value specified for PCT_SLAVES_TO_CONSIDER" << endl; } else if ("REPLICATION_START_DELAY" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_iReplicationStartDelay = atoi(param.m_vstrValue[0].c_str()); else cerr << "no value specified for REPLICATION_START_DELAY" << endl; } else if ("REPLICATION_FULL_SCAN_DELAY" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_iReplicationFullScanDelay = atoi(param.m_vstrValue[0].c_str()); else cerr << "no value specified for REPLICATION_FULL_SCAN_DELAY" << endl; if (configData.m_iReplicationFullScanDelay < 60) configData.m_iReplicationFullScanDelay = 60; } else if ("DISK_BALANCE_AGGRESSIVENESS" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_iDiskBalanceAggressiveness = atoi(param.m_vstrValue[0].c_str()); else cerr << "no value specified for DISK_BALANCE_AGGRESSIVENESS" << endl; configData.m_iDiskBalanceAggressiveness = std::max( 0, configData.m_iDiskBalanceAggressiveness ); configData.m_iDiskBalanceAggressiveness = std::min( 100, configData.m_iDiskBalanceAggressiveness ); } else if ("REPLICATE_ON_TRANSACTION_CLOSE" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_bReplicateOnTransactionClose = (param.m_vstrValue[0] == "TRUE"); else cerr << "no value specified for REPLICATE_ON_TRANSACTION_CLOSE" << endl; } else if ("CHECK_REPLICA_CLUSTER" == param.m_strName) { if( !param.m_vstrValue.empty() ) configData.m_bCheckReplicaCluster = (param.m_vstrValue[0] == "TRUE"); else cerr << "no value specified for CHECK_REPLCIA_CLUSTER" << endl; } else { cerr << "unrecognized replica.conf parameter: " << param.m_strName << endl; } } parser.close(); return true; }
int MasterConf::init(const string& path) { ConfParser parser; Param param; if (0 != parser.init(path)) return -1; while (parser.getNextParam(param) >= 0) { if (param.m_vstrValue.empty()) continue; if ("SECTOR_PORT" == param.m_strName) m_iServerPort = atoi(param.m_vstrValue[0].c_str()); else if ("SECURITY_SERVER" == param.m_strName) { char buf[128]; strncpy(buf, param.m_vstrValue[0].c_str(), 128); unsigned int i = 0; for (unsigned int n = strlen(buf); i < n; ++ i) { if (buf[i] == ':') break; } buf[i] = '\0'; m_strSecServIP = buf; m_iSecServPort = atoi(buf + i + 1); } else if ("MAX_ACTIVE_USER" == param.m_strName) m_iMaxActiveUser = atoi(param.m_vstrValue[0].c_str()); else if ("DATA_DIRECTORY" == param.m_strName) { m_strHomeDir = param.m_vstrValue[0]; if (m_strHomeDir.c_str()[m_strHomeDir.length() - 1] != '/') m_strHomeDir += "/"; } else if ("REPLICA_NUM" == param.m_strName) m_iReplicaNum = atoi(param.m_vstrValue[0].c_str()); else if ("REPLICA_DIST" == param.m_strName) m_iReplicaDist = atoi(param.m_vstrValue[0].c_str()); else if ("META_LOC" == param.m_strName) { if ("MEMORY" == param.m_vstrValue[0]) m_MetaType = MEMORY; else if ("DISK" == param.m_vstrValue[0]) m_MetaType = DISK; } else if ("SLAVE_TIMEOUT" == param.m_strName) { m_iSlaveTimeOut = atoi(param.m_vstrValue[0].c_str()); // slave reports every 30 - 60 seconds if (m_iSlaveTimeOut < 120) m_iSlaveTimeOut = 120; } else if ("LOST_SLAVE_RETRY_TIME" == param.m_strName) { m_iSlaveRetryTime = atoi(param.m_vstrValue[0].c_str()); if (m_iSlaveRetryTime < 0) m_iSlaveRetryTime = 0; } else if ("SLAVE_MIN_DISK_SPACE" == param.m_strName) { m_llSlaveMinDiskSpace = atoll(param.m_vstrValue[0].c_str()) * 1000000; } else if ("CLIENT_TIMEOUT" == param.m_strName) { m_iClientTimeOut = atoi(param.m_vstrValue[0].c_str()); // client only sends heartbeat every 60 - 120 seconds, so this value cannot be too small if (m_iClientTimeOut < 300) m_iClientTimeOut = 300; } else if ("LOG_LEVEL" == param.m_strName) { m_iLogLevel = atoi(param.m_vstrValue[0].c_str()); } else if ("PROCESS_THREADS" == param.m_strName) { m_iProcessThreads = atoi(param.m_vstrValue[0].c_str()); } else if ("WRITE_ONCE_PROTECTION" == param.m_strName) { for (vector<string>::iterator i = param.m_vstrValue.begin(); i != param.m_vstrValue.end(); ++ i) { string rp = Metadata::revisePath(*i); m_vWriteOncePath.push_back(rp); } } else { cerr << "unrecongnized system parameter: " << param.m_strName << endl; } } parser.close(); return 0; }
int ClientConf::init(const string& path) { ConfParser parser; Param param; if (0 != parser.init(path)) return -1; while (parser.getNextParam(param) >= 0) { if (param.m_vstrValue.empty()) continue; if ("MASTER_ADDRESS" == param.m_strName) { char buf[128]; strncpy(buf, param.m_vstrValue[0].c_str(), 128); unsigned int i = 0; for (unsigned int n = strlen(buf); i < n; ++ i) { if (buf[i] == ':') break; } buf[i] = '\0'; m_strMasterIP = buf; m_iMasterPort = atoi(buf + i + 1); } else if ("USERNAME" == param.m_strName) { m_strUserName = param.m_vstrValue[0]; } else if ("PASSWORD" == param.m_strName) { m_strPassword = param.m_vstrValue[0]; } else if ("CERTIFICATE" == param.m_strName) { m_strCertificate = param.m_vstrValue[0]; } else if ("MAX_CACHE_SIZE" == param.m_strName) { #ifndef WIN32 m_llMaxCacheSize = atoll(param.m_vstrValue[0].c_str()) * 1000000; #else m_llMaxCacheSize = _atoi64(param.m_vstrValue[0].c_str()) * 1000000; #endif } else if ("FUSE_READ_AHEAD_BLOCK" == param.m_strName) { m_iFuseReadAheadBlock = atoi(param.m_vstrValue[0].c_str()) * 1000000; } else if ("MAX_READ_CACHE_SIZE" == param.m_strName) { #ifndef WIN32 m_llMaxWriteCacheSize = atoll(param.m_vstrValue[0].c_str()) * 1000000; #else m_llMaxWriteCacheSize = _atoi64(param.m_vstrValue[0].c_str()) * 1000000; #endif } else cerr << "unrecongnized client.conf parameter: " << param.m_strName << endl; } parser.close(); return 0; }
int SlaveConf::init(const string& path) { // initialize these values; a slave must call init() // cannot initialize the following values in constructor because they are reserved for global conf m_iMasterPort = 6000; m_strHomeDir = "./"; m_llMaxDataSize = -1; m_iMaxServiceNum = 64; m_MetaType = MEMORY; m_iLogLevel = 1; ConfParser parser; Param param; if (0 != parser.init(path)) return -1; while (parser.getNextParam(param) >= 0) { if (param.m_vstrValue.empty()) continue; if ("MASTER_ADDRESS" == param.m_strName) { char buf[128]; strncpy(buf, param.m_vstrValue[0].c_str(), 128); unsigned int i = 0; for (unsigned int n = strlen(buf); i < n; ++ i) { if (buf[i] == ':') break; } buf[i] = '\0'; m_strMasterHost = buf; m_iMasterPort = atoi(buf + i + 1); } else if ("DATA_DIRECTORY" == param.m_strName) { m_strHomeDir = param.m_vstrValue[0]; if (m_strHomeDir.c_str()[m_strHomeDir.length() - 1] != '/') m_strHomeDir += "/"; } else if ("MAX_DATA_SIZE" == param.m_strName) { m_llMaxDataSize = atoll(param.m_vstrValue[0].c_str()) * 1024 * 1024; } else if ("MAX_SERVICE_INSTANCE" == param.m_strName) m_iMaxServiceNum = atoi(param.m_vstrValue[0].c_str()); else if ("LOCAL_ADDRESS" == param.m_strName) m_strLocalIP = param.m_vstrValue[0]; else if ("PUBLIC_ADDRESS" == param.m_strName) m_strPublicIP = param.m_vstrValue[0]; else if ("META_LOC" == param.m_strName) { if ("MEMORY" == param.m_vstrValue[0]) m_MetaType = MEMORY; else if ("DISK" == param.m_vstrValue[0]) m_MetaType = DISK; } else if ("LOG_LEVEL" == param.m_strName) { m_iLogLevel = atoi(param.m_vstrValue[0].c_str()); } else { cerr << "unrecongnized system parameter: " << param.m_strName << endl; } } parser.close(); return 0; }
int SlaveConf::init(const string& path) { ConfParser parser; Param param; if (0 != parser.init(path)) return -1; while (parser.getNextParam(param) >= 0) { if (param.m_vstrValue.empty()) continue; if ("MASTER_ADDRESS" == param.m_strName) { char buf[128]; strncpy(buf, param.m_vstrValue[0].c_str(), 128); unsigned int i = 0; for (unsigned int n = strlen(buf); i < n; ++ i) { if (buf[i] == ':') break; } buf[i] = '\0'; m_strMasterHost = buf; m_iMasterPort = atoi(buf + i + 1); } else if ("DATA_DIRECTORY" == param.m_strName) { m_strHomeDir = param.m_vstrValue[0]; #ifdef WIN32 win_to_unix_path (m_strHomeDir); struct stat t; if (stat(m_strHomeDir.c_str(), &t) != 0) { char szPath[MAX_PATH]=""; if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_DEFAULT, szPath))) { m_strHomeDir.assign (szPath); char first = param.m_vstrValue[0][0]; if (first != '/' && first != '\\') m_strHomeDir += "\\"; m_strHomeDir.append(param.m_vstrValue[0]); win_to_unix_path (m_strHomeDir); } } #ifdef _DEBUG printf ("DATA_DIRECTORY: %s\n", m_strHomeDir.c_str()); #endif #endif if (m_strHomeDir.c_str()[m_strHomeDir.length() - 1] != '/') m_strHomeDir += "/"; } else if ("MAX_DATA_SIZE" == param.m_strName) { #ifndef WIN32 m_llMaxDataSize = atoll(param.m_vstrValue[0].c_str()) * 1024 * 1024; #else m_llMaxDataSize = _atoi64(param.m_vstrValue[0].c_str()) * 1024 * 1024; #endif } else if ("MAX_SERVICE_INSTANCE" == param.m_strName) m_iMaxServiceNum = atoi(param.m_vstrValue[0].c_str()); else if ("LOCAL_ADDRESS" == param.m_strName) m_strLocalIP = param.m_vstrValue[0]; else if ("PUBLIC_ADDRESS" == param.m_strName) m_strPublicIP = param.m_vstrValue[0]; else if ("META_LOC" == param.m_strName) { if ("MEMORY" == param.m_vstrValue[0]) m_MetaType = MEMORY; else if ("DISK" == param.m_vstrValue[0]) m_MetaType = DISK; } else cerr << "unrecongnized system parameter: " << param.m_strName << endl; } parser.close(); return 0; }
int MasterConf::init(const string& path) { ConfParser parser; Param param; if (0 != parser.init(path)) return -1; while (parser.getNextParam(param) >= 0) { if (param.m_vstrValue.empty()) continue; if ("SECTOR_PORT" == param.m_strName) m_iServerPort = atoi(param.m_vstrValue[0].c_str()); else if ("SECURITY_SERVER" == param.m_strName) { char buf[128]; strncpy(buf, param.m_vstrValue[0].c_str(), 128); unsigned int i = 0; for (unsigned int n = strlen(buf); i < n; ++ i) { if (buf[i] == ':') break; } buf[i] = '\0'; m_strSecServIP = buf; m_iSecServPort = atoi(buf + i + 1); } else if ("MAX_ACTIVE_USER" == param.m_strName) m_iMaxActiveUser = atoi(param.m_vstrValue[0].c_str()); else if ("DATA_DIRECTORY" == param.m_strName) { m_strHomeDir = param.m_vstrValue[0]; #ifdef WIN32 win_to_unix_path (m_strHomeDir); struct stat t; if (stat(m_strHomeDir.c_str(), &t) != 0) { char szPath[MAX_PATH]=""; if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_DEFAULT, szPath))) { m_strHomeDir.assign (szPath); char first = param.m_vstrValue[0][0]; if (first != '/' && first != '\\') m_strHomeDir += "\\"; m_strHomeDir.append(param.m_vstrValue[0]); win_to_unix_path (m_strHomeDir); } } #ifdef _DEBUG printf ("DATA_DIRECTORY: %s\n", m_strHomeDir.c_str()); #endif #endif char last = m_strHomeDir.c_str()[m_strHomeDir.length() - 1]; if (last != '/' && last != '\\') m_strHomeDir += "/"; } else if ("REPLICA_NUM" == param.m_strName) m_iReplicaNum = atoi(param.m_vstrValue[0].c_str()); else if ("META_LOC" == param.m_strName) { if ("MEMORY" == param.m_vstrValue[0]) m_MetaType = MEMORY; else if ("DISK" == param.m_vstrValue[0]) m_MetaType = DISK; } else if ("SLAVE_TIMEOUT" == param.m_strName) { m_iSlaveTimeOut = atoi(param.m_vstrValue[0].c_str()); if (m_iSlaveTimeOut < 120) m_iSlaveTimeOut = 120; } else if ("SLAVE_MIN_DISK_SPACE" == param.m_strName) { #ifndef WIN32 m_llSlaveMinDiskSpace = atoll(param.m_vstrValue[0].c_str()) * 1000000; #else m_llSlaveMinDiskSpace = _atoi64(param.m_vstrValue[0].c_str()) * 1000000; #endif } else if ("CLIENT_TIMEOUT" == param.m_strName) { m_iClientTimeOut = atoi(param.m_vstrValue[0].c_str()); } else if ("LOG_LEVEL" == param.m_strName) { m_iLogLevel = atoi(param.m_vstrValue[0].c_str()); } else { cerr << "unrecongnized system parameter: " << param.m_strName << endl; } } parser.close(); return 0; }