MCPcopy Create free account
hub / github.com/apache/trafficserver / config_reloader

Function config_reloader

plugins/origin_server_auth/origin_server_auth.cc:1134–1181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1132}
1133
1134int
1135config_reloader(TSCont cont, TSEvent /* event ATS_UNUSED */, void *edata)
1136{
1137 Dbg(dbg_ctl, "reloading configs");
1138 S3Config *s3 = static_cast<S3Config *>(TSContDataGet(cont));
1139 s3->check_current_action(edata);
1140 S3Config *file_config = gConfCache.get(s3->conf_fname());
1141 std::string config_fname = makeConfigPath(s3->conf_fname() == nullptr ? "" : s3->conf_fname());
1142
1143 if (!file_config || !file_config->valid()) {
1144 TSError("[%s] invalid configuration for version: %s %s. Check mandatory fields. Scheduling reload", PLUGIN_NAME,
1145 s3->versionString(), config_fname.c_str());
1146 long delay = 1 << s3->incr_invalid_file_count();
1147 s3->schedule_conf_reload(delay);
1148 return TS_ERROR;
1149 }
1150 s3->reset_invalid_file_count();
1151
1152 {
1153 std::unique_lock lock(s3->reload_mutex);
1154 s3->copy_changes_from(file_config);
1155 }
1156
1157 if (s3->expiration() == 0) {
1158 Dbg(dbg_ctl, "disabling auto config reload for version: %s %s", s3->versionString(), config_fname.c_str());
1159 } else {
1160 // auto reload is scheduled to be 5 minutes before the expiration time to get some headroom
1161 long time_diff = s3->expiration() -
1162 std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
1163 if (time_diff > 0) {
1164 long delay = cal_reload_delay(time_diff);
1165 TSNote("scheduling config reload with %ld seconds delay for version: %s %s", delay, s3->versionString(),
1166 config_fname.c_str());
1167 s3->reset_conf_reload_count();
1168 s3->schedule_conf_reload(delay);
1169 } else {
1170 Dbg(dbg_ctl, "config expiration time for version: %s %s is in the past, re-checking in 1 minute", s3->versionString(),
1171 config_fname.c_str());
1172 if (s3->incr_conf_reload_count() % 10 == 0) {
1173 TSError("[%s] tried to reload config automatically but failed, please try manual reloading the config file: %s",
1174 PLUGIN_NAME, config_fname.c_str());
1175 }
1176 s3->schedule_conf_reload(60);
1177 }
1178 }
1179
1180 return TS_SUCCESS;
1181}
1182
1183///////////////////////////////////////////////////////////////////////////////
1184// Initialize the plugin.

Callers

nothing calls this directly

Calls 15

TSContDataGetFunction · 0.85
cal_reload_delayFunction · 0.85
TSNoteFunction · 0.85
check_current_actionMethod · 0.80
conf_fnameMethod · 0.80
versionStringMethod · 0.80
schedule_conf_reloadMethod · 0.80
copy_changes_fromMethod · 0.80
expirationMethod · 0.80

Tested by

no test coverage detected