mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-28 21:33:51 +00:00
Update size_enforcer.go
This commit is contained in:
parent
21b91ea6e4
commit
1619df2d5e
@ -81,9 +81,6 @@ func checkFileSize(maxSizeBytes int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pruneOldEntries(currentFileSize int64) {
|
func pruneOldEntries(currentFileSize int64) {
|
||||||
IsDBLocked = true
|
|
||||||
defer func() {IsDBLocked = false}()
|
|
||||||
|
|
||||||
amountOfBytesToTrim := currentFileSize / (100 / percentageOfMaxSizeBytesToPrune)
|
amountOfBytesToTrim := currentFileSize / (100 / percentageOfMaxSizeBytesToPrune)
|
||||||
|
|
||||||
rows, err := GetEntriesTable().Limit(10000).Order("id").Rows()
|
rows, err := GetEntriesTable().Limit(10000).Order("id").Rows()
|
||||||
@ -110,6 +107,10 @@ func pruneOldEntries(currentFileSize int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(entryIdsToRemove) > 0 {
|
if len(entryIdsToRemove) > 0 {
|
||||||
|
// sqlite locks the database while delete or VACUUM are running and sqlite is terrible at handling its own db lock while a lot of inserts are attempted, we prevent a significant bottleneck by handling the db lock ourselves here
|
||||||
|
IsDBLocked = true
|
||||||
|
defer func() {IsDBLocked = false}()
|
||||||
|
|
||||||
GetEntriesTable().Where(entryIdsToRemove).Delete(models.MizuEntry{})
|
GetEntriesTable().Where(entryIdsToRemove).Delete(models.MizuEntry{})
|
||||||
// VACUUM causes sqlite to shrink the db file after rows have been deleted, the db file will not shrink without this
|
// VACUUM causes sqlite to shrink the db file after rows have been deleted, the db file will not shrink without this
|
||||||
DB.Exec("VACUUM")
|
DB.Exec("VACUUM")
|
||||||
|
Loading…
Reference in New Issue
Block a user