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

Function RecSetRecord

src/records/P_RecCore.cc:137–214  ·  view source on GitHub ↗

------------------------------------------------------------------------- RecSetRecordXXX -------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

135// RecSetRecordXXX
136//-------------------------------------------------------------------------
137RecErrT
138RecSetRecord(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 }

Callers 7

SetRecordFromYAMLNodeFunction · 0.85
RecSetRecordIntFunction · 0.85
RecSetRecordFloatFunction · 0.85
RecSetRecordStringFunction · 0.85
RecSetRecordCounterFunction · 0.85
RecReadStatsFileFunction · 0.85
RecConsumeConfigEntryFunction · 0.85

Calls 11

ink_rwlock_wrlockFunction · 0.85
i_am_the_record_ownerFunction · 0.85
rec_mutex_acquireFunction · 0.85
RecDataSetFromStringFunction · 0.85
RecDataSetFunction · 0.85
rec_mutex_releaseFunction · 0.85
RecAllocFunction · 0.85
ink_rwlock_unlockFunction · 0.85
emplaceMethod · 0.80
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected