------------------------------------------------------------------------- register_record -------------------------------------------------------------------------
| 54 | // register_record |
| 55 | //------------------------------------------------------------------------- |
| 56 | static RecRecord * |
| 57 | register_record(RecT rec_type, const char *name, RecDataT data_type, RecData data_default, RecPersistT persist_type, |
| 58 | bool *updated_p = nullptr) |
| 59 | { |
| 60 | RecRecord *r = nullptr; |
| 61 | |
| 62 | // Metrics are restored from persistence before they are registered. In this case, when the registration arrives, we |
| 63 | // might find that they have changed. For example, a metric might change it's type due to a software upgrade. Records |
| 64 | // must not flip between config and metrics, but changing within those classes is OK. |
| 65 | if (auto it = g_records_ht.find(name); it != g_records_ht.end()) { |
| 66 | r = it->second; |
| 67 | if (REC_TYPE_IS_STAT(rec_type)) { |
| 68 | ink_release_assert(REC_TYPE_IS_STAT(r->rec_type)); |
| 69 | } |
| 70 | |
| 71 | if (REC_TYPE_IS_CONFIG(rec_type)) { |
| 72 | ink_release_assert(REC_TYPE_IS_CONFIG(r->rec_type)); |
| 73 | } |
| 74 | |
| 75 | if (data_type != r->data_type) { |
| 76 | // Clear with the old type before resetting with the new type. |
| 77 | RecDataZero(r->data_type, &(r->data)); |
| 78 | RecDataZero(r->data_type, &(r->data_default)); |
| 79 | |
| 80 | // If the data type changed, reset the current value to the default. |
| 81 | RecDataSet(data_type, &(r->data), &(data_default)); |
| 82 | } |
| 83 | |
| 84 | // NOTE: Do not set r->data as we want to keep the previous value because we almost certainly restored a persisted |
| 85 | // value before the metric was registered. |
| 86 | RecDataSet(data_type, &(r->data_default), &(data_default)); |
| 87 | |
| 88 | r->data_type = data_type; |
| 89 | r->rec_type = rec_type; |
| 90 | |
| 91 | if (updated_p) { |
| 92 | *updated_p = true; |
| 93 | } |
| 94 | } else { |
| 95 | if ((r = RecAlloc(rec_type, name, data_type)) == nullptr) { |
| 96 | return nullptr; |
| 97 | } |
| 98 | |
| 99 | // Set the r->data to its default value as this is a new record |
| 100 | RecDataSet(r->data_type, &(r->data), &(data_default)); |
| 101 | RecDataSet(r->data_type, &(r->data_default), &(data_default)); |
| 102 | g_records_ht.emplace(name, r); |
| 103 | |
| 104 | if (REC_TYPE_IS_STAT(r->rec_type)) { |
| 105 | r->stat_meta.persist_type = persist_type; |
| 106 | } |
| 107 | |
| 108 | if (updated_p) { |
| 109 | *updated_p = false; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // we're now registered |
no test coverage detected