Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #639 from thezoggy/dev--migration_tweaks

1080p migration tweak
  • Loading branch information...
commit fb37d332b333b43e7bcae46b619ae6b7ef94e266 2 parents 3aa78af + 91c428a
@midgetspy authored
Showing with 69 additions and 8 deletions.
  1. +24 −7 sickbeard/databases/mainDB.py
  2. +45 −1 sickbeard/db.py
View
31 sickbeard/databases/mainDB.py
@@ -27,6 +27,7 @@
MAX_DB_VERSION = 12
+
class MainSanityCheck(db.DBSanityCheck):
def check(self):
self.fix_duplicate_shows()
@@ -503,7 +504,7 @@ def execute(self):
ep_file_name = ek.ek(os.path.basename, cur_result["location"])
ep_file_name = os.path.splitext(ep_file_name)[0]
- # I only want to find real scene names here so anything with a space in it is out
+ # only want to find real scene names here so anything with a space in it is out
if ' ' in ep_file_name:
continue
@@ -621,6 +622,8 @@ def execute(self):
new_any = common.Quality.combineQualities([common.Quality.SDTV, common.Quality.SDDVD, common.Quality.HDTV, common.Quality.FULLHDTV, common.Quality.HDWEBDL, common.Quality.FULLHDWEBDL, common.Quality.HDBLURAY, common.Quality.FULLHDBLURAY, common.Quality.UNKNOWN], [])
# update qualities (including templates)
+ logger.log(u"[1/4] Updating pre-defined templates and the quality for each show...", logger.MESSAGE)
+ ql = []
shows = self.connection.select("SELECT * FROM tv_shows")
for cur_show in shows:
if cur_show["quality"] == old_hd:
@@ -629,23 +632,37 @@ def execute(self):
new_quality = new_any
else:
new_quality = self._update_composite_qualities(cur_show["quality"])
- self.connection.action("UPDATE tv_shows SET quality = ? WHERE tvdb_id = ?", [new_quality, cur_show["tvdb_id"]])
+ ql.append(["UPDATE tv_shows SET quality = ? WHERE show_id = ?", [new_quality, cur_show["show_id"]]])
+ self.connection.mass_action(ql)
# update status that are are within the old hdwebdl (1<<3 which is 8) and better -- exclude unknown (1<<15 which is 32768)
- episodes = self.connection.select("SELECT * FROM tv_episodes WHERE status/100 < 32768 AND status/100 >= 8")
+ logger.log(u"[2/4] Updating the status for the episodes within each show...", logger.MESSAGE)
+ ql = []
+ episodes = self.connection.select("SELECT * FROM tv_episodes WHERE status < 3276800 AND status >= 800")
for cur_episode in episodes:
- self.connection.action("UPDATE tv_episodes SET status = ? WHERE episode_id = ?", [self._update_status(cur_episode["status"]), cur_episode["episode_id"]])
+ ql.append(["UPDATE tv_episodes SET status = ? WHERE episode_id = ?", [self._update_status(cur_episode["status"]), cur_episode["episode_id"]]])
+ self.connection.mass_action(ql)
# make two seperate passes through the history since snatched and downloaded (action & quality) may not always coordinate together
# update previous history so it shows the correct action
- historyAction = self.connection.select("SELECT * FROM history WHERE action/100 < 32768 AND action/100 >= 8")
+ logger.log(u"[3/4] Updating history to reflect the correct action...", logger.MESSAGE)
+ ql = []
+ historyAction = self.connection.select("SELECT * FROM history WHERE action < 3276800 AND action >= 800")

Not sure what changed here, but this failed for me (as in, it would not go past this point).

I "fixed" it by disabling step 3/4 and 4/4 and it continued after that.

According to the interface, I was 70 commits behind (if that even means anything to anyone).

@thezoggy
thezoggy added a note

what did logs show? disabling any part of the migration can have ill effects.

1st attempt:
sickbeard.log.2-Apr-08 18:07:08 WARNING MAIN :: DB error: database is locked
sickbeard.log.2:Apr-08 18:07:09 INFO MAIN :: [3/4] Updating history to reflect the correct action...
sickbeard.log.2-Apr-08 18:07:09 DEBUG MAIN :: sickbeard.db: SELECT * FROM history WHERE action < 3276800 AND action >= 800
sickbeard.log.2-Apr-08 18:07:31 WARNING MAIN :: DB error: database is locked

2nd attempt:
sickbeard.log.2:Apr-08 18:09:35 INFO MAIN :: [3/4] Updating history to reflect the correct action...
sickbeard.log.2-Apr-08 18:09:35 DEBUG MAIN :: sickbeard.db: SELECT * FROM history WHERE action < 3276800 AND action >= 800
sickbeard.log.2-Apr-08 18:13:51 INFO MAIN :: Signal 15 caught, saving and exiting...

(I shut it down after a couple of minutes)

Then I modfied it a bit (basically reverted to the previous version and added logging):

Apr-08 18:31:11 DEBUG MAIN :: sickbeard.db: SELECT * FROM history WHERE action/100 < 32768 AND action/100 >= 8
Apr-08 18:31:11 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3202, 71663, 20121011182046L]
Apr-08 18:31:12 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 71663, 20121011184646L]
Apr-08 18:31:12 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 71663, 20121011191146L]
Apr-08 18:31:12 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3202, 75734, 20121011191659L]
Apr-08 18:31:13 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 71663, 20121011193721L]
Apr-08 18:31:13 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 75734, 20121011194127L]
Apr-08 18:31:14 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 71663, 20121011194736L]
Apr-08 18:31:14 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 75734, 20121011194851L]
Apr-08 18:31:14 DEBUG MAIN :: sickbeard.db: UPDATE history SET action = ? WHERE showid = ? AND date = ? with args [3204, 71663, 20121011195134L]

Seems like some IDs are repeated a lot?

Here's a quick count:
grep "sickbeard.db: UPDATE history SET action =" * | wc -l
18258

For comparison: Here's the stats at the bottom of the my SickBeard page: 57 shows (17 active) | 2893/5264 episodes downloaded

Hope that helps!

PS: Using the synology package as well, if that changes anything :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
for cur_entry in historyAction:
- self.connection.action("UPDATE history SET action = ? WHERE showid = ? AND date = ?", [self._update_status(cur_entry["action"]), cur_entry["showid"], cur_entry["date"]])
+ ql.append(["UPDATE history SET action = ? WHERE showid = ? AND date = ?", [self._update_status(cur_entry["action"]), cur_entry["showid"], cur_entry["date"]]])
+ self.connection.mass_action(ql)
# update previous history so it shows the correct quality
+ logger.log(u"[4/4] Updating history to reflect the correct quality...", logger.MESSAGE)
+ ql = []
historyQuality = self.connection.select("SELECT * FROM history WHERE quality < 32768 AND quality >= 8")
for cur_entry in historyQuality:
- self.connection.action("UPDATE history SET quality = ? WHERE showid = ? AND date = ?", [self._update_quality(cur_entry["quality"]), cur_entry["showid"], cur_entry["date"]])
+ ql.append(["UPDATE history SET quality = ? WHERE showid = ? AND date = ?", [self._update_quality(cur_entry["quality"]), cur_entry["showid"], cur_entry["date"]]])
+ self.connection.mass_action(ql)
self.incDBVersion()
+
+ # cleanup and reduce db if any previous data was removed
+ logger.log(u"Performing a vacuum on the database.", logger.DEBUG)
+ self.connection.action("VACUUM")
View
46 sickbeard/db.py
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
-from __future__ import with_statement
+from __future__ import with_statement
import os.path
import re
@@ -66,6 +66,50 @@ def checkDBVersion(self):
else:
return 0
+ def mass_action(self, querylist, logTransaction=False):
+
+ with db_lock:
+
+ if querylist == None:
+ return
+
+ sqlResult = []
+ attempt = 0
+
+ while attempt < 5:
+ try:
+ for qu in querylist:
+ if len(qu) == 1:
+ if logTransaction:
+ logger.log(qu[0], logger.DEBUG)
+ sqlResult.append(self.connection.execute(qu[0]))
+ elif len(qu) > 1:
+ if logTransaction:
+ logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG)
+ sqlResult.append(self.connection.execute(qu[0], qu[1]))
+ self.connection.commit()
+ logger.log(u"Transaction with " + str(len(querylist)) + u" query's executed", logger.DEBUG)
+ return sqlResult
+ except sqlite3.OperationalError, e:
+ sqlResult = []
+ if self.connection:
+ self.connection.rollback()
+ if "unable to open database file" in e.message or "database is locked" in e.message:
+ logger.log(u"DB error: " + ex(e), logger.WARNING)
+ attempt += 1
+ time.sleep(1)
+ else:
+ logger.log(u"DB error: " + ex(e), logger.ERROR)
+ raise
+ except sqlite3.DatabaseError, e:
+ sqlResult = []
+ if self.connection:
+ self.connection.rollback()
+ logger.log(u"Fatal error executing query: " + ex(e), logger.ERROR)
+ raise
+
+ return sqlResult
+
def action(self, query, args=None):
with db_lock:

5 comments on commit fb37d33

@MrSmoke

Dunno if its just me, but this update pushed my db version to 13, making sickbeard not start again (as max version is 12)

@thezoggy

that would not be this update. just you.

@heliostatic

I'm using the Synology Package, and I'm having the same issue.

@thezoggy

sounds like you guys used other peoples forks/branches that modified the db schema. revert their changes or start fresh with a new sickbeard.db (or hack db_version down.. but stuff may be broken as we cant predict what other peoples fork/branches may have done to your data)

@heliostatic
Please sign in to comment.
Something went wrong with that request. Please try again.