Skip to content

MOD-7795 stop background index when memory is low#4766

Closed
DvirDukhan wants to merge 8 commits intomasterfrom
dvirdu_break_scan_when_low_mem
Closed

MOD-7795 stop background index when memory is low#4766
DvirDukhan wants to merge 8 commits intomasterfrom
dvirdu_break_scan_when_low_mem

Conversation

@DvirDukhan
Copy link

@DvirDukhan DvirDukhan commented Jun 19, 2024

Describe the changes in the pull request

This PR stops background indexing when the memory used is above 80%. The FT.INFO command output will show the memory error as the last indexing error for the index.

Which issues this PR fixes
MOD-7795

  • This PR introduces API changes
  • This PR introduces serialization changes

void IndexSpec_SetIndexErrorMessage(IndexSpec *sp, const char *error, RedisModuleString *key) {
RedisModule_Assert(sp);
RedisModule_Assert(error);
IndexError_AddError(&sp->stats.indexError, error, key);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these assertions temporary? We will get SEGV if sp is not set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sp is not set, we really messed up

src/spec.c Outdated
return;
}

RedisModuleServerInfoData *memory_data = RedisModule_GetServerInfo(ctx, "memory");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use setMemoryInfo and the globals memoryLimit and used_memory instead of reimplementing the info retrieval again

src/spec.c Outdated

RedisModuleServerInfoData *memory_data = RedisModule_GetServerInfo(ctx, "memory");
const char *error = NULL;
if (memory_data) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this possible?

if(scanner->cancelled) {
// We need to report the error message besides the log, so we can show it in FT.INFO
if(scanner->global) {
// Dvirdu: Do we really get here?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think temporary indexes also use the global scanner

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only code path I found using global scanner is for legacy index. @MeirShpilraien thoughts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not legacy indexes, its when we running on Redis version that does not support the load event. I believe this is no longer relevant right?

@github-actions
Copy link

This pull request is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale label Aug 20, 2024
@github-actions github-actions bot removed the stale label Sep 9, 2024
@DvirDukhan DvirDukhan force-pushed the dvirdu_break_scan_when_low_mem branch from a9d92e0 to 9b57b90 Compare September 10, 2024 14:25
@DvirDukhan DvirDukhan marked this pull request as ready for review September 10, 2024 14:25
@DvirDukhan DvirDukhan changed the title WIP - stop background index when memory is low MOD-7795 stop background index when memory is low Sep 10, 2024
@codecov
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.69%. Comparing base (613bc67) to head (c992b77).
Report is 240 commits behind head on master.

Files with missing lines Patch % Lines
src/spec.c 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4766      +/-   ##
==========================================
+ Coverage   86.59%   86.69%   +0.09%     
==========================================
  Files         193      193              
  Lines       34769    34808      +39     
==========================================
+ Hits        30109    30177      +68     
+ Misses       4660     4631      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

const char* error;
// Get the memory limit and memory usage
setMemoryInfo(ctx);
if(used_memory > 0.8 * memoryLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add some search config for that? (default could be 0.8)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legit
@MeirShpilraien thoughts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not canceling it at 100%?

last_indexing_error_key_str: 'doc1',
last_indexing_error_str: 'Used memory is more than 80%% of max memory, cancelling the scan'
}
env.assertEqual(global_index_errors, expected_error_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DvirDukhan We can also make sure the index has no scan in progress now (percent_indexed is 0)

src/spec.c Outdated
StrongRef_Release(curr_run_ref);
} else {
// spec was deleted
RedisModule_Log(ctx, "notice", "Scanning index %s in background: cancelled (index deleted)",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just how GitHub displays this or is the indentation off here?

@github-actions
Copy link

github-actions bot commented Apr 7, 2025

This pull request is stale because it has been open for 60 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants