* * @brief: 检查从json中解析的字段是否符合规定 * @return: 解析正确返回true,错误为false */
()
| 188 | * @return: 解析正确返回true,错误为false |
| 189 | */ |
| 190 | func (cfg *ServerConfig) checkJsonParser() error { |
| 191 | // 当配置数小于7的时候,留给其他服务器启动的时间太少,配置为8的时候,至少已经过了51秒了(2^9-2^1) |
| 192 | if cfg.Maxreries <= 7 { |
| 193 | return ErrorInParserConfig(maxreries_to_small) |
| 194 | } |
| 195 | |
| 196 | ServerAddressLength := len(cfg.ServersAddress) |
| 197 | |
| 198 | if ServerAddressLength < 2 { // 至少三台,且推荐为奇数,计算时加上自己 |
| 199 | return ErrorInParserConfig(serveraddress_length_to_small) |
| 200 | } |
| 201 | |
| 202 | for _, AddressItem := range cfg.ServersAddress { |
| 203 | if !ParserIP(AddressItem) { |
| 204 | return ErrorInParserConfig(serveraddress_format_error) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if !parserMyPort(cfg.MyPort) { |
| 209 | return ErrorInParserConfig(parser_port_error) |
| 210 | } |
| 211 | |
| 212 | // TODO 看下几个函数的收敛区间 |
| 213 | // 一个超时区间不能太大或者太小。这个区间是可以保证 |
| 214 | if cfg.TimeOutEntry <= 100 || cfg.TimeOutEntry >= 2000 { |
| 215 | return ErrorInParserConfig(time_out_entry_error) |
| 216 | } |
| 217 | |
| 218 | // /proc/cpuinfo https://blog.csdn.net/wswit/article/details/52665413 l2 cache |
| 219 | if cfg.MaxRaftState < 0 || cfg.MaxRaftState > 2097152 { |
| 220 | return ErrorInParserConfig(raft_maxraftstate_not_suitable) |
| 221 | } |
| 222 | |
| 223 | // 解析SnapshotFileName是否符合规范 |
| 224 | if !ParserFileName(cfg.SnapshotFileName){ |
| 225 | return ErrorInParserConfig(parser_snapshot_file_name) |
| 226 | } |
| 227 | |
| 228 | // 解析RaftstateFileName是否符合规范 |
| 229 | if !ParserFileName(cfg.RaftstateFileName){ |
| 230 | return ErrorInParserConfig(parser_raftstate_file_name) |
| 231 | } |
| 232 | |
| 233 | // 解析PersistenceStrategy是否符合规范 |
| 234 | if !checkPersistenceStrategy(cfg.PersistenceStrategy){ |
| 235 | return ErrorInParserConfig(parser_persistence_strategy) |
| 236 | } |
| 237 | |
| 238 | // 解析ChubbyGoMapStrategy是否符合规范 |
| 239 | if !checkChubbyGoMapStrategy(cfg.ChubbyGoMapStrategy){ |
| 240 | return ErrorInParserConfig(parser_chubbygomap_strategy) |
| 241 | } |
| 242 | |
| 243 | return nil |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * @brief: 再调用这个函数的时候开始服务, |
no test coverage detected