Skip to content

Commit 7edfb1e

Browse files
committed
Revert "[2.10] [MOD-11011] Fix deadlock while RDB loading and RM_Yield (#6763) (#6785)"
This reverts commit b38f839.
1 parent b38f839 commit 7edfb1e

8 files changed

Lines changed: 21 additions & 189 deletions

File tree

src/debug_commands.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,36 +1595,6 @@ DEBUG_COMMAND(bgScanController) {
15951595

15961596
}
15971597

1598-
// Global variable for sleep time before yielding (in microseconds)
1599-
static unsigned int g_indexerSleepBeforeYieldMicros = 0;
1600-
1601-
unsigned int GetIndexerSleepBeforeYieldMicros(void) {
1602-
return g_indexerSleepBeforeYieldMicros;
1603-
}
1604-
1605-
/**
1606-
* FT.DEBUG INDEXER_SLEEP_BEFORE_YIELD [<microseconds>]
1607-
* Get or set the sleep time in microseconds before yielding during indexing while loading
1608-
*/
1609-
DEBUG_COMMAND(IndexerSleepBeforeYieldMicros) {
1610-
if (argc > 3) {
1611-
return RedisModule_WrongArity(ctx);
1612-
}
1613-
1614-
// Set new sleep time
1615-
if (argc == 3) {
1616-
long long sleepMicros;
1617-
if (RedisModule_StringToLongLong(argv[2], &sleepMicros) != REDISMODULE_OK || sleepMicros < 0) {
1618-
return RedisModule_ReplyWithError(ctx, "Invalid sleep time. Must be a non-negative integer.");
1619-
}
1620-
1621-
g_indexerSleepBeforeYieldMicros = (unsigned int)sleepMicros;
1622-
return RedisModule_ReplyWithSimpleString(ctx, "OK");
1623-
}
1624-
1625-
return RedisModule_WrongArity(ctx);
1626-
}
1627-
16281598
DebugCommandType commands[] = {{"DUMP_INVIDX", DumpInvertedIndex}, // Print all the inverted index entries.
16291599
{"DUMP_NUMIDX", DumpNumericIndex}, // Print all the headers (optional) + entries of the numeric tree.
16301600
{"DUMP_NUMIDXTREE", DumpNumericIndexTree}, // Print tree general info, all leaves + nodes + stats
@@ -1659,7 +1629,6 @@ DebugCommandType commands[] = {{"DUMP_INVIDX", DumpInvertedIndex}, // Print all
16591629
{"GET_HIDE_USER_DATA_FROM_LOGS", getHideUserDataFromLogs},
16601630
{"YIELDS_ON_LOAD_COUNTER", YieldCounter},
16611631
{"BG_SCAN_CONTROLLER", bgScanController},
1662-
{"INDEXER_SLEEP_BEFORE_YIELD_MICROS", IndexerSleepBeforeYieldMicros},
16631632
/**
16641633
* The following commands are for debugging distributed search/aggregation.
16651634
*/

src/debug_commands.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,3 @@ typedef struct DebugCTX {
3838

3939
// Should be called after each debug command that changes the debugCtx
4040
void validateDebugMode(DebugCTX *debugCtx);
41-
42-
// Yield counter functions
43-
void IncrementYieldCounter(void);
44-
45-
// Indexer sleep before yield functions
46-
unsigned int GetIndexerSleepBeforeYieldMicros(void);

src/indexer.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static void writeCurEntries(DocumentIndexer *indexer, RSAddDocumentCtx *aCtx, Re
106106
if (invidx) {
107107
entry->docId = aCtx->doc->docId;
108108
RS_LOG_ASSERT(entry->docId, "docId should not be 0");
109+
IndexerYieldWhileLoading(ctx->redisCtx);
109110
writeIndexEntry(spec, invidx, encoder, entry);
110111
if (Index_StoreFieldMask(spec)) {
111112
invidx->fieldMask |= entry->fieldMask;
@@ -222,6 +223,8 @@ static void indexBulkFields(RSAddDocumentCtx *aCtx, RedisSearchCtx *sctx) {
222223
if (fs->types == INDEXFLD_T_FULLTEXT || !FieldSpec_IsIndexable(fs) || fdata->isNull) {
223224
continue;
224225
}
226+
227+
IndexerYieldWhileLoading(sctx->redisCtx);
225228
if (IndexerBulkAdd(cur, sctx, doc->fields + ii, fs, fdata, &cur->status) != 0) {
226229
IndexError_AddError(&cur->spec->stats.indexError, cur->status.message, cur->status.detail, doc->docKey);
227230
FieldSpec_AddError(&cur->spec->fields[fs->index], cur->status.message, cur->status.detail, doc->docKey);
@@ -396,21 +399,14 @@ bool g_isLoading = false;
396399
* Yield to Redis after a certain number of operations during indexing.
397400
* This helps keep Redis responsive during long indexing operations.
398401
* @param ctx The Redis context
399-
* @param numOps Tue number of operations to count in the counter before considering RSGlobalConfig.indexerYieldEveryOpsWhileLoading. These are related to the number of fields in the document
400-
* @param flags The flags to pass to RedisModule_Yield
401402
*/
402-
void IndexerYieldWhileLoading(RedisModuleCtx *ctx, unsigned int numOps, int flags) {
403+
static void IndexerYieldWhileLoading(RedisModuleCtx *ctx) {
403404
static size_t opCounter = 0;
404405

405-
// If server is loading, Yield to Redis if the number of operations is greater than the yieldEveryOps
406-
opCounter += numOps;
407-
if (g_isLoading && opCounter >= RSGlobalConfig.indexerYieldEveryOpsWhileLoading) {
408-
opCounter = opCounter % RSGlobalConfig.indexerYieldEveryOpsWhileLoading;
406+
// If server is loading, Yield to Redis every RSGlobalConfig.indexerYieldEveryOps operations
407+
if (g_isLoading && ++opCounter >= RSGlobalConfig.indexerYieldEveryOpsWhileLoading) {
408+
opCounter = 0;
409409
IncrementYieldCounter(); // Track that we called yield
410-
unsigned int sleepMicros = GetIndexerSleepBeforeYieldMicros();
411-
if (sleepMicros > 0) {
412-
usleep(sleepMicros);
413-
}
414-
RedisModule_Yield(ctx, flags, NULL);
410+
RedisModule_Yield(ctx, REDISMODULE_YIELD_FLAG_CLIENTS, NULL);
415411
}
416412
}

src/indexer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ int IndexerBulkAdd(RSAddDocumentCtx *cur, RedisSearchCtx *sctx,
8888
* Yield to Redis after a certain number of operations during indexing while loading.
8989
* This helps keep Redis responsive during long indexing operations.
9090
* @param ctx The Redis context
91-
* @param numOps Tue number of operations to count in the counter before considering RSGlobalConfig.indexerYieldEveryOpsWhileLoading. These are related to the number of fields in the document
92-
* @param flags The flags to pass to RedisModule_Yield
9391
*/
94-
void IndexerYieldWhileLoading(RedisModuleCtx *ctx, unsigned int numOps, int flags);
92+
static void IndexerYieldWhileLoading(RedisModuleCtx *ctx);
9593

9694
#endif

src/info/indexes_info.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "indexes_info.h"
88
#include "util/dict.h"
99
#include "spec.h"
10-
#include <string.h> // Add this for strerror
1110

1211
// Assuming the GIL is held by the caller
1312
TotalIndexesInfo IndexesInfo_TotalInfo() {
@@ -28,11 +27,7 @@ TotalIndexesInfo IndexesInfo_TotalInfo() {
2827
continue;
2928
}
3029
// Lock for read
31-
int rc = pthread_rwlock_rdlock(&sp->rwlock);
32-
if (rc != 0) {
33-
RedisModule_Log(RSDummyContext, "warning", "Failed to acquire read lock on index: rc=%d (%s). Cannot continue getting Index info", rc, strerror(rc));
34-
continue;
35-
}
30+
pthread_rwlock_rdlock(&sp->rwlock);
3631

3732
// Vector index stats
3833
VectorIndexStats vec_info = IndexSpec_GetVectorIndexStats(sp);

src/spec.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,21 +1812,6 @@ void IndexSpec_InitializeSynonym(IndexSpec *sp) {
18121812

18131813
///////////////////////////////////////////////////////////////////////////////////////////////
18141814

1815-
static void IndexSpec_InitLock(IndexSpec *sp) {
1816-
int res = 0;
1817-
pthread_rwlockattr_t attr;
1818-
res = pthread_rwlockattr_init(&attr);
1819-
RS_ASSERT(res == 0);
1820-
#if !defined(__APPLE__) && !defined(__FreeBSD__) && defined(__GLIBC__)
1821-
int pref = PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP;
1822-
res = pthread_rwlockattr_setkind_np(&attr, pref);
1823-
RS_ASSERT(res == 0);
1824-
#endif
1825-
1826-
pthread_rwlock_init(&sp->rwlock, &attr);
1827-
}
1828-
1829-
18301815
IndexSpec *NewIndexSpec(const char *name) {
18311816
IndexSpec *sp = rm_calloc(1, sizeof(IndexSpec));
18321817
sp->fields = rm_calloc(sizeof(FieldSpec), SPEC_MAX_FIELDS);
@@ -1854,7 +1839,17 @@ IndexSpec *NewIndexSpec(const char *name) {
18541839
memset(&sp->stats, 0, sizeof(sp->stats));
18551840
sp->stats.indexError = IndexError_Init();
18561841

1857-
IndexSpec_InitLock(sp);
1842+
int res = 0;
1843+
pthread_rwlockattr_t attr;
1844+
res = pthread_rwlockattr_init(&attr);
1845+
RS_ASSERT(res == 0);
1846+
#if !defined(__APPLE__) && !defined(__FreeBSD__)
1847+
int pref = PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP;
1848+
res = pthread_rwlockattr_setkind_np(&attr, pref);
1849+
RS_ASSERT(res == 0);
1850+
#endif
1851+
1852+
pthread_rwlock_init(&sp->rwlock, &attr);
18581853

18591854
return sp;
18601855
}
@@ -2659,7 +2654,6 @@ int IndexSpec_CreateFromRdb(RedisModuleCtx *ctx, RedisModuleIO *rdb, int encver,
26592654
RedisModule_Free(rawName);
26602655

26612656
IndexSpec *sp = rm_calloc(1, sizeof(IndexSpec));
2662-
IndexSpec_InitLock(sp);
26632657
StrongRef spec_ref = StrongRef_New(sp, (RefManager_Free)IndexSpec_Free);
26642658
sp->own_ref = spec_ref;
26652659
// setting isDuplicate to true will make sure index will not be removed from aliases container.
@@ -2792,7 +2786,6 @@ void *IndexSpec_LegacyRdbLoad(RedisModuleIO *rdb, int encver) {
27922786

27932787
RedisModuleCtx *ctx = RedisModule_GetContextFromIO(rdb);
27942788
IndexSpec *sp = rm_calloc(1, sizeof(IndexSpec));
2795-
IndexSpec_InitLock(sp);
27962789
StrongRef spec_ref = StrongRef_New(sp, (RefManager_Free)IndexSpec_Free);
27972790
sp->own_ref = spec_ref;
27982791

@@ -2890,7 +2883,6 @@ void *IndexSpec_LegacyRdbLoad(RedisModuleIO *rdb, int encver) {
28902883
Cursors_initSpec(sp);
28912884

28922885
dictAdd(legacySpecDict, sp->name, spec_ref.rm);
2893-
28942886
return spec_ref.rm;
28952887
}
28962888

@@ -3119,8 +3111,6 @@ int IndexSpec_UpdateDoc(IndexSpec *spec, RedisModuleCtx *ctx, RedisModuleString
31193111
return REDISMODULE_ERR;
31203112
}
31213113

3122-
unsigned int numOps = doc.numFields != 0 ? doc.numFields: 1;
3123-
IndexerYieldWhileLoading(ctx, numOps, REDISMODULE_YIELD_FLAG_CLIENTS);
31243114
RedisSearchCtx_LockSpecWrite(&sctx);
31253115
IndexSpec_IncrActiveWrites(spec);
31263116

tests/pytests/test_debug_commands.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def testDebugHelp(self):
5757
'GET_HIDE_USER_DATA_FROM_LOGS',
5858
'YIELDS_ON_LOAD_COUNTER',
5959
'BG_SCAN_CONTROLLER',
60-
'INDEXER_SLEEP_BEFORE_YIELD_MICROS',
6160
'FT.AGGREGATE',
6261
'FT.SEARCH',
6362
]

tests/pytests/test_rdb_load.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)