MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / syncToStorage

Method syncToStorage

src/meta/UIDMeta.java:174–277  ·  view source on GitHub ↗

Attempts a CompareAndSet storage call, loading the object from storage, synchronizing changes, and attempting a put. Note: If the local object didn't have any fields set by the caller then the data will not be written. @param tsdb The TSDB to use for storage access @param overwrite When the R

(final TSDB tsdb, 
      final boolean overwrite)

Source from the content-addressed store, hash-verified

172 * @throws JSONException if the object could not be serialized
173 */
174 public Deferred<Boolean> syncToStorage(final TSDB tsdb,
175 final boolean overwrite) {
176 if (uid == null || uid.isEmpty()) {
177 throw new IllegalArgumentException("Missing UID");
178 }
179 if (type == null) {
180 throw new IllegalArgumentException("Missing type");
181 }
182
183 boolean has_changes = false;
184 for (Map.Entry<String, Boolean> entry : changed.entrySet()) {
185 if (entry.getValue()) {
186 has_changes = true;
187 break;
188 }
189 }
190 if (!has_changes) {
191 LOG.debug(this + " does not have changes, skipping sync to storage");
192 throw new IllegalStateException("No changes detected in UID meta data");
193 }
194
195 /**
196 * Callback used to verify that the UID to name mapping exists. Uses the TSD
197 * for verification so the name may be cached. If the name does not exist
198 * it will throw a NoSuchUniqueId and the meta data will not be saved to
199 * storage
200 */
201 final class NameCB implements Callback<Deferred<Boolean>, String> {
202 private final UIDMeta local_meta;
203
204 public NameCB(final UIDMeta meta) {
205 local_meta = meta;
206 }
207
208 /**
209 * Nested callback used to merge and store the meta data after verifying
210 * that the UID mapping exists. It has to access the {@code local_meta}
211 * object so that's why it's nested within the NameCB class
212 */
213 final class StoreUIDMeta implements Callback<Deferred<Boolean>,
214 ArrayList<KeyValue>> {
215
216 /**
217 * Executes the CompareAndSet after merging changes
218 * @return True if the CAS was successful, false if the stored data
219 * was modified during flight.
220 */
221 @Override
222 public Deferred<Boolean> call(final ArrayList<KeyValue> row)
223 throws Exception {
224
225 final UIDMeta stored_meta;
226 if (row == null || row.isEmpty()) {
227 stored_meta = null;
228 } else {
229 stored_meta = JSON.parseToObject(row.get(0).value(), UIDMeta.class);
230 stored_meta.initializeChangedMap();
231 }

Callers 2

callMethod · 0.95
handleUIDMetaMethod · 0.95

Calls 4

stringToUidMethod · 0.95
isEmptyMethod · 0.80
getUidNameMethod · 0.80
getValueMethod · 0.45

Tested by

no test coverage detected