| 1215 | |
| 1216 | |
| 1217 | int ds_reload_db(ds_partition_t *partition, int initial, int is_inherit_state) |
| 1218 | { |
| 1219 | ds_data_t *old_data; |
| 1220 | ds_data_t *new_data; |
| 1221 | |
| 1222 | if (initial) |
| 1223 | sr_set_status( ds_srg, STR2CI(partition->name), |
| 1224 | SR_STATUS_LOADING_DATA, CHAR_INT("startup data loading"), 0); |
| 1225 | else |
| 1226 | sr_set_status( ds_srg, STR2CI(partition->name), |
| 1227 | SR_STATUS_RELOADING_DATA, CHAR_INT("data re-loading"), 0); |
| 1228 | |
| 1229 | new_data = ds_load_data(partition); |
| 1230 | if (new_data==NULL) { |
| 1231 | LM_ERR("failed to load the new data, dropping the reload\n"); |
| 1232 | if (initial) |
| 1233 | sr_set_status( ds_srg, STR2CI(partition->name), SR_STATUS_NO_DATA, |
| 1234 | CHAR_INT("no data loaded"), 0); |
| 1235 | else |
| 1236 | sr_set_status( ds_srg, STR2CI(partition->name), SR_STATUS_READY, |
| 1237 | CHAR_INT("data available"), 0); |
| 1238 | return -1; |
| 1239 | } |
| 1240 | |
| 1241 | lock_start_write( partition->lock ); |
| 1242 | |
| 1243 | /* no more activ readers -> do the swapping */ |
| 1244 | old_data = *partition->data; |
| 1245 | *partition->data = new_data; |
| 1246 | |
| 1247 | lock_stop_write( partition->lock ); |
| 1248 | |
| 1249 | /* destroy old data */ |
| 1250 | if (old_data) { |
| 1251 | /* copy the state of the destinations from the old set |
| 1252 | * (for the matching ids) */ |
| 1253 | if (is_inherit_state) { |
| 1254 | ds_inherit_state( old_data, new_data); |
| 1255 | } |
| 1256 | |
| 1257 | ds_destroy_data_set( old_data ); |
| 1258 | } |
| 1259 | |
| 1260 | /* update the Black Lists with the new gateways */ |
| 1261 | populate_ds_bls( new_data->sets, partition->name); |
| 1262 | |
| 1263 | sr_set_status( ds_srg, STR2CI(partition->name), SR_STATUS_READY, |
| 1264 | CHAR_INT("data available"), 0); |
| 1265 | |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | /** |
no test coverage detected