Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel activedefrag in case we empty db #1411

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ long long emptyData(int dbnum, int flags, void(callback)(dict *)) {
return -1;
}

/* In case we are in the process of activedefrag, the db keys and expire might be in the stage of defrag.
* we thus cancel the active defrag so that it will be restarted from the beginning. */
cancelActiveDefrag();

/* Fire the flushdb modules event. */
moduleFireServerEvent(VALKEYMODULE_EVENT_FLUSHDB, VALKEYMODULE_SUBEVENT_FLUSHDB_START, &fi);

Expand Down
10 changes: 10 additions & 0 deletions src/defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,12 @@ static void updateDefragCpuPercent(void) {
}
}

void cancelActiveDefrag(void) {
if (defragIsRunning()) {
// Defrag is requested to stop while running
endDefragCycle(false);
}
}

void monitorActiveDefrag(void) {
if (!server.active_defrag_enabled) return;
Expand All @@ -1382,6 +1388,10 @@ void monitorActiveDefrag(void) {

#else /* HAVE_DEFRAG */

void cancelActiveDefrag(void) {
/* Not implemented yet. */
}

void monitorActiveDefrag(void) {
/* Not implemented yet. */
}
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,7 @@ void enterExecutionUnit(int update_cached_time, long long us);
void exitExecutionUnit(void);
void resetServerStats(void);
void monitorActiveDefrag(void);
void cancelActiveDefrag(void);
void defragWhileBlocked(void);
unsigned int getLRUClock(void);
unsigned int LRU_CLOCK(void);
Expand Down
Loading