Kodi Community Forum
SQLite fails database initialization on mounted network volume (SMB) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: SQLite fails database initialization on mounted network volume (SMB) (/showthread.php?tid=370660)



SQLite fails database initialization on mounted network volume (SMB) - Koder123 - 2022-12-04

Not sure if there are any SQLite expert around but my problem is exactly the same as in https://forum.kodi.tv/showthread.php?tid=345011, only difference is my client is Android / Shield Pro.

In short, Kodi / SQLite fails to initialize Addons33.db when it is located in mounted SMB share, in my case Shield Pro mount.

1. I'm using Android -specific xbmc_env.properties which points to Shield mounted SMB share on Linux server
2. Kodi is able to create directories (.kodi and all default folders for example) and files (temp/kodi.log for example) in the mount so it is not a write permission issue
3. If Addons33.db does not exist in Database/ Kodi tries to initialize it but fails mysteriously

2022-12-04 18:08:23.544 T:11828   DEBUG <general>: Initialize, updating databases...
2022-12-04 18:08:23.577 T:11828   ERROR <general>: SQL: [Addons33.db] SQLite error SQLITE_ERROR (no such table: version)
                                                   Query: SELECT idVersion FROM version
2022-12-04 18:08:23.581 T:11828   ERROR <general>: Process error processing job
2022-12-04 18:08:53.583 T:11828   DEBUG <general>: Thread JobWorker 155871622384 terminating (autodelete)

I understand that SQLite is not especially designed to run on network shares, however it would be nice to know what the actual issue here is.

I took look at the source code and cannot figure out why there is no logging about creating tables etc. before version -table is queried causing an error, or if SQLite fails somehow why there are no errors related to that.


RE: SQLite fails database initialization on mounted network volume (SMB) - Klojum - 2022-12-04

(2022-12-04, 22:05)Koder123 Wrote: I'm using Android -specific xbmc_env.properties which points to Shield mounted SMB share on Linux server

Any Linux 'server' can also run MySQL or MariaDB. Using a solution that knowingly is not suited for network access is a bit pushing it....

You could try to set up the complete SQLite database locally, and when all runs, move it to the network location.
Right now, the SQLite file seems corrupted/broken with missing tables.


RE: SQLite fails database initialization on mounted network volume (SMB) - Koder123 - 2022-12-04

(2022-12-04, 22:18)Klojum Wrote:
(2022-12-04, 22:05)Koder123 Wrote: ...

Any Linux 'server' can also run MySQL or MariaDB. Using a solution that knowingly is not suited for network access is a bit pushing it....

You could try to set up the complete SQLite database locally, and when all runs, move it to the network location.
Right now, the SQLite file seems corrupted/broken with missing tables.
Hi, yes I have working MariaDB set up for video/music DB but I'm looking for solution to move all stuff to network location.

DB file is surely "corrupted" but it is created by Kodi (because I have removed it completely first) but size is 0 and it does not contain any tables and for some reason there are no errors about initialization, but only when missing table is accessed.

If I use local directory in xbmc_env.properties initialization works fine. If I move complete .db files to network location Kodi still does not work but hangs on black startup screen, so this initialization is first step to figure out.


RE: SQLite fails database initialization on mounted network volume (SMB) - Klojum - 2022-12-04

(2022-12-04, 22:24)Koder123 Wrote: Hi, yes I have working MariaDB set up for video/music DB but I'm looking for solution to move all stuff to network location.
You already know the answer to that. Wink

(2022-12-04, 22:24)Koder123 Wrote: If I move complete .db files to network location Kodi still does not work but hangs on black startup screen, so this initialization is first step to figure out.
Try to provide the full debug log (wiki) of that session, or, the kodi.old.log when you restarted Kodi.


RE: SQLite fails database initialization on mounted network volume (SMB) - Koder123 - 2022-12-04

(2022-12-04, 22:32)Klojum Wrote: Try to provide the full debug log (wiki) of that session, or, the kodi.old.log when you restarted Kodi.

What happens is, if sane Addons33.db already exists, I see Database/Addons33.db-journal file which indicates that write operation was attempted but is not succeeding (transaction not finishing) and Kodi remains hang (black screen). Last line in the debug logs is

"2022-12-04 22:41:52.476 T:17979   DEBUG <general>: CAddonDatabase: vfs.libarchive has been installed."

and there are no errors in logs, only successful CAddonMgr / CAddonDatabase stuff.


RE: SQLite fails database initialization on mounted network volume (SMB) - Klojum - 2022-12-04

(2022-12-04, 22:47)Koder123 Wrote: Last line in the debug logs is

Eh... How is that gonna help us? Just a simple URL of the pasted log file will do.


RE: SQLite fails database initialization on mounted network volume (SMB) - Koder123 - 2022-12-04

(2022-12-04, 23:29)Klojum Wrote:
(2022-12-04, 22:47)Koder123 Wrote: Last line in the debug logs is

Eh... How is that gonna help us? Just a simple URL of the pasted log file will do.

It helps so that last thing happening is related to AddonDatabase which is also indicated by a journal file getting stuck. There's nothing more in the logs that helps here.


RE: SQLite fails database initialization on mounted network volume (SMB) - Koder123 - 2022-12-05

I tested network share on Windows, same results: Kodi is able to create all the directories and configuration files but fails creating Database/Addons33.db which remains size 0kb and also Database/Addons33.db-journal size 0kb remains.


RE: SQLite fails database initialization on mounted network volume (SMB) - Koder123 - 2022-12-06

So I built a modified version of Android build and got this working, everything related to Kodi is now running on a mounted network share.

What was needed was nolock=1 flag for SQLite (sqlitedataset.cpp).

Code:

std::string db_fullpath = "file:" + URIUtils::AddFileToFolder(host, db) + "?nolock=1";
...
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_URI;



RE: SQLite fails database initialization on mounted network volume (SMB) - scott967 - 2022-12-06

OK I guess you got a good connect using URI filename.  Don't know how URIUtils works, can this be a problem on windows (\\ vs /)?
Also need to consider:

"Caution: If two or more database connections try to interact with the same SQLite database and one or more of those connections has enabled "nolock", then database corruption can result. The "nolock" query parameter should only be used if the application can guarantee that writes to the database are serialized."

I don't think this could be PRed for v20 at this point, but that's just my guess I don't have any authority.

scott s.
.