------------------------------------------------------------------------- RecSetRecordXXX -------------------------------------------------------------------------
| 135 | // RecSetRecordXXX |
| 136 | //------------------------------------------------------------------------- |
| 137 | RecErrT |
| 138 | RecSetRecord(RecT rec_type, const char *name, RecDataT data_type, RecData *data, RecRawStat *data_raw, RecSourceT source, bool lock) |
| 139 | { |
| 140 | RecErrT err = REC_ERR_OKAY; |
| 141 | RecRecord *r1; |
| 142 | |
| 143 | // FIXME: Most of the time we set, we don't actually need to wrlock |
| 144 | // since we are not modifying the g_records_ht. |
| 145 | if (lock) { |
| 146 | ink_rwlock_wrlock(&g_records_rwlock); |
| 147 | } |
| 148 | if (auto it = g_records_ht.find(name); it != g_records_ht.end()) { |
| 149 | r1 = it->second; |
| 150 | if (i_am_the_record_owner(r1->rec_type)) { |
| 151 | rec_mutex_acquire(&(r1->lock)); |
| 152 | if ((data_type != RECD_NULL) && (r1->data_type != data_type)) { |
| 153 | err = REC_ERR_FAIL; |
| 154 | } else { |
| 155 | bool rec_updated_p = false; |
| 156 | if (data_type == RECD_NULL) { |
| 157 | // If the caller didn't know the data type, they gave us a string |
| 158 | // and we should convert based on the record's data type. |
| 159 | ink_release_assert(data->rec_string != nullptr); |
| 160 | rec_updated_p = RecDataSetFromString(r1->data_type, &(r1->data), data->rec_string); |
| 161 | } else { |
| 162 | rec_updated_p = RecDataSet(data_type, &(r1->data), data); |
| 163 | } |
| 164 | |
| 165 | if (rec_updated_p) { |
| 166 | r1->sync_required = REC_SYNC_REQUIRED; |
| 167 | if (REC_TYPE_IS_CONFIG(r1->rec_type)) { |
| 168 | r1->config_meta.update_required = REC_UPDATE_REQUIRED; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (REC_TYPE_IS_STAT(r1->rec_type) && (data_raw != nullptr)) { |
| 173 | r1->stat_meta.data_raw = *data_raw; |
| 174 | } else if (REC_TYPE_IS_CONFIG(r1->rec_type)) { |
| 175 | r1->config_meta.source = source; |
| 176 | } |
| 177 | } |
| 178 | rec_mutex_release(&(r1->lock)); |
| 179 | } |
| 180 | } else { |
| 181 | // Add the record but do not set the 'registered' flag, as this |
| 182 | // record really hasn't been registered yet. Also, in order to |
| 183 | // add the record, we need to have a rec_type, so if the user |
| 184 | // calls RecSetRecord on a record we haven't registered yet, we |
| 185 | // should fail out here. |
| 186 | if ((rec_type == RECT_NULL) || (data_type == RECD_NULL)) { |
| 187 | err = REC_ERR_FAIL; |
| 188 | goto Ldone; |
| 189 | } |
| 190 | r1 = RecAlloc(rec_type, name, data_type); |
| 191 | if (r1 == nullptr) { |
| 192 | err = REC_ERR_FAIL; |
| 193 | goto Ldone; |
| 194 | } |
no test coverage detected