improved zonedb search, fixed root zone case + basic unit tests #242
Merge request reports
Activity
1563 typedef struct { 1564 const struct conf_t *config; 1564 1565 knot_nameserver_t *ns; 1565 1566 knot_zonedb_t *db_new; 1566 1567 pthread_mutex_t lock; 1567 int inserted; 1568 unsigned qhead; 1569 unsigned qtail; 1570 conf_zone_t *q[]; 1571 1572 }; 1568 } zone_loader_ctx_t; 1573 1569 1574 1570 /*! Thread entrypoint for loading zones. */ 1575 static int zonewalker(dthread_t *thread) 1571 static int zones_loader_thread(dthread_t *thread) 1729 1688 * if the pointers match, remove the zone from old DB 1730 1689 */ 1731 /*! \todo Find better way of removing zone with given pointer.*/ 1732 knot_zone_t *new_zone = (knot_zone_t *)(*hattrie_iter_val(i)); 1733 knot_zone_t *old_zone = knot_zonedb_find_zone( 1734 db_old, knot_zone_name(new_zone)); 1735 if (old_zone == new_zone) { 1736 dbg_zones_exec( 1737 char *name = knot_dname_to_str(knot_zone_name(old_zone)); 1738 dbg_zones_verb("zones: zone pointers match, removing zone %s " 1739 "from database.\n", name); 1740 free(name); 1741 ); 1742 1690 old_zone = knot_zonedb_find_zone(db_old, knot_zone_name(new_zones[i])); 1691 if (old_zone == new_zones[i]) { 65 /* Name with more labels goes first. */ 66 return b_labels - a_labels; 67 } 68 69 /*! \brief Find an equal name in sorted array (binary search). */ 70 #define ZONEDB_LEQ(arr,i,x) (knot_zonedb_cmp(((arr)[i])->name, (x)) <= 0) 71 static long knot_zonedb_binsearch(knot_zone_t **arr, unsigned count, 72 const knot_dname_t *name) 73 { 74 int k = BIN_SEARCH_FIRST_GE_CMP(arr, count, ZONEDB_LEQ, name) - 1; 75 if (k > -1 && knot_dname_is_equal(arr[k]->name, name)) { 76 return k; 77 } 78 79 return -1; 80 35 110 /* API functions */ 36 111 /*----------------------------------------------------------------------------*/ 37 112 38 knot_zonedb_t *knot_zonedb_new() 113 knot_zonedb_t *knot_zonedb_new(unsigned size) 39 114 { 40 knot_zonedb_t *db = 41 (knot_zonedb_t *)malloc(sizeof(knot_zonedb_t)); 115 knot_zonedb_t *db = malloc(sizeof(knot_zonedb_t)); 42 116 CHECK_ALLOC_LOG(db, NULL); 43 117 44 db->zone_tree = hattrie_create(); 45 if (db->zone_tree == NULL) { 118 memset(db, 0, sizeof(knot_zonedb_t)); 119 db->reserved = size; 120 db->array = malloc(size * sizeof(knot_zone_t*));
Please register or sign in to reply