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

CPVRChannelGroup - Persist: SQL constraint violation #172

Closed
buzz-tee opened this issue Jan 18, 2016 · 15 comments · Fixed by xbmc/xbmc#10507
Closed

CPVRChannelGroup - Persist: SQL constraint violation #172

buzz-tee opened this issue Jan 18, 2016 · 15 comments · Fixed by xbmc/xbmc#10507

Comments

@buzz-tee
Copy link

Loading the hts plugin will frequently on reboot and the screen gets stuck in 'Starting PVR manager'.
I'm using TVHeadend with two satellite networks (Astra + Hotbird) so there are plenty of services and channels mapped. It seems the issue occurs when a video PID is missing and a channel that was classified 'tv' is changed to 'radio' or vice versa. This happens every few hours so I have to clear the TV DB on every reboot.

In this such a case the logs would give me an error like this:

22:13:46 T:139793007634176   ERROR: SQL: Abort due to constraint violation
        Query: INSERT INTO channels (iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon,
        bIsUserSetName, bIsLocked, sIconPath, sChannelName, bIsVirtual, bEPGEnabled, 
        sEPGScraper, iLastWatched, iClientId, idEpg) VALUES (1800902271, 1, 0, 0, 0, 0,
        'http://192.168.10.2:9981/imagecache/1577', 'Bahai Radio', 0, 1, 'client', 0, 1600, -1)
22:13:46 T:139793007634176   ERROR: CommitInsertQueries - failed to execute queries

At the same time TV29.db already contains the following entry in table channels:

sqlite> select * from channels where iUniqueId=1800902271;
1711|1800902271|0|0|0|0|0|http://192.168.10.2:9981/imagecache/1577|Bahai Radio|0|1|client|0|1600|1711

The records only differ in bIsRadio (insert statement wants to set it 1, exists as 0) and idEpg (insert: -1, exists: 1711). The error gets thrown because the records would share the same values for iUniqueId and iClientId (unique index).

Environment:
ArchLinux 4.3.3-2 x86_64
Kodi 15.2
kodi-addon-pvr-hts 2.1.18-1 (built from Isengard branch)

Note: I'm not sure if it's a bug in the addon or rather in the Kodi PVR manager but I understand that existing channels should have the m_iChannelId field populated in order to have the PVR manager call 'REPLACE INTO' rather than 'INSERT INTO'.

@Glenn-1990
Copy link
Contributor

Can you also provide a kodi debug log from when this happens? I'm facing the same problem from time to time, but I was not able to get a proper log file yet.
EDIT: please also turn on all pvr/database specific debugging

@buzz-tee
Copy link
Author

Sure, no problem: http://gmeiner.xyz/kodi/kodi.debug.log
I had debug logging + pvr.hts extended logging enabled during the capture (is there a way to enable extended db logging?)
My apologies: the file holds all the crap of a fresh channel list (adding all fta channels...) so it's a bit lengthy.
EDIT: the DB at the time when the error occurred can be found here: http://gmeiner.xyz/kodi/TV29.debug.db

@Glenn-1990
Copy link
Contributor

Looking at the log file, I suspect that it has something to do with the channel groups, can you reproduce the database error with the "sync channel groups with backend" option in kodi off? (clear db after changing setting). Is it possible for you to run Jarvis if this wasn't a success, there were some database fixes there.

@Glenn-1990
Copy link
Contributor

Glenn-1990 commented Jan 21, 2016

@ksooo this is 100% reproducible, the problem is that in tvheadend a channel can be changed from tv to radio and the other way around. Kodi will not handle this and throw the sql error.

Found some more recent reports from this db error and in all cases the channel to be added is a radio channel, so it never appears for tv channels.
http://forum.kodi.tv/showthread.php?tid=235246
http://forum.kodi.tv/showthread.php?tid=189534&page=5
VDR also seems to trigger this issue.

The problem according my debugging:

  1. a tv channel (channel without service is also a tv channel according pvr.hts) is loaded in the kodi database
  2. after some time the user (or tvheadend itself) changes this channel into a radio channel. Kodi will interpret this as a new radio channel and try to add it to it's database. Of Course the old tv channel is still present there.

Steps to reproduce:

  1. add a channel in tvh backend without an service assigned (= tv channel)
  2. start kodi and clear db
  3. close kodi
  4. edit the channel in tvheadend and add a radio service to it
  5. open kodi -> db error, pvr addon will not load!
    21:11:31 T:140465655490304 ERROR: SQL: [TV29.db] Abort due to constraint violation
    Query: INSERT INTO channels (iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, idEpg) VALUES (1368899658, 1, 0, 0, 0, 0, '', '123test123', 0, 1, 'client', 0, 881, -1)

@Glenn-1990
Copy link
Contributor

@Bastig Not needed to test Jarvis anymore as I encountered the same problem with it now ;-)

@Jalle19
Copy link
Contributor

Jalle19 commented Jan 29, 2016

@Glenn-1990 so is this purely a Kodi bug or do we have to fix something in the addon as well? If not please go ahead and close this ticket.

@Glenn-1990
Copy link
Contributor

Well pvr.hts will assign undefined channels (channels without a service) as tv channels, this will increase the chance to trigger this issue. It's possible to hide these undefined channels, as the user will not be able to watch them anyway... But the kodi issue is the main problem of this.

@Jalle19
Copy link
Contributor

Jalle19 commented Jan 29, 2016

Should we ignore channels without a service? IMO we shouldn't since it may be confusing.

@Glenn-1990
Copy link
Contributor

Maybe we should notify the user why tuning such a channel fails (display "no service assigned to this channel" or such), but that's not related to this issue.

@Glenn-1990
Copy link
Contributor

@Jalle19 What do you think of the kodi fix for this?

@Jalle19
Copy link
Contributor

Jalle19 commented Jan 30, 2016

Perhaps it would be enough to just log it?

@Jalle19
Copy link
Contributor

Jalle19 commented Jun 1, 2016

Any update on this?

@Glenn-1990
Copy link
Contributor

PR to fix this is still open:
xbmc/xbmc#8953

Seems that multiple users are suffering from this issue, but on the forums they just get the explanation that their db got corrupted...
Mainly tvh and vdr reports, probably because of the way they define radio/tv channels.
(video PID present = tv channel in pvr.hts, radio otherwise; when the video PID disappears, pvr.hts will transfer it to a radio channel)

Try to google "ERROR: SQL: Abort due to constraint violation" almost every post with this error has the radio flag set, meaning that's it's most likely caused by the issue described above.

@hoppel118
Copy link

hoppel118 commented Jun 25, 2016

Moin,

yes, it's an Issue for me too.

I am using vdr 2.2.0, vnsiserver 1.3.1, kodi 16.1 and vnsiclient 1.11.16.

Have some Windows-10-Clients with kodi and now an odroid c2 with libreelec affected from this. I have to delete the TV29.db to bring back live tv after some time, again and again.

I will try to deactivate the Channel Updates on the vdr server by setting: "UpdateChannels = 0" in the setup.conf and report back here, if this worked as workaround.

Please bring the fix to krypton.

Greetings Hoppel

@hoppel118
Copy link

I will try to deactivate the Channel Updates on the vdr server by setting: "UpdateChannels = 0" in the setup.conf and report back here, if this worked as workaround.

Since deactivation of channel updates by vdr I didn't had this issue again. As a workaround it's fine.

Jalle19 pushed a commit to Jalle19/xbmc that referenced this issue Sep 19, 2016
Supersedes xbmc#8963
Fixes trac xbmc#16031
Closes kodi-pvr/pvr.hts#172

This fixes the problem without bumping the database version so it should be more possibly to get it merged for V17.

Basically the code that persists channels has been made smarter. Instead of just blindly looking at the primary key stored in the object we query the database to check if a channel with the unique ID and client ID already exists. If it does, we update that channel, if not we create a new channel. There is more background information in the referenced PRs.

This fix also has the added side-effect that it increases database performance. While a new SELECT statement has been added, we now do an UPDATE instead of a REPLACE INTO which prevents indexes from having to be re-calculated (REPLACE INTO basically does a DELETE followed by an INSERT). This also means we don't need to worry about the channel ID changing after the channel has been updated (which was a side effect of using REPLACE INTO).
Jalle19 pushed a commit to Jalle19/xbmc that referenced this issue Sep 21, 2016
Supersedes xbmc#8963
Fixes trac xbmc#16031
Closes kodi-pvr/pvr.hts#172

This fixes the problem without bumping the database version so it should be more possibly to get it merged for V17.

Basically the code that persists channels has been made smarter. Instead of just blindly looking at the primary key stored in the object we query the database to check if a channel with the unique ID and client ID already exists. If it does, we update that channel, if not we create a new channel. There is more background information in the referenced PRs.

This fix also has the added side-effect that it increases database performance. While a new SELECT statement has been added, we now do an UPDATE instead of a REPLACE INTO which prevents indexes from having to be re-calculated (REPLACE INTO basically does a DELETE followed by an INSERT). This also means we don't need to worry about the channel ID changing after the channel has been updated (which was a side effect of using REPLACE INTO).
Jalle19 pushed a commit to Jalle19/xbmc that referenced this issue Sep 25, 2016
Supersedes xbmc#8963
Fixes trac xbmc#16031
Closes kodi-pvr/pvr.hts#172

This fixes the problem without bumping the database version so it should be more possibly to get it merged for V17.

Basically the code that persists channels has been made smarter. Instead of just blindly looking at the primary key stored in the object we query the database to check if a channel with the unique ID and client ID already exists. If it does, we update that channel, if not we create a new channel. There is more background information in the referenced PRs.

This fix also has the added side-effect that it increases database performance. While a new SELECT statement has been added, we now do an UPDATE instead of a REPLACE INTO which prevents indexes from having to be re-calculated (REPLACE INTO basically does a DELETE followed by an INSERT). This also means we don't need to worry about the channel ID changing after the channel has been updated (which was a side effect of using REPLACE INTO).
Jalle19 pushed a commit to Jalle19/xbmc that referenced this issue Sep 25, 2016
Supersedes xbmc#8963
Fixes trac xbmc#16031
Closes kodi-pvr/pvr.hts#172

This fixes the problem without bumping the database version so it should be more possibly to get it merged for V17.

Basically the code that persists channels has been made smarter. Instead of just blindly looking at the primary key stored in the object we query the database to check if a channel with the unique ID and client ID already exists. If it does, we update that channel, if not we create a new channel. There is more background information in the referenced PRs.

This fix also has the added side-effect that it increases database performance. While a new SELECT statement has been added, we now do an UPDATE instead of a REPLACE INTO which prevents indexes from having to be re-calculated (REPLACE INTO basically does a DELETE followed by an INSERT). This also means we don't need to worry about the channel ID changing after the channel has been updated (which was a side effect of using REPLACE INTO).
Jalle19 pushed a commit to Jalle19/xbmc that referenced this issue Sep 25, 2016
Supersedes xbmc#8963
Fixes trac xbmc#16031
Closes kodi-pvr/pvr.hts#172

This fixes the problem without bumping the database version so it should be more possibly to get it merged for V17.

Basically the code that persists channels has been made smarter. Instead of just blindly looking at the primary key stored in the object we query the database to check if a channel with the unique ID and client ID already exists. If it does, we update that channel, if not we create a new channel. There is more background information in the referenced PRs.

This fix also has the added side-effect that it increases database performance. While a new SELECT statement has been added, we now do an UPDATE instead of a REPLACE INTO which prevents indexes from having to be re-calculated (REPLACE INTO basically does a DELETE followed by an INSERT). This also means we don't need to worry about the channel ID changing after the channel has been updated (which was a side effect of using REPLACE INTO).
Jalle19 pushed a commit to Jalle19/xbmc that referenced this issue Sep 25, 2016
Supersedes xbmc#8963
Fixes trac xbmc#16031
Closes kodi-pvr/pvr.hts#172

This fixes the problem without bumping the database version so it should be more possibly to get it merged for V17.

Basically the code that persists channels has been made smarter. Instead of just blindly looking at the primary key stored in the object we query the database to check if a channel with the unique ID and client ID already exists. If it does, we update that channel, if not we create a new channel. There is more background information in the referenced PRs.

This fix also has the added side-effect that it increases database performance. While a new SELECT statement has been added, we now do an UPDATE instead of a REPLACE INTO which prevents indexes from having to be re-calculated (REPLACE INTO basically does a DELETE followed by an INSERT). This also means we don't need to worry about the channel ID changing after the channel has been updated (which was a side effect of using REPLACE INTO).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants