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

Duplicate Key Violation Error in files_meta_path_key Causing Package Lock in Latest Dev Version #794

Open
madman2012 opened this issue Aug 9, 2024 · 13 comments

Comments

@madman2012
Copy link

On latest dev, I am getting the following error:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:52.020 EDT [1142] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:52.020 EDT [1142] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:52.020 EDT [1142] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:52] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 167 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:53.014 EDT [1146] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:53.014 EDT [1146] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:53.014 EDT [1146] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:53] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 168 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:54.081 EDT [3302] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:54.081 EDT [3302] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:54.081 EDT [3302] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:54] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 169 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:55.013 EDT [1110] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:55.013 EDT [1110] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:55.013 EDT [1110] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:55] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 170 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:56.017 EDT [1110] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:56.017 EDT [1110] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:56.017 EDT [1110] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:56] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 171 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:57.012 EDT [3302] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:57.012 EDT [3302] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:57.012 EDT [3302] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:57] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 172 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:58.020 EDT [1110] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:58.020 EDT [1110] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:58.020 EDT [1110] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:58] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 173 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:23:59.020 EDT [1110] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:23:59.020 EDT [1110] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:23:59.020 EDT [1110] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:23:59] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 174 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:24:00.012 EDT [1110] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:24:00.012 EDT [1110] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:24:00.012 EDT [1110] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:24:00] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 175 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:24:01.013 EDT [1146] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:24:01.013 EDT [1146] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:24:01.013 EDT [1146] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:24:01] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 176 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:24:02.016 EDT [1146] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:24:02.016 EDT [1146] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:24:02.016 EDT [1146] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:24:02] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 177 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:24:03.085 EDT [1146] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:24:03.085 EDT [1146] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:24:03.085 EDT [1146] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:24:03] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 178 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2024-08-08 20:24:04.017 EDT [1146] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-08 20:24:04.017 EDT [1146] DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.
2024-08-08 20:24:04.017 EDT [1146] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/front_door/segmen
[2024-08-08 20:24:04] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723162858.m4s, message repeated 179 times
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 276, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 222, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/front_door/segments/front_door/1723162858.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/front_door/segments/front_door/1723162858.m4s', 'orig_ctime': datetime.datetime(2024, 8, 9, 0, 20, 58), 'meta': '{"m3u8": {"EXTINF": 5.4895}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)

here is my config:
ffmpeg:
global:
hwaccel_args: -hwaccel nvdec -c:v hevc_cuvid -c:v h264_cuvid -c:v hevc_nvenc -c:v h264_nvenc
camera:
front_door:
name: Front Door
host: 10.0.1.188
path: /cam/realmonitor?channel=1&subtype=0
port: 554
stream_format: rtsp
username:
password:
fps: 15
recorder:
lookback: 10

back_yard:
  name: Back Yard
  host: 10.0.1.196
  path: /cam/realmonitor?channel=1&subtype=0
  port: 554
  stream_format: rtsp
  username: <scrubbed>
  password: <scrubbed>
  fps: 15
  codec: hevc_cuvid
  recorder:
    lookback: 10

drive_way:
  name: Drive Way
  host: 10.0.1.197
  path: /cam/realmonitor?channel=1&subtype=0
  port: 554
  stream_format: rtsp
  username: <scrubbed>
  password: <scrubbed>
  fps: 15
  codec: hevc_cuvid
  recorder:
    lookback: 10

garage:
  name: Garage
  host: 10.0.1.126
  path: /cam/realmonitor?channel=4&subtype=0
  port: 554
  stream_format: rtsp
  username: <scrubbed>
  password: <scrubbed>
  fps: 15
  codec: hevc_cuvid
  recorder:
    lookback: 10

mog2:
motion_detector:
cameras:
front_door:
trigger_recorder: true
recorder_keepalive: true
max_recorder_keepalive: 30
fps: 5
area: 0.05
width: 300
height: 300
mask: []
threshold: 25
history: 500
detect_shadows: true
learning_rate: 0.01

  back_yard:
    trigger_recorder: true
    recorder_keepalive: true
    max_recorder_keepalive: 30
    fps: 5
    area: 0.05
    width: 300
    height: 300
    mask: []
    threshold: 25
    history: 500
    detect_shadows: true
    learning_rate: 0.01

  drive_way:
    trigger_recorder: true
    recorder_keepalive: true
    max_recorder_keepalive: 30
    fps: 5
    area: 0.05
    width: 300
    height: 300
    mask: []
    threshold: 25
    history: 500
    detect_shadows: true
    learning_rate: 0.01

  garage:
    trigger_recorder: true
    recorder_keepalive: true
    max_recorder_keepalive: 30
    fps: 5
    area: 0.05
    width: 300
    height: 300
    mask: []
    threshold: 30
    history: 500
    detect_shadows: true
    learning_rate: 0.01

darknet:
object_detector:
cameras:
front_door:
fps: 2
scan_on_motion_only: true
labels:
- label: person
confidence: 0.8
trigger_recorder: true
- label: dog
confidence: 0.8
trigger_recorder: true
- label: truck
confidence: 0.8
trigger_recorder: true
back_yard:
fps: 1
scan_on_motion_only: true
labels:
- label: person
confidence: 0.85
trigger_recorder: true
- label: dog
confidence: 0.8
trigger_recorder: true
drive_way:
fps: 2
scan_on_motion_only: true
labels:
- label: person
confidence: 0.8
trigger_recorder: true
- label: car
confidence: 0.85
trigger_recorder: true
require_motion: true
- label: truck
confidence: 0.8
trigger_recorder: true
garage:
fps: 1
scan_on_motion_only: true
labels:
- label: person
confidence: 0.8
trigger_recorder: true

nvr:
front_door: {}
back_yard: {}
drive_way: {}
garage: {}

webserver: {}

logger:
default_level: error
logs:
viseron.components.ffmpeg: error
viseron.components.nvr: error
viseron.components.darknet: error
viseron.components.mog2: error
viseron.components.storage: error
sqlalchemy.engine: error

storage:
recorder:
tiers:
- path: /recordings/front_door
events:
max_age:
days: 30
continuous:
max_age:
days: 30
- path: /recordings/back_yard
events:
max_age:
days: 31
continuous:
max_age:
days: 31
- path: /recordings/drive_way
events:
max_age:
days: 32
continuous:
max_age:
days: 32
- path: /recordings/garage
events:
max_age:
days: 33
continuous:
max_age:
days: 33

snapshots:
tiers:
- path: /recordings/snapshots
max_age:
days: 30

@roflcoopter
Copy link
Owner

Should be fixed now in dev.
The files were not being removed after they were processed, but now they are.
Depending on how many files you still have in the temp folder you might get a sea of errors when restarting, but eventually Viseron will catch up and have deleted all the files.

Also i think you have missunderstood the tiers config a bit.
The storage > recorder > tiers config is global for all cameras, so with the config you have now all your cameras will first move to /recordings/front_door, then to /recordings/back_yard, then to /recordings/drive_way etc etc

This should be enough to save everything for 30 days:

storage:
  recorder:
    tiers:
      - path: /recordings
        events:
          max_age:
            days: 30
        continuous:
          max_age:
            days: 30

  snapshots:
    tiers:
      - path: /snapshots
        max_age:
          days: 30

@madman2012
Copy link
Author

madman2012 commented Aug 9, 2024 via email

@madman2012
Copy link
Author

@roflcoopter Any ideas what is happening here? It happens on dev then fails to run anymore. I have to restart the container to get it recording again. Then it errors out and stops recording after 15-20mins.

text error warn system array login

self._objects_in_fov_setter(shared_frame, objects_in_fov)

File "/src/viseron/domains/object_detector/init.py", line 409, in _objects_in_fov_setter
snapshot_path = self._camera.save_snapshot(
File "/src/viseron/domains/camera/init.py", line 676, in save_snapshot
decoded_frame = self.shared_frames.get_decoded_frame_rgb(shared_frame)
File "/src/viseron/domains/camera/shared_frames.py", line 115, in get_decoded_frame_rgb
return self._color_convert(shared_frame, COLOR_MODEL_RGB)
File "/src/viseron/domains/camera/shared_frames.py", line 105, in _color_convert
decoded_frame = self.get_decoded_frame(shared_frame).copy()
File "/src/viseron/domains/camera/shared_frames.py", line 95, in get_decoded_frame
return self._frames[shared_frame.name]
KeyError: UUID('e7df6543-1fe6-40db-85e9-c00200f82d08')
[2024-08-13 09:09:49] [ERROR ] [viseron.components.nvr.nvr.drive_way] - Failed to retrieve result for object_detector, message repeated 2 times
[2024-08-13 09:09:50] [ERROR ] [viseron.watchdog.thread_watchdog] - Thread drive_way.object_detection is dead, restarting
[2024-08-13 09:10:54] [ERROR ] [viseron.components.ffmpeg.camera.garage] - Frame reader process has exited
[2024-08-13 09:10:59] [ERROR ] [viseron.components.ffmpeg.camera.garage] - Restarting frame pipe
[2024-08-13 09:11:57] [ERROR ] [viseron.components.ffmpeg.camera.drive_way] - Did not receive a frame
[2024-08-13 09:11:59] [ERROR ] [viseron.components.ffmpeg.camera.back_yard] - Did not receive a frame
[2024-08-13 09:12:02] [ERROR ] [viseron.components.ffmpeg.camera.drive_way] - Restarting frame pipe
[2024-08-13 09:12:04] [ERROR ] [viseron.components.ffmpeg.camera.back_yard] - Restarting frame pipe
[2024-08-13 10:43:27] [ERROR ] [viseron.components.nvr.nvr.garage] - Failed to retrieve result for motion_detector
[2024-08-13 10:44:02] [ERROR ] [viseron.components.ffmpeg.stream.drive_way] - [rtsp @ 0x55db98c0f600] RTP: PT=62: bad cseq 7e9b expected=6d19
[2024-08-13 10:44:03] [ERROR ] [viseron.components.ffmpeg.stream.drive_way] - [rtsp @ 0x55db98c0f600] RTP: PT=62: bad cseq 93d8 expected=81ef
[2024-08-13 11:16:01] [ERROR ] [viseron.components.ffmpeg.stream.drive_way] - [rtsp @ 0x55db98c0f600] RTP: PT=62: bad cseq 787f expected=670e
[2024-08-13 11:16:15] [ERROR ] [viseron.components.nvr.nvr.drive_way] - Failed to retrieve result for object_detector
[2024-08-13 11:16:26] [ERROR ] [viseron.components.nvr.nvr.back_yard] - Failed to retrieve result for motion_detector
[2024-08-13 11:16:33] [ERROR ] [viseron.components.ffmpeg.stream.back_yard] - [rtsp @ 0x55aa2089f600] RTP: PT=62: bad cseq f018 expected=e33f
[2024-08-13 11:17:14] [ERROR ] [viseron.components.ffmpeg.stream.back_yard] - [rtsp @ 0x55aa2089f600] RTP: PT=62: bad cseq 1310 expected=0740
[2024-08-13 11:17:16] [ERROR ] [viseron.components.ffmpeg.stream.back_yard] - [rtsp @ 0x55aa2089f600] RTP: PT=62: bad cseq 292a expected=1d21
[2024-08-13 11:17:16] [ERROR ] [viseron.components.ffmpeg.stream.drive_way] - [rtsp @ 0x55db98c0f600] RTP: PT=62: bad cseq 04dc expected=e1ba
[2024-08-13 11:17:17] [ERROR ] [viseron.components.ffmpeg.stream.drive_way] - [rtsp @ 0x55db98c0f600] RTP: PT=62: bad cseq 349c expected=086e
[2024-08-13 11:17:19] [ERROR ] [viseron.components.ffmpeg.stream.back_yard] - [rtsp @ 0x55aa2089f600] RTP: PT=62: bad cseq 45e1 expected=2e57
[2024-08-13 11:21:44] [ERROR ] [viseron.domains.camera.fragmenter.back_yard] - Failed to get extinf for 1723562280.m4s
2024-08-13 11:22:23.111 EDT [10578] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-08-13 11:22:23.111 EDT [10578] DETAIL: Key (path)=(/recordings/segments/front_door/1723562540.m4s) already exists.
2024-08-13 11:22:23.111 EDT [10578] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/recordings/segments/front_door/1723562540.m4s', '2024-08-13T15:22:20'::timestamp, '{"m3u8": {"EXTINF": 2.643522}}') RETURNING files_meta.id
[2024-08-13 11:22:23] [ERROR ] [viseron.domains.camera.fragmenter.front_door] - Failed to process m4s file 1723562540.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/segments/front_door/1723562540.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/domains/camera/fragmenter.py", line 274, in _handle_m4s
self._write_files_metadata(file, extinf, program_date_time)
File "/src/viseron/domains/camera/fragmenter.py", line 220, in _write_files_metadata
session.execute(stmt)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/segments/front_door/1723562540.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/recordings/segments/front_door/1723562540.m4s', 'orig_ctime': datetime.datetime(2024, 8, 13, 15, 22, 20), 'meta': '{"m3u8": {"EXTINF": 2.643522}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-08-13 11:22:34] [ERROR ] [viseron.components.ffmpeg.camera.front_door] - Frame reader process has exited
[2024-08-13 11:22:40] [ERROR ] [viseron.components.ffmpeg.camera.front_door] - Restarting frame pipe
[2024-08-13 11:22:51] [ERROR ] [viseron.components.ffmpeg.camera.garage] - Did not receive a frame
[2024-08-13 11:22:56] [ERROR ] [viseron.components.ffmpeg.camera.garage] - Restarting frame pipe
[2024-08-13 11:24:40] [ERROR ] [viseron.components.ffmpeg.camera.drive_way] - Did not receive a frame
[2024-08-13 11:24:41] [ERROR ] [viseron.components.ffmpeg.camera.back_yard] - Did not receive a frame
[2024-08-13 11:24:45] [ERROR ] [viseron.components.ffmpeg.camera.drive_way] - Restarting frame pipe
[2024-08-13 11:24:46] [ERROR ] [viseron.components.ffmpeg.camera.back_yard] - Restarting frame pipe

@roflcoopter
Copy link
Owner

Strange, what does your config look like now?
Can you try to stop Viseron, delete the postgres folder in your config folder, delete all the files in recordings, segments, thumbnails and snapshots to see if the issues persist?

I have an upcoming fix for the missing frame (the UUID KeyError)

Regarding 2024-08-09 11:33:32.299 EDT [32103] ERROR: could not resize shared memory segment "/PostgreSQL.3947467608" to 4194304 bytes: No space left on device, there is a fix here: #721 (reply in thread)

@madman2012
Copy link
Author

madman2012 commented Aug 15, 2024 via email

@madman2012
Copy link
Author

madman2012 commented Aug 16, 2024 via email

@madman2012
Copy link
Author

Hi @roflcoopter,

I wanted to share what I've observed in case it helps with the next dev release.

The main issue I'm seeing is related to database inserts. There are a lot of errors like this:

sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/segments/front_door/1723828367.m4s) already exists.

This seems to be happening in the fragmenter.py file, specifically in the _write_files_metadata method. From what I understand, it's trying to insert a record that already exists. Maybe there's a way to update the record instead of inserting a new one if it already exists? I am not sure why its doing this after a database reset.

Another thing I noticed is that sometimes threads seem to die, especially for motion detection. For example:

Certainly! Here's a revised, more specific comment from a non-coder perspective:
CopyHi @roflcoopter,

I've been testing Viseron and it's really impressive! I've run into a few hiccups though, and I wanted to share what I've observed in case it helps with the next dev release.

The main issue I'm seeing is related to database inserts. There are a lot of errors like this:
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/recordings/segments/front_door/1723828367.m4s) already exists.
Copy
This seems to be happening in the fragmenter.py file, specifically in the _write_files_metadata method. From what I understand, it's trying to insert a record that already exists. Maybe there's a way to update the record instead of inserting a new one if it already exists?

Another thing I noticed is that sometimes threads seem to die, especially for motion detection. For example:
[2024-08-16 12:56:53] [ERROR ] [viseron.watchdog.thread_watchdog] - Thread garage.motion_detection is dead, restarting

I'm not sure how to fix this, but perhaps there's a way to make these threads more resilient or restart them more smoothly?

Lastly, I sometimes get this error:
KeyError: UUID('4158075b-74c0-4c3b-99b0-f8b64ce1227d')

This seems to be happening in the shared_frames.py file when trying to get a decoded frame. Maybe there's a way to handle this more gracefully if the frame isn't found?

I hope this information is helpful! I'm really excited about Viseron and appreciate all your hard work. Let me know if you need any more details or if there's anything else I can do to help test.

@roflcoopter
Copy link
Owner

The motion detector thread dies because of the exception when trying to get the missing shared frame.
The frames are kept in memory for about 2 seconds, so it seems the motion detector thread is running very slowly.
There are safe guards in place to not remove a frame that is currently being processed, but the were not enabled for the motion detectors or object detectors. I have that fixed locally so in the next release that should not be an issue.

Viseron periodically looks for new files to to insert into the database, and my guess is that multiple checks are running concurrently. I have some fixes for that locally as well which i believe will help.

I need a few more days to finish it up before i can push it so please bare with me!

@roflcoopter
Copy link
Owner

Changes are now pushed to dev that hopefully fixes this!
If its not too much hassle i would suggest starting fresh again and see if you still encounter issues.
That way we can me sure that there are now strange left overs from the previous runs.

@madman2012
Copy link
Author

Hi @roflcoopter

Thanks for such an awesome project. I am excited about it and still keep tinkering. I’m still encountering a few persistent issues with Viseron on the latest version of DEV that I hope you can help with. Below is a summary of the main errors and behaviors I'm experiencing, along with my configuration and Docker run command for your reference.

  1. Garbage Collection Error
    The following error is causing problems during garbage collection:
    Exception ignored in garbage collection:
    Traceback (most recent call last):
    File "/usr/local/lib/python3.10/dist-packages/watchdog/utils/dirsnapshot.py", line 353, in walk
    entry = (p, self.stat(p))
    TypeError: object.new() takes exactly one argument (the type to instantiate)

  2. Segmentation Fault (Signal 11)
    This error occurs and crashes the container:
    [viseron-finish] Viseron received signal 11

  3. File Handling & Metadata Insertion Failures
    I've encountered several errors related to file movement and metadata insertion. Here's a representative log:

[ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to move file /localrecord/segments/back_yard/1727405014.m4s to /nasrecord/segments/back_yard/1727405014.m4s: [Errno 2] No such file or directory: '/localrecord/segments/back_yard/1727405014.m4s'

2024-09-27 22:45:22.796 EDT [150213] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1727405018.m4s) already exists.

This error is repeated for various file paths and seems to be related to attempting to insert metadata into the database, causing it to fail due to a unique constraint violation:

sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"

Summary:
Garbage Collection TypeError: Preventing proper cleanup of filesystem objects.
Segmentation Fault (Signal 11): Causing container crashes.
File Handling & Metadata Integrity: Repeated failures when moving files and inserting metadata, likely causing cascading issues with the system.

Here is my current configuration and the Docker run command (with passwords removed) for reference:

docker run -d
--name viseron
-v /var/tmp/viseron:/localrecord
-v /mnt/cctv/recordings:/nasrecord
-v /etc/localtime:/etc/localtime:ro
-v /dev/bus/usb:/dev/bus/usb
--device /dev/dri
--privileged
-p 8888:8888
-e PUID=0
-e PGID=0
roflcoopter/viseron:dev

ffmpeg:
camera:
front_door:
name: Front Door
host: 10.0.1.188
path: /cam/realmonitor?channel=1&subtype=0
port: 554
stream_format: rtsp
username:
password:
fps: 15
hwaccel_args:
- -hwaccel
- vaapi
- -hwaccel_device
- /dev/dri/renderD128
- -hwaccel_output_format
- yuv420p
recorder:
lookback: 10
create_event_clip: true

back_yard:
  name: Back Yard
  host: 10.0.1.196
  path: /cam/realmonitor?channel=1&subtype=0
  port: 554
  stream_format: rtsp
  username: 
  password: 
  fps: 15
  hwaccel_args:
    - -hwaccel
    - vaapi
    - -hwaccel_device
    - /dev/dri/renderD128
    - -hwaccel_output_format
    - yuv420p
  recorder:
    lookback: 10
    create_event_clip: true

drive_way:
  name: Drive Way
  host: 10.0.1.197
  path: /cam/realmonitor?channel=1&subtype=0
  port: 554
  stream_format: rtsp
  username: 
  password: 
  fps: 15
  hwaccel_args:
    - -hwaccel
    - vaapi
    - -hwaccel_device
    - /dev/dri/renderD128
    - -hwaccel_output_format
    - yuv420p
  recorder:
    lookback: 10
    create_event_clip: true

garage:
  name: Garage
  host: 10.0.1.126
  path: /cam/realmonitor?channel=4&subtype=0
  port: 554
  stream_format: rtsp
  username: 
  password: 
  fps: 15
  hwaccel_args: []
  recorder:
    lookback: 10
    create_event_clip: true

edgetpu:
object_detector:
device: usb
cameras:
front_door:
fps: 5
scan_on_motion_only: false
labels:
- label: person
confidence: 0.70
trigger_recorder: true
- label: dog
confidence: 0.70
trigger_recorder: true
- label: truck
confidence: 0.70
trigger_recorder: true

  back_yard:
    fps: 1
    scan_on_motion_only: false
    labels:
      - label: person
        confidence: 0.70
        trigger_recorder: true
      - label: dog
        confidence: 0.70
        trigger_recorder: true

  drive_way:
    fps: 2
    scan_on_motion_only: false
    labels:
      - label: person
        confidence: 0.70
        trigger_recorder: true

  garage:
    fps: 2
    scan_on_motion_only: true
    labels:
      - label: person
        confidence: 0.70
        trigger_recorder: true

storage:
recorder:
tiers:
- path: /localrecord
move_on_shutdown: false
poll: false
continuous:
max_size:
gb: 75
max_age:
days: 1
events:
max_size:
gb: 50
max_age:
days: 1
- path: /nasrecord
poll: true
continuous:
max_size:
gb: 4000
max_age:
days: 90
events:
max_size:
gb: 2000
max_age:
days: 180

Let me know if I can provide any more information to help troubleshoot these issues!

@madman2012
Copy link
Author

accidentally closed it. Sorry.

@madman2012 madman2012 reopened this Sep 28, 2024
@roflcoopter
Copy link
Owner

Hmm this is a hard one.
I have not seen the error 1 and 2, and its hard to figure out without more information.

Do you have a longer stacktrace of the first error o i can see what code in Viseron it originates from?

Would also need a crash dump to figure out what is causing the segmentation fault.

I do get sporadic error for duplicates as well so that is something i can work on by myself.

Thanks for your reports!

@madman2012
Copy link
Author

I ran the following log through 01 and this is what it came up with. If you tell me how to run the dumps I can get you more details from my log? I can probably figure that out with 01 and drop more here. Wish I could help more on the code but it sounds like an issue with the tiers.py? The code line fails are identified.

"It's all duplicate key stuff. Can you walk me through the fix step by step? 2024-10-04 16:55:55.159 EDT [39375] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-10-04 16:55:55.159 EDT [39375] DETAIL: Key (path)=(/nasrecord/segments/garage/1728062722.m4s) already exists.
2024-10-04 16:55:55.159 EDT [39375] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/nasrecord/segments/garage/1728062722.m4s', '2024-10-04T17:25:22'::timestamp, '{"m3u8": {"EXTINF": 4.023145}}') RETURNING files_meta.id
[2024-10-04 16:55:55] [ERROR ] [viseron.components.storage.tier_handler.garage.tier_0] - Failed to insert metadata for /nasrecord/segments/garage/1728062722.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/garage/1728062722.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/components/storage/tier_handler.py", line 810, in move_file
session.execute(ins)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/garage/1728062722.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/nasrecord/segments/garage/1728062722.m4s', 'orig_ctime': datetime.datetime(2024, 10, 4, 17, 25, 22), 'meta': '{"m3u8": {"EXTINF": 4.023145}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-10-04 16:55:55] [ERROR ] [viseron.components.storage.tier_handler.garage.tier_0] - Failed to move file /localrecord/segments/garage/1728062722.m4s to /nasrecord/segments/garage/1728062722.m4s: [Errno 2] No such file or directory: '/localrecord/segments/garage/1728062722.m4s'
[2024-10-04 16:56:06] [ERROR ] [viseron.components.ffmpeg.stream.garage] - [h264 @ 0x648f61051e00] out of range intra chroma pred mode
[2024-10-04 16:56:56] [ERROR ] [viseron.components.ffmpeg.stream.garage] - [h264 @ 0x648f61051e00] negative number of zero coeffs at 133 3
2024-10-04 16:57:43.854 EDT [39057] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-10-04 16:57:43.854 EDT [39057] DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066316.m4s) already exists.
2024-10-04 16:57:43.854 EDT [39057] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/nasrecord/segments/back_yard/1728066316.m4s', '2024-10-04T18:25:16'::timestamp, '{"m3u8": {"EXTINF": 5.913477}}') RETURNING files_meta.id
[2024-10-04 16:57:43] [ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to insert metadata for /nasrecord/segments/back_yard/1728066316.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066316.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/components/storage/tier_handler.py", line 810, in move_file
session.execute(ins)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066316.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/nasrecord/segments/back_yard/1728066316.m4s', 'orig_ctime': datetime.datetime(2024, 10, 4, 18, 25, 16), 'meta': '{"m3u8": {"EXTINF": 5.913477}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-10-04 16:57:44] [ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to move file /localrecord/segments/back_yard/1728066316.m4s to /nasrecord/segments/back_yard/1728066316.m4s: [Errno 2] No such file or directory: '/localrecord/segments/back_yard/1728066316.m4s'
2024-10-04 16:59:20.974 EDT [39375] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-10-04 16:59:20.974 EDT [39375] DETAIL: Key (path)=(/nasrecord/segments/drive_way/1728065801.m4s) already exists.
2024-10-04 16:59:20.974 EDT [39375] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/nasrecord/segments/drive_way/1728065801.m4s', '2024-10-04T18:16:41'::timestamp, '{"m3u8": {"EXTINF": 6.001693}}') RETURNING files_meta.id
[2024-10-04 16:59:20] [ERROR ] [viseron.components.storage.tier_handler.drive_way.tier_0] - Failed to insert metadata for /nasrecord/segments/drive_way/1728065801.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/drive_way/1728065801.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/components/storage/tier_handler.py", line 810, in move_file
session.execute(ins)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/drive_way/1728065801.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/nasrecord/segments/drive_way/1728065801.m4s', 'orig_ctime': datetime.datetime(2024, 10, 4, 18, 16, 41), 'meta': '{"m3u8": {"EXTINF": 6.001693}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-10-04 16:59:21] [ERROR ] [viseron.components.storage.tier_handler.drive_way.tier_0] - Failed to move file /localrecord/segments/drive_way/1728065801.m4s to /nasrecord/segments/drive_way/1728065801.m4s: [Errno 2] No such file or directory: '/localrecord/segments/drive_way/1728065801.m4s'
2024-10-04 16:59:49.325 EDT [39057] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-10-04 16:59:49.325 EDT [39057] DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066426.m4s) already exists.
2024-10-04 16:59:49.325 EDT [39057] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/nasrecord/segments/back_yard/1728066426.m4s', '2024-10-04T18:27:06'::timestamp, '{"m3u8": {"EXTINF": 6.010417}}') RETURNING files_meta.id
[2024-10-04 16:59:49] [ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to insert metadata for /nasrecord/segments/back_yard/1728066426.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066426.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/components/storage/tier_handler.py", line 810, in move_file
session.execute(ins)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066426.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/nasrecord/segments/back_yard/1728066426.m4s', 'orig_ctime': datetime.datetime(2024, 10, 4, 18, 27, 6), 'meta': '{"m3u8": {"EXTINF": 6.010417}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-10-04 16:59:49] [ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to move file /localrecord/segments/back_yard/1728066426.m4s to /nasrecord/segments/back_yard/1728066426.m4s: [Errno 2] No such file or directory: '/localrecord/segments/back_yard/1728066426.m4s'
2024-10-04 17:00:49.744 EDT [39057] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-10-04 17:00:49.744 EDT [39057] DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066472.m4s) already exists.
2024-10-04 17:00:49.744 EDT [39057] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/nasrecord/segments/back_yard/1728066472.m4s', '2024-10-04T18:27:52'::timestamp, '{"m3u8": {"EXTINF": 4.007031}}') RETURNING files_meta.id
[2024-10-04 17:00:49] [ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to insert metadata for /nasrecord/segments/back_yard/1728066472.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066472.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/components/storage/tier_handler.py", line 810, in move_file
session.execute(ins)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/back_yard/1728066472.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/nasrecord/segments/back_yard/1728066472.m4s', 'orig_ctime': datetime.datetime(2024, 10, 4, 18, 27, 52), 'meta': '{"m3u8": {"EXTINF": 4.007031}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-10-04 17:00:50] [ERROR ] [viseron.components.storage.tier_handler.back_yard.tier_0] - Failed to move file /localrecord/segments/back_yard/1728066472.m4s to /nasrecord/segments/back_yard/1728066472.m4s: [Errno 2] No such file or directory: '/localrecord/segments/back_yard/1728066472.m4s'
2024-10-04 17:03:09.089 EDT [39056] ERROR: duplicate key value violates unique constraint "files_meta_path_key"
2024-10-04 17:03:09.089 EDT [39056] DETAIL: Key (path)=(/nasrecord/segments/garage/1728063122.m4s) already exists.
2024-10-04 17:03:09.089 EDT [39056] STATEMENT: INSERT INTO files_meta (path, orig_ctime, meta) VALUES ('/nasrecord/segments/garage/1728063122.m4s', '2024-10-04T17:32:02'::timestamp, '{"m3u8": {"EXTINF": 4.060645}}') RETURNING files_meta.id
[2024-10-04 17:03:09] [ERROR ] [viseron.components.storage.tier_handler.garage.tier_0] - Failed to insert metadata for /nasrecord/segments/garage/1728063122.m4s
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/garage/1728063122.m4s) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/src/viseron/components/storage/tier_handler.py", line 810, in move_file
session.execute(ins)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2236, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/bulk_persistence.py", line 1283, in orm_execute_statement
result = conn.execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1418, in execute
return meth(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2353, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/garage/1728063122.m4s) already exists.

[SQL: INSERT INTO files_meta (path, orig_ctime, meta) VALUES (%(path)s, %(orig_ctime)s, %(meta)s) RETURNING files_meta.id]
[parameters: {'path': '/nasrecord/segments/garage/1728063122.m4s', 'orig_ctime': datetime.datetime(2024, 10, 4, 17, 32, 2), 'meta': '{"m3u8": {"EXTINF": 4.060645}}'}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
[2024-10-04 17:03:09] [ERROR ] [viseron.components.storage.tier_handler.garage.tier_0] - Failed to move file /localrecord/segments/garage/1728063122.m4s to /nasrecord/segments/garage/1728063122.m4s: [Errno 2] No such file or directory: '/localrecord/segments/garage/1728063122.m4s'

"Thank you for providing the error logs and the tier_handler.py code. I’ll guide you through the steps to identify and fix the duplicate key errors you’re experiencing in Viseron.

Understanding the Error

The error messages indicate that there’s a violation of a unique constraint in the database:

psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "files_meta_path_key"
DETAIL: Key (path)=(/nasrecord/segments/garage/1728062722.m4s) already exists.

•	Explanation: The database table files_meta has a unique constraint on the path column, meaning no two records can have the same path value.
•	Cause: The code is attempting to insert a new record with a path that already exists in the files_meta table.

Additionally, there’s an error when moving files:

Failed to move file /localrecord/segments/garage/1728062722.m4s to /nasrecord/segments/garage/1728062722.m4s: [Errno 2] No such file or directory: '/localrecord/segments/garage/1728062722.m4s'

•	Explanation: The program is trying to move a file that doesn’t exist at the source location.

Step-by-Step Fix

  1. Locate the Problematic Code

In your tier_handler.py, the error occurs in the move_file function when inserting into the files_meta table. Here’s the relevant code snippet:

def move_file(
get_session: Callable[..., Session],
src: str,
dst: str,
logger: logging.Logger,
) -> None:
"""Move file from src to dst."""
logger.debug("Moving file from %s to %s", src, dst)
try:
with get_session() as session:
sel = select(FilesMeta).where(FilesMeta.path == src)
res = session.execute(sel).scalar_one()
ins = insert(FilesMeta).values(
path=dst, meta=res.meta, orig_ctime=res.orig_ctime
)
session.execute(ins)
session.commit()
except IntegrityError:
logger.error(f"Failed to insert metadata for {dst}", exc_info=True)

try:
    os.makedirs(os.path.dirname(dst), exist_ok=True)
    shutil.copy(src, dst)
    os.remove(src)
except FileNotFoundError as error:
    logger.error(f"Failed to move file {src} to {dst}: {error}")
    with get_session() as session:
        stmt = delete(Files).where(Files.path == src)
        session.execute(stmt)
        session.commit()
  1. Identify the Cause

    • Duplicate Insertion: The code attempts to insert a new record into files_meta with the destination path (dst), but if a record with that path already exists, it causes a UniqueViolation error.
    • File Not Found: If the source file (src) doesn’t exist, the FileNotFoundError is raised when trying to copy or remove the file.

  2. Modify the Code to Handle Duplicates

To prevent the duplicate key error, we need to check if a record with the destination path already exists before inserting. If it exists, we can update it or skip the insertion.

Here’s how you can modify the move_file function:

from sqlalchemy.exc import IntegrityError, NoResultFound

def move_file(
get_session: Callable[..., Session],
src: str,
dst: str,
logger: logging.Logger,
) -> None:
"""Move file from src to dst."""
logger.debug("Moving file from %s to %s", src, dst)
try:
with get_session() as session:
# Check if the destination path already exists in files_meta
sel_dst = select(FilesMeta).where(FilesMeta.path == dst)
try:
res_dst = session.execute(sel_dst).scalar_one()
# If it exists, update the existing record
upd = (
update(FilesMeta)
.where(FilesMeta.path == dst)
.values(meta=res_dst.meta, orig_ctime=res_dst.orig_ctime)
)
session.execute(upd)
except NoResultFound:
# If it doesn't exist, insert a new record
sel_src = select(FilesMeta).where(FilesMeta.path == src)
res_src = session.execute(sel_src).scalar_one()
ins = insert(FilesMeta).values(
path=dst, meta=res_src.meta, orig_ctime=res_src.orig_ctime
)
session.execute(ins)
session.commit()
except IntegrityError as e:
logger.error(f"Integrity error when handling metadata for {dst}: {e}", exc_info=True)
session.rollback()
except NoResultFound as e:
logger.error(f"No metadata found for source {src}: {e}", exc_info=True)
session.rollback()

try:
    os.makedirs(os.path.dirname(dst), exist_ok=True)
    shutil.copy(src, dst)
    os.remove(src)
except FileNotFoundError as error:
    logger.error(f"Failed to move file {src} to {dst}: {error}")
    with get_session() as session:
        stmt = delete(Files).where(Files.path == src)
        session.execute(stmt)
        session.commit()
  1. Explanation of Changes

    • Check for Existing Destination Record:
    • Before inserting, we check if a record with dst already exists.
    • If it exists, we can choose to update it or skip the insertion.
    • Handle NoResultFound Exception:
    • When fetching the source metadata, if the source record doesn’t exist, we catch NoResultFound and log an error.
    • Handle IntegrityError:
    • If an IntegrityError occurs, we log the error and rollback the session to prevent the transaction from being left in an invalid state.
    • Improved Exception Handling:
    • Added more specific exception handling to provide clearer error messages and maintain database integrity.

  2. Verify File Existence Before Moving

Before attempting to move the file, ensure that the source file exists:

import os

def move_file(
get_session: Callable[..., Session],
src: str,
dst: str,
logger: logging.Logger,
) -> None:
"""Move file from src to dst."""
if not os.path.exists(src):
logger.error(f"Source file {src} does not exist. Skipping move.")
with get_session() as session:
stmt = delete(Files).where(Files.path == src)
session.execute(stmt)
session.commit()
return
# Rest of the code...

  1. Update Database After File Operations

Ensure that after moving the file, the Files table is updated with the new path:

# After os.remove(src)
with get_session() as session:
    # Update the path in the Files table
    upd_files = update(Files).where(Files.path == src).values(path=dst)
    session.execute(upd_files)
    session.commit()
  1. Rebuild and Test

    • Rebuild the Docker Image:

docker build -t viseron-dev .

•	Run the Docker Container:

docker run -d --name viseron-dev -p 8888:8888 viseron-dev

•	Monitor the Logs:

docker logs -f viseron-dev

•	Check for Errors:
•	Verify that the duplicate key errors no longer appear.
•	Ensure that files are being moved correctly and that their metadata is handled appropriately.
  1. Clean Up the Database (Optional)

If there are existing duplicate entries or inconsistencies, consider cleaning up the files_meta table:

•	Connect to the Database:

psql -U yourusername -h yourhost -p yourport yourdbname

•	Remove Duplicate Entries:

DELETE FROM files_meta
WHERE id IN (
SELECT id FROM (
SELECT id,
ROW_NUMBER() OVER (partition BY path ORDER BY id) AS rnum
FROM files_meta
) t
WHERE t.rnum > 1
);

Additional Tips

•	Database Indexes: Ensure that the files_meta table has appropriate indexes to optimize queries.
•	Logging: Enhance logging to provide more context when errors occur.
•	Exception Handling: Always handle exceptions gracefully to prevent the application from crashing.

Conclusion

By modifying the move_file function to handle cases where the destination path already exists in the files_meta table, you should resolve the duplicate key errors. Remember to test thoroughly after making changes to confirm that the issue is fixed and that no new issues have been introduced.

Feel free to ask if you need further assistance or clarification on any of the steps. Good luck!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants