|
| 1 | +import os |
| 2 | +import pytest |
| 3 | +import multiprocessing |
| 4 | +import time |
| 5 | +from common import * |
| 6 | +from RLTest import Env |
| 7 | + |
| 8 | + |
| 9 | +def downloadFiles(rdbs): |
| 10 | + os.makedirs(REDISEARCH_CACHE_DIR, exist_ok=True) # create cache dir if not exists |
| 11 | + for f in rdbs: |
| 12 | + path = os.path.join(REDISEARCH_CACHE_DIR, f) |
| 13 | + if not os.path.exists(path): |
| 14 | + subprocess.run(["wget", "--no-check-certificate", BASE_RDBS_URL + f, "-O", path, "-q"]) |
| 15 | + if not os.path.exists(path): |
| 16 | + return False |
| 17 | + return True |
| 18 | + |
| 19 | + |
| 20 | +@skip(cluster=True) |
| 21 | +@pytest.mark.timeout(120) |
| 22 | +def test_rdb_load_no_deadlock(): |
| 23 | + """ |
| 24 | + Test that loading from RDB while constantly sending INFO commands doesn't cause deadlock. |
| 25 | + This test starts a clean Redis server, then triggers RDB loading from the client side |
| 26 | + while some subprocesses keep sending INFO commands. |
| 27 | + """ |
| 28 | + # Download the RDB file using downloadFile function |
| 29 | + rdb_filename = 'redisearch_2.6.9_with_vecsim.rdb' |
| 30 | + |
| 31 | + # Create a clean Redis environment |
| 32 | + test_env = Env(moduleArgs='') |
| 33 | + |
| 34 | + # Start the server first |
| 35 | + test_env.start() |
| 36 | + |
| 37 | + # Verify server is running |
| 38 | + test_env.expect('PING').equal(True) |
| 39 | + |
| 40 | + # Download the RDB file |
| 41 | + if not downloadFiles([rdb_filename]): |
| 42 | + test_env.assertTrue(False, message=f'Failed to download RDB file: {rdb_filename}') |
| 43 | + return |
| 44 | + |
| 45 | + # Configure indexer to yield more frequently during loading to increase chance of deadlock |
| 46 | + test_env.cmd(config_cmd(), 'SET', 'INDEXER_YIELD_EVERY_OPS', '1') |
| 47 | + test_env.expect(debug_cmd(), 'INDEXER_SLEEP_BEFORE_YIELD_MICROS', '50000').ok() |
| 48 | + |
| 49 | + # Get Redis configuration for RDB file location |
| 50 | + dbFileName = test_env.cmd('config', 'get', 'dbfilename')[1] |
| 51 | + dbDir = test_env.cmd('config', 'get', 'dir')[1] |
| 52 | + rdbFilePath = os.path.join(dbDir, dbFileName) |
| 53 | + |
| 54 | + # Get the downloaded RDB file path |
| 55 | + filePath = os.path.join(REDISEARCH_CACHE_DIR, rdb_filename) |
| 56 | + |
| 57 | + # Create symlink to the downloaded RDB file |
| 58 | + try: |
| 59 | + os.unlink(rdbFilePath) |
| 60 | + except OSError: |
| 61 | + pass |
| 62 | + os.symlink(filePath, rdbFilePath) |
| 63 | + |
| 64 | + # Give the system time to process the symlink |
| 65 | + time.sleep(1) |
| 66 | + |
| 67 | + def info_command_process(port): |
| 68 | + """Process that continuously sends INFO commands""" |
| 69 | + import redis |
| 70 | + |
| 71 | + # Create a new connection in this process |
| 72 | + conn = redis.Redis(host='localhost', port=port, decode_responses=True) |
| 73 | + |
| 74 | + while True: |
| 75 | + try: |
| 76 | + result = conn.execute_command('INFO', 'everything') |
| 77 | + except Exception as e: |
| 78 | + continue |
| 79 | + |
| 80 | + # Start the INFO command thread |
| 81 | + redis_port = test_env.getConnection().connection_pool.connection_kwargs['port'] |
| 82 | + info_processes = [] |
| 83 | + |
| 84 | + for i in range(20): |
| 85 | + process = multiprocessing.Process( |
| 86 | + target=info_command_process, |
| 87 | + args=(redis_port,), |
| 88 | + daemon=True |
| 89 | + ) |
| 90 | + process.start() |
| 91 | + info_processes.append(process) |
| 92 | + |
| 93 | + # Get current database size before reload |
| 94 | + # Trigger the reload - use NOSAVE to prevent overwriting our RDB file |
| 95 | + test_env.cmd('DEBUG', 'RELOAD', 'NOSAVE') |
| 96 | + for process in info_processes: |
| 97 | + process.terminate() |
| 98 | + process.join() |
| 99 | + |
| 100 | + test_env.expect('PING').equal(True) |
| 101 | + |
| 102 | + # Check database size to see if anything was loaded |
| 103 | + dbsize = test_env.cmd('DBSIZE') |
| 104 | + |
| 105 | + # Try to get info about any existing indices |
| 106 | + indices_info = test_env.cmd('FT._LIST') |
| 107 | + assert indices_info, "No indices found after RDB load" |
| 108 | + # If there are indices, verify we can get info about the first one |
| 109 | + test_env.expect('FT.INFO', indices_info[0]).noError() |
0 commit comments