• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4948

04 Feb 2026 09:05AM UTC coverage: 66.866% (-0.006%) from 66.872%
#4948

push

travis-ci

web-flow
enh(keeper): password information desensitization processing (#34458)

Close https://project.feishu.cn/taosdata_td/feature/detail/6600039687

Commits:

* feat: add String method to TDengineRestful for safe string representation

* feat: replace hardcoded credentials with test utility functions in tests

* feat: update test workflows to use environment variables for credentials

* test: fix failed test case

* chore: setup tmate

* feat: streamline test execution by setting environment variables for credentials

* feat: enhance test utility functions to return default values if environment variables are not set

205522 of 307364 relevant lines covered (66.87%)

124991068.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/source/dnode/vnode/src/vnd/vnodeHash.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "vnodeHash.h"
17

18
#define VNODE_HASH_DEFAULT_NUM_BUCKETS 1024
19

20
typedef struct SVHashEntry SVHashEntry;
21

22
struct SVHashEntry {
23
  SVHashEntry* next;
24
  void*        obj;
25
};
26

27
static void vHashRehash(SVHashTable* ht, uint32_t newNumBuckets) {
14,152✔
28
  SVHashEntry** newBuckets = (SVHashEntry**)taosMemoryCalloc(newNumBuckets, sizeof(SVHashEntry*));
14,152✔
29
  if (newBuckets == NULL) {
14,152✔
30
    return;
×
31
  }
32

33
  for (int32_t i = 0; i < ht->numBuckets; i++) {
21,751,624✔
34
    SVHashEntry* entry = ht->buckets[i];
21,737,472✔
35
    while (entry != NULL) {
32,599,132✔
36
      SVHashEntry* next = entry->next;
10,861,660✔
37
      uint32_t     bucketIndex = ht->hash(entry->obj) % newNumBuckets;
10,861,660✔
38
      entry->next = newBuckets[bucketIndex];
10,861,660✔
39
      newBuckets[bucketIndex] = entry;
10,861,660✔
40
      entry = next;
10,861,660✔
41
    }
42
  }
43

44
  taosMemoryFree(ht->buckets);
14,152✔
45
  ht->buckets = newBuckets;
14,152✔
46
  ht->numBuckets = newNumBuckets;
14,152✔
47

48
  return;
14,152✔
49
}
50

51
int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*)) {
8,302,323✔
52
  if (ht == NULL || hash == NULL || compare == NULL) {
8,302,323✔
53
    return TSDB_CODE_INVALID_PARA;
×
54
  }
55

56
  (*ht) = (SVHashTable*)taosMemoryMalloc(sizeof(SVHashTable));
8,302,561✔
57
  if (*ht == NULL) {
8,302,561✔
58
    return terrno;
×
59
  }
60

61
  (*ht)->hash = hash;
8,302,323✔
62
  (*ht)->compare = compare;
8,302,561✔
63
  (*ht)->numEntries = 0;
8,302,323✔
64
  (*ht)->numBuckets = VNODE_HASH_DEFAULT_NUM_BUCKETS;
8,302,323✔
65
  (*ht)->buckets = (SVHashEntry**)taosMemoryCalloc((*ht)->numBuckets, sizeof(SVHashEntry*));
8,302,323✔
66
  if ((*ht)->buckets == NULL) {
8,302,561✔
67
    taosMemoryFree(*ht);
×
68
    return terrno;
×
69
  }
70

71
  return 0;
8,302,561✔
72
}
73

74
void vHashDestroy(SVHashTable** ht) {
8,302,561✔
75
  if (ht == NULL) {
8,302,561✔
76
    return;
×
77
  }
78

79
  if (*ht) {
8,302,561✔
80
    taosMemoryFree((*ht)->buckets);
8,302,561✔
81
    taosMemoryFree(*ht);
8,302,561✔
82
    (*ht) = NULL;
8,302,561✔
83
  }
84
}
85

86
int32_t vHashPut(SVHashTable* ht, void* obj) {
22,385,114✔
87
  if (ht == NULL || obj == NULL) {
22,385,114✔
88
    return TSDB_CODE_INVALID_PARA;
×
89
  }
90

91
  uint32_t bucketIndex = ht->hash(obj) % ht->numBuckets;
22,385,728✔
92
  for (SVHashEntry* entry = ht->buckets[bucketIndex]; entry != NULL; entry = entry->next) {
29,124,711✔
93
    if (ht->compare(entry->obj, obj) == 0) {
6,737,759✔
94
      return TSDB_CODE_DUP_KEY;
×
95
    }
96
  }
97

98
  if (ht->numEntries >= ht->numBuckets) {
22,386,533✔
99
    vHashRehash(ht, ht->numBuckets * 2);
7,076✔
100
    bucketIndex = ht->hash(obj) % ht->numBuckets;
7,076✔
101
  }
102

103
  SVHashEntry* entry = (SVHashEntry*)taosMemoryMalloc(sizeof(SVHashEntry));
22,386,014✔
104
  if (entry == NULL) {
22,386,590✔
105
    return terrno;
×
106
  }
107
  entry->obj = obj;
22,386,590✔
108
  entry->next = ht->buckets[bucketIndex];
22,386,352✔
109
  ht->buckets[bucketIndex] = entry;
22,386,214✔
110
  ht->numEntries++;
22,385,978✔
111

112
  return 0;
22,385,740✔
113
}
114

115
int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj) {
97,806,545✔
116
  if (ht == NULL || obj == NULL || retObj == NULL) {
97,806,545✔
117
    return TSDB_CODE_INVALID_PARA;
×
118
  }
119

120
  uint32_t bucketIndex = ht->hash(obj) % ht->numBuckets;
97,834,238✔
121
  for (SVHashEntry* entry = ht->buckets[bucketIndex]; entry != NULL; entry = entry->next) {
111,890,883✔
122
    if (ht->compare(entry->obj, obj) == 0) {
90,091,638✔
123
      *retObj = entry->obj;
76,022,555✔
124
      return 0;
76,017,784✔
125
    }
126
  }
127

128
  *retObj = NULL;
21,798,083✔
129
  return TSDB_CODE_NOT_FOUND;
21,797,463✔
130
}
131

132
int32_t vHashDrop(SVHashTable* ht, const void* obj) {
22,386,771✔
133
  if (ht == NULL || obj == NULL) {
22,386,771✔
134
    return TSDB_CODE_INVALID_PARA;
×
135
  }
136

137
  uint32_t bucketIndex = ht->hash(obj) % ht->numBuckets;
22,386,771✔
138
  for (SVHashEntry** entry = &ht->buckets[bucketIndex]; *entry != NULL; entry = &(*entry)->next) {
25,236,959✔
139
    if (ht->compare((*entry)->obj, obj) == 0) {
25,236,959✔
140
      SVHashEntry* tmp = *entry;
22,386,771✔
141
      *entry = (*entry)->next;
22,386,771✔
142
      taosMemoryFree(tmp);
22,386,771✔
143
      ht->numEntries--;
22,386,771✔
144
      if (ht->numBuckets > VNODE_HASH_DEFAULT_NUM_BUCKETS && ht->numEntries < ht->numBuckets / 4) {
22,386,771✔
145
        vHashRehash(ht, ht->numBuckets / 2);
7,076✔
146
      }
147
      return 0;
22,386,771✔
148
    }
149
  }
150

151
  return TSDB_CODE_NOT_FOUND;
×
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc