Skip to content

Commit

Permalink
EC: add indexes to some columns
Browse files Browse the repository at this point in the history
CMK-16740

Indexes are base on gui DataSourceECEventHistory

Change-Id: I47f84391bb46b6cd3f6eb04a5e9e4e74e59f8747
  • Loading branch information
Konstantin Baikov authored and thl-cmk committed Apr 5, 2024
1 parent b59fec7 commit 1ba9ca5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmk/ec/history_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,22 @@
"match_groups_syslog_application",
)

INDEXED_COLUMNS: Final = (
"time",
"id",
"host",
)

SQLITE_PRAGMAS = {
"PRAGMA journal_mode=WAL;": "WAL mode for concurrent reads and writes",
"PRAGMA synchronous = NORMAL;": "Writes should not blocked by reads",
"PRAGMA busy_timeout = 2000;": "2 seconds timeout for busy handler. Avoids database is locked errors",
}

SQLITE_INDEXES = [
f"CREATE INDEX IF NOT EXISTS idx_{column} ON history ({column});" for column in INDEXED_COLUMNS
]


def configure_sqlite_types() -> None:
"""
Expand Down Expand Up @@ -201,10 +211,13 @@ def __init__(
orig_host TEXT,
contact_groups_precedence TEXT,
core_host TEXT,
host_in_downtime BOOL,
host_in_downtime BOOL,
match_groups_syslog_application JSON
);"""
)
with self.conn as connection:
for index_statement in SQLITE_INDEXES:
connection.execute(index_statement)

def flush(self) -> None:
"""Drop the history table."""
Expand Down

0 comments on commit 1ba9ca5

Please sign in to comment.