mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Truncate write ahead log if it gets too big (#10866)
* Truncate write ahead log if it gets too big * formatting * Reduce size
This commit is contained in:
parent
12e6e43d6c
commit
f6ff1c84b8
@ -39,6 +39,10 @@ AUDIO_MAX_BIT_RANGE = 32768.0
|
|||||||
AUDIO_SAMPLE_RATE = 16000
|
AUDIO_SAMPLE_RATE = 16000
|
||||||
AUDIO_MIN_CONFIDENCE = 0.5
|
AUDIO_MIN_CONFIDENCE = 0.5
|
||||||
|
|
||||||
|
# DB Consts
|
||||||
|
|
||||||
|
MAX_WAL_SIZE = 10 # MB
|
||||||
|
|
||||||
# Ffmpeg Presets
|
# Ffmpeg Presets
|
||||||
|
|
||||||
FFMPEG_HWACCEL_NVIDIA = "preset-nvidia"
|
FFMPEG_HWACCEL_NVIDIA = "preset-nvidia"
|
||||||
|
@ -3,12 +3,15 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import threading
|
import threading
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
from multiprocessing.synchronize import Event as MpEvent
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
|
|
||||||
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
||||||
from frigate.const import CACHE_DIR, RECORD_DIR
|
from frigate.const import CACHE_DIR, MAX_WAL_SIZE, RECORD_DIR
|
||||||
from frigate.models import Event, Previews, Recordings, ReviewSegment
|
from frigate.models import Event, Previews, Recordings, ReviewSegment
|
||||||
from frigate.record.util import remove_empty_directories, sync_recordings
|
from frigate.record.util import remove_empty_directories, sync_recordings
|
||||||
from frigate.util.builtin import clear_and_unlink, get_tomorrow_at_time
|
from frigate.util.builtin import clear_and_unlink, get_tomorrow_at_time
|
||||||
@ -33,6 +36,23 @@ class RecordingCleanup(threading.Thread):
|
|||||||
logger.debug("Deleting tmp clip.")
|
logger.debug("Deleting tmp clip.")
|
||||||
clear_and_unlink(p)
|
clear_and_unlink(p)
|
||||||
|
|
||||||
|
def truncate_wal(self) -> None:
|
||||||
|
"""check if the WAL needs to be manually truncated."""
|
||||||
|
|
||||||
|
# by default the WAL should be check-pointed automatically
|
||||||
|
# however, high levels of activity can prevent an opportunity
|
||||||
|
# for the checkpoint to be finished which means the WAL will grow
|
||||||
|
# without bound
|
||||||
|
|
||||||
|
# with auto checkpoint most users should never hit this
|
||||||
|
|
||||||
|
if (
|
||||||
|
os.stat(f"{self.config.database.path}-wal").st_size / (1024 * 1024)
|
||||||
|
) > MAX_WAL_SIZE:
|
||||||
|
db = SqliteExtDatabase(self.config.database.path)
|
||||||
|
db.execute_sql("PRAGMA wal_checkpoint(TRUNCATE);")
|
||||||
|
db.close()
|
||||||
|
|
||||||
def expire_existing_camera_recordings(
|
def expire_existing_camera_recordings(
|
||||||
self, expire_date: float, config: CameraConfig, events: Event
|
self, expire_date: float, config: CameraConfig, events: Event
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -328,3 +348,4 @@ class RecordingCleanup(threading.Thread):
|
|||||||
if counter == 0:
|
if counter == 0:
|
||||||
self.expire_recordings()
|
self.expire_recordings()
|
||||||
remove_empty_directories(RECORD_DIR)
|
remove_empty_directories(RECORD_DIR)
|
||||||
|
self.truncate_wal()
|
||||||
|
Loading…
Reference in New Issue
Block a user