void dump_record(const as_record* p_rec) { if (! p_rec) { info(" null as_record object"); return; } if (p_rec->key.valuep) { char* key_val_as_str = as_val_tostring(p_rec->key.valuep); info(" key: %s", key_val_as_str); free(key_val_as_str); } uint16_t num_bins = as_record_numbins(p_rec); info(" generation %u, ttl %u, %u bin%s", p_rec->gen, p_rec->ttl, num_bins, num_bins == 0 ? "s" : (num_bins == 1 ? ":" : "s:")); as_record_iterator it; as_record_iterator_init(&it, p_rec); while (as_record_iterator_has_next(&it)) { dump_bin(as_record_iterator_next(&it)); } as_record_iterator_destroy(&it); }
static void as_get_callback1(as_error* err, as_record* rec, void* udata, as_event_loop* event_loop) { assert_success_async(&monitor, err, udata); assert_int_eq_async(&monitor, as_record_numbins(rec), 1); assert_int_eq_async(&monitor, as_record_get_int64(rec, "a", 0), 123); as_monitor_notify(&monitor); }
void example_dump_record(const as_record* p_rec) { if (! p_rec) { LOG(" null as_record object"); return; } uint16_t num_bins = as_record_numbins(p_rec); LOG(" generation %u, ttl %u, %u bin%s:", p_rec->gen, p_rec->ttl, num_bins, num_bins == 1 ? "" : "s"); as_record_iterator it; as_record_iterator_init(&it, p_rec); while (as_record_iterator_has_next(&it)) { example_dump_bin(as_record_iterator_next(&it)); } as_record_iterator_destroy(&it); }
static uint16_t as_record_rec_numbins(const as_rec * r) { return r ? as_record_numbins((as_record *) r) : 0; }
static bool scan_check_callback(const as_val * val, void * udata) { int i; // NULL is END OF SCAN if ( !val ) { return false; } scan_check * check = (scan_check *) udata; as_record * rec = as_record_fromval(val); if ( !rec ) { error("Expected a record, but got type %d", as_val_type(val)); return !(check->failed = true); } const char * set = rec->key.set[0] == '\0' ? NULL : rec->key.set; check->count++; // Find the number of unique threads spawned under the hood. // Note that the scan callback will be called in the thread context. // As the number of threads is same as node count, they will be limited. // A linear search is good enough for this. pthread_t cur_thread = pthread_self(); for (i=0; i<check->unique_tcount; i++) { if (check->threadids[i] == cur_thread) { break; } } // Found a new thread if (i == check->unique_tcount) { check->threadids[check->unique_tcount] = cur_thread; check->unique_tcount++; } // Check if we are getting the results only from the set the scan is triggered for // If scan is called with NULL set, all the recs will come. So, no checks in this case. if ( check->set ) { // Do the check only if the rec also have a setname if ( !set ) { error("Expected set '%s', but got set NULL", check->set); return !(check->failed = true); } else if ( strcmp(check->set, set) != 0) { error("Expected set '%s', but got set '%s'", check->set, set); return !(check->failed = true); } } // Check that we got the right number of bins int numbins = as_record_numbins(rec); if ( check->nobindata ) { if ( numbins != 0 ) { error("Expected 0 bins, but got %d", numbins); return !(check->failed = true); } return !(check->failed = false); } // only validate data if in sb_set1 or sb_set2 if ( check->set && strcmp(set, SET1) != 0 && strcmp(set, SET2) != 0 ) { return !(check->failed = false); } // validate bins int nbins = sizeof(check->bins) / sizeof(char *); for( int i = 0; check->bins[i] && i < nbins; i++ ) { char * bin = check->bins[i]; if ( strcmp(bin, "bin1") == 0 ) { if ( !check_bin1(rec, check) ) { error("Failed check of bin1"); return !(check->failed = true); } } else if ( strcmp(bin, "bin2") == 0 ) { if ( !check_bin2(rec, check) ) { error("Failed check of bin2"); return !(check->failed = true); } } else if ( strcmp(bin, "bin3") == 0 ) { if ( !check_bin3(rec, check) ) { error("Failed check of bin3"); return !(check->failed = true); } } else if ( strcmp(bin, "bin4") == 0 ) { if ( !check_bin4(rec, check) ) { error("Failed check of bin4"); return !(check->failed = true); } } else { error("Unknown bin %s", bin); return !(check->failed = true); } } return !(check->failed = false); }