Re: Cleaning up after manual Core Data migration
Re: Cleaning up after manual Core Data migration
- Subject: Re: Cleaning up after manual Core Data migration
- From: Jerry Krinock <email@hidden>
- Date: Fri, 12 Sep 2014 00:16:33 -0700
On 2014 Sep 11, at 15:38, Rick Mann <email@hidden> wrote:
> The problem is, I now have to specify the destination URL explicitly, and I'm not able to give it the source URL. So, I create a new sqlite data file, and that's fine. But the old sqlite DB actually has three files (DB.sqlite, DB.sqlite-shm, DB.sqlite-wal),
These will explain to you what those pesky -shm and -wal files are:
https://developer.apple.com/library/prerelease/ios/qa/qa1809/_index.html
http://www.sqlite.org/wal.html
However reverting to legacy rollback journaling with heavyweight migration needs a workaround due to Apple Bug 16038419:
http://openradar.appspot.com/radar?id=5784482221129728
and it may be too late for that anyhow if you have data already in the field.
> so when I swap the new and old files after the migration completes, there's still leftover sqlite metadata in the form of these additional files,
Those -shm and -wal files may contain actual data, not just metadata.
> and SQLite thinks the newly migrated DB is corrupt.
without the -shm and -wal files, it probably *is* corrupt.
> I can, of course, just delete these additional files,
I don’t think so.
> but it's an implementation detail I'd rather not put in my code. Am I overlooking some more elegant way to update the on-disk files?
According to http://www.sqlite.org/wal.html, "A checkpoint operation takes content from the WAL file and transfers it back into the original database file”. You can do this with sqlite3_wal_checkpoint_v2(). But digging in the database with sqlite behind Core Data’s back is not elegant. You could also copy all three files. Pick whichever way you deem to be least un-elegant :)
I’ve often wondered why SQLite author D. Richard Hipp found it necessary to put the write-ahead log and shared memory in separate files. He must have realized how much pain it was going to cause. But he’s a very smart guy so I presume there is a good reason for it.
If you need to discuss this further, tell us if the app is iOS or OS X, and also is this database a document (UIManagedDocument or NSPersistentDocument)?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden