-
Notifications
You must be signed in to change notification settings - Fork 68
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
feature(api): add refiller index goroutine for search index #907
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d2e1ed5
add refill index goroutine and refactor index
almostinf 455dc95
up refiller run interval
almostinf f15b5f8
add delete subscription function and debug logs
almostinf 7ef3a69
add delete all subscriptions
almostinf a3f4835
commented health notifier prob
almostinf fd7e842
add more logs
almostinf 92d0b46
flash database
almostinf 856b735
returned check on healthy
almostinf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package index | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
const refillerRunInterval = 30 * time.Minute | ||
|
||
// const batchSizeForTest = 50 // TODO: DELETE BEFORE MERGE | ||
|
||
func (index *Index) runIndexRefiller() error { | ||
ticker := time.NewTicker(refillerRunInterval) | ||
defer ticker.Stop() | ||
index.logger.Info(). | ||
Interface("refilling_interval", refillerRunInterval). | ||
Msg("Start refiller for search index") | ||
|
||
for { | ||
select { | ||
case <-index.tomb.Dying(): | ||
index.logger.Info().Msg("Stop refilling search index") | ||
return nil | ||
case <-ticker.C: | ||
index.logger.Info().Msg("Refill search index by timeout") | ||
|
||
start := time.Now() | ||
if err := index.Refill(); err != nil { | ||
index.logger.Warning(). | ||
Error(err). | ||
Msg("Cannot refill index") | ||
continue | ||
} | ||
end := time.Now() | ||
index.logger.Debug(). | ||
Msg(fmt.Sprintf("Refill took %v sec", end.Sub(start).Seconds())) | ||
} | ||
} | ||
} | ||
|
||
// Completely clears the index and then repopulates it, this function is needed to clean up memory leaks that appear when updating or searching the index | ||
func (index *Index) Refill() error { | ||
start := time.Now() | ||
triggerIds, err := index.database.GetAllTriggerIDs() | ||
if err != nil { | ||
return err | ||
} | ||
end := time.Now() | ||
index.logger.Debug(). | ||
Msg(fmt.Sprintf("Fetching all trigger ids from database took %v sec", end.Sub(start).Seconds())) | ||
|
||
index.indexed = false | ||
defer func() { | ||
index.indexed = true | ||
}() | ||
start = time.Now() | ||
if err := index.deleteByBatches(triggerIds, defaultIndexBatchSize); err != nil { | ||
return err | ||
} | ||
end = time.Now() | ||
index.logger.Debug(). | ||
Msg(fmt.Sprintf("Deleting all triggers from index took %v sec", end.Sub(start).Seconds())) | ||
|
||
start = time.Now() | ||
if err := index.fillIndex(); err != nil { | ||
return err | ||
} | ||
end = time.Now() | ||
index.logger.Debug(). | ||
Msg(fmt.Sprintf("Filling all triggers to index took %v sec", end.Sub(start).Seconds())) | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ой