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

Function RecReadStatsFile

src/records/P_RecCore.cc:272–325  ·  view source on GitHub ↗

------------------------------------------------------------------------- RecReadStatsFile -------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

270// RecReadStatsFile
271//-------------------------------------------------------------------------
272RecErrT
273RecReadStatsFile()
274{
275 RecRecord *r;
276 RecMessage *m;
277 RecMessageItr itr;
278 RecPersistT persist_type = RECP_NULL;
279 ats_scoped_str snap_fpath(RecConfigReadPersistentStatsPath());
280
281 // lock our hash table
282 ink_rwlock_wrlock(&g_records_rwlock);
283
284 CheckSnapFileVersion(snap_fpath);
285
286 if ((m = RecMessageReadFromDisk(snap_fpath)) != nullptr) {
287 if (RecMessageUnmarshalFirst(m, &itr, &r) != REC_ERR_FAIL) {
288 do {
289 if ((r->name == nullptr) || (!strlen(r->name))) {
290 continue;
291 }
292
293 // If we don't have a persistence type for this record, it means that it is not a stat, or it is
294 // not registered yet. Either way, it's ok to just set the persisted value and keep going.
295 if (RecGetRecordPersistenceType(r->name, &persist_type, false /* lock */) != REC_ERR_OKAY) {
296 RecDebug(DL_Debug, "restoring value for persisted stat '%s'", r->name);
297 RecSetRecord(r->rec_type, r->name, r->data_type, &(r->data), &(r->stat_meta.data_raw), REC_SOURCE_EXPLICIT, false);
298 continue;
299 }
300
301 if (!REC_TYPE_IS_STAT(r->rec_type)) {
302 // This should not happen, but be defensive against records changing their type ..
303 RecLog(DL_Warning, "skipping restore of non-stat record '%s'", r->name);
304 continue;
305 }
306
307 // Check whether the persistence type was changed by a new software version. If the record is
308 // already registered with an updated persistence type, then we don't want to set it. We should
309 // keep the registered value.
310 if (persist_type == RECP_NON_PERSISTENT) {
311 RecDebug(DL_Debug, "preserving current value of formerly persistent stat '%s'", r->name);
312 continue;
313 }
314
315 RecDebug(DL_Debug, "restoring value for persisted stat '%s'", r->name);
316 RecSetRecord(r->rec_type, r->name, r->data_type, &(r->data), &(r->stat_meta.data_raw), REC_SOURCE_EXPLICIT, false);
317 } while (RecMessageUnmarshalNext(m, &itr, &r) != REC_ERR_FAIL);
318 }
319 }
320
321 ink_rwlock_unlock(&g_records_rwlock);
322 ats_free(m);
323
324 return REC_ERR_OKAY;
325}
326
327//-------------------------------------------------------------------------
328// RecSyncStatsFile

Callers 1

RecCoreInitFunction · 0.85

Calls 10

ink_rwlock_wrlockFunction · 0.85
CheckSnapFileVersionFunction · 0.85
RecMessageReadFromDiskFunction · 0.85
RecMessageUnmarshalFirstFunction · 0.85
RecSetRecordFunction · 0.85
RecMessageUnmarshalNextFunction · 0.85
ink_rwlock_unlockFunction · 0.85
ats_freeFunction · 0.85

Tested by

no test coverage detected