| 70 | } |
| 71 | |
| 72 | static int _fdb_wal_cmp(struct avl_node *a, struct avl_node *b, void *aux) |
| 73 | { |
| 74 | _fdb_key_cmp_info *info = (_fdb_key_cmp_info*)aux; |
| 75 | struct snap_wal_entry *aa, *bb; |
| 76 | aa = _get_entry(a, struct snap_wal_entry, avl); |
| 77 | bb = _get_entry(b, struct snap_wal_entry, avl); |
| 78 | |
| 79 | if (info->kvs_config.custom_cmp) { |
| 80 | // custom compare function for variable-length key |
| 81 | if (info->kvs) { |
| 82 | // multi KV instance mode |
| 83 | // KV ID should be compared separately |
| 84 | size_t size_chunk = info->kvs->root->config.chunksize; |
| 85 | fdb_kvs_id_t a_id, b_id; |
| 86 | buf2kvid(size_chunk, aa->key, &a_id); |
| 87 | buf2kvid(size_chunk, bb->key, &b_id); |
| 88 | |
| 89 | if (a_id < b_id) { |
| 90 | return -1; |
| 91 | } else if (a_id > b_id) { |
| 92 | return 1; |
| 93 | } else { |
| 94 | if (aa->keylen == size_chunk) { // key1 < key2 |
| 95 | return -1; |
| 96 | } else if (bb->keylen == size_chunk) { // key1 > key2 |
| 97 | return 1; |
| 98 | } |
| 99 | return info->kvs_config.custom_cmp( |
| 100 | (uint8_t*)aa->key + size_chunk, |
| 101 | aa->keylen - size_chunk, |
| 102 | (uint8_t*)bb->key + size_chunk, |
| 103 | bb->keylen - size_chunk); |
| 104 | } |
| 105 | } else { |
| 106 | return info->kvs_config.custom_cmp(aa->key, aa->keylen, |
| 107 | bb->key, bb->keylen); |
| 108 | } |
| 109 | } else { |
| 110 | return _fdb_keycmp(aa->key, aa->keylen, bb->key, bb->keylen); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static int _fdb_key_cmp(fdb_iterator *iterator, void *key1, size_t keylen1, |
| 115 | void *key2, size_t keylen2) { |
nothing calls this directly
no test coverage detected