Skip to content

Commit b7d0a38

Browse files
author
DvirDukhan
authored
memceck race handling (#1152)
* removed time.sleep from tests teardown * added async delete config * fixed config and makefile * moved memcheck to compiler flag
1 parent f8bb292 commit b7d0a38

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
command: |
9595
# Replace the default Redis server with one linked to libc malloc rather than jemalloc.
9696
git clone https://github.com/antirez/redis.git; cd redis; git checkout 6.0.1; make valgrind; make install; cd ..
97-
make clean; make DEBUG=1 # Rebuild module at O0
97+
make clean;
9898
make memcheck # Re-run the test suite, failing if definite memory leaks have been introduced.
9999
# Allow RediSearch global destructors.
100100
environment:

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,6 @@ endif
200200
endif
201201
@$(MAKE) -C ../tests test
202202

203+
memcheck: CFLAGS += -fno-omit-frame-pointer -g -ggdb -O0 -D MEMCHECK
203204
memcheck: redisgraph.so
204205
@$(MAKE) -C ../tests memcheck

src/config.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int _Config_SetCacheSize(RedisModuleCtx *ctx, RedisModuleString *cache_si
138138
}
139139

140140
// Initialize every module-level configuration to its default value.
141-
static void _Config_SetToDefaults(void) {
141+
static void _Config_SetToDefaults(RedisModuleCtx *ctx) {
142142
// The thread pool's default size is equal to the system's number of cores.
143143
int CPUCount = sysconf(_SC_NPROCESSORS_ONLN);
144144
config.thread_count = (CPUCount != -1) ? CPUCount : 1;
@@ -154,14 +154,24 @@ static void _Config_SetToDefaults(void) {
154154
config.vkey_entity_count = VKEY_ENTITY_COUNT_UNLIMITED;
155155
}
156156

157+
// MEMCHECK compile flag;
158+
#ifdef MEMCHECK
159+
// Disable async delete during memcheck.
160+
config.async_delete = false;
161+
RedisModule_Log(ctx, "notice", "Graph deletion will be done synchronously.");
162+
#else
163+
// Always perform async delete when no checking for memory issues.
164+
config.async_delete = true;
165+
RedisModule_Log(ctx, "notice", "Graph deletion will be done asynchronously.");
166+
#endif
157167
// Always build transposed matrices by default.
158168
config.maintain_transposed_matrices = true;
159169
config.cache_size = CACHE_SIZE_DEFAULT;
160170
}
161171

162172
int Config_Init(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
163173
// Initialize the configuration to its default values.
164-
_Config_SetToDefaults();
174+
_Config_SetToDefaults(ctx);
165175

166176
if(argc % 2) {
167177
// Emit an error if we received an odd number of arguments, as this indicates an invalid configuration.
@@ -222,3 +232,6 @@ uint64_t Config_GetCacheSize() {
222232
return config.cache_size;
223233
}
224234

235+
bool Config_GetAsyncDelete(void) {
236+
return config.async_delete;
237+
}

src/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
typedef struct {
1414
int thread_count; // Thread count for thread pool.
15+
bool async_delete; // If true, graph deletion is done asynchronously.
1516
uint64_t cache_size; // The cache size for each thread, per graph.
1617
int omp_thread_count; // Maximum number of OpenMP threads.
1718
uint64_t vkey_entity_count; // The limit of number of entities encoded at once for each RDB key.
@@ -37,3 +38,5 @@ bool Config_MaintainTranspose(void);
3738
// Return the cache size.
3839
uint64_t Config_GetCacheSize(void);
3940

41+
// Return true if graph deletion is done asynchronously.
42+
bool Config_GetAsyncDelete(void);

src/graph/graphcontext.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ static inline void _GraphContext_IncreaseRefCount(GraphContext *gc) {
3232

3333
static inline void _GraphContext_DecreaseRefCount(GraphContext *gc) {
3434
// If the reference count is less than 0, the graph has been marked for deletion and no queries are active - free the graph.
35-
if(__atomic_sub_fetch(&gc->ref_count, 1, __ATOMIC_RELAXED) < 0)
36-
thpool_add_work(_thpool, _GraphContext_Free, gc);
35+
if(__atomic_sub_fetch(&gc->ref_count, 1, __ATOMIC_RELAXED) < 0) {
36+
if(Config_GetAsyncDelete()) {
37+
// Async delete
38+
thpool_add_work(_thpool, _GraphContext_Free, gc);
39+
} else {
40+
// Sync delete
41+
_GraphContext_Free(gc);
42+
}
43+
}
3744
}
3845

3946
//------------------------------------------------------------------------------

tests/flow/test_bulk_insertion.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import sys
44
import csv
5-
import time
65
import click
76
from RLTest import Env
87
from click.testing import CliRunner
@@ -28,9 +27,6 @@ def __init__(self):
2827
port = self.env.envRunner.port
2928
redis_graph = Graph("graph", redis_con)
3029

31-
def tearDown(self):
32-
time.sleep(1)
33-
3430
# Run bulk loader script and validate terminal output
3531
def test01_run_script(self):
3632
graphname = "graph"

tests/flow/test_imdb.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import sys
3-
import time
43
from RLTest import Env
54
from redisgraph import Graph
65
from base import FlowTestsBase
@@ -32,7 +31,6 @@ def setUp(self):
3231

3332
def tearDown(self):
3433
self.env.cmd('flushall')
35-
time.sleep(1)
3634

3735
def assert_reversed_pattern(self, query, resultset):
3836
# Test reversed pattern query.

0 commit comments

Comments
 (0)