Comments (7)
It seems that the new Write-Ahead-Logging (WAL) of IOS 7 is causing problems because it splits up the sqlite database in 3 files:
- persistentStore.sqlite
- persistentStore.sqlite-wal
- persistentStore.sqlite-shm
I tried to disable it with this option but it still creates 3 files:
NSDictionary *options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} };
Any suggestion?
from ticoredatasync.
How do you build the Core Data stack?
from ticoredatasync.
Here how I build the Core Data stack, even if I set up the option "NSDictionary *options = @{NSSQLitePragmasOption:@{@"journal_mode":@"DELETE"}};" it still creates 3 files. Reading the specification of the WriteAheadLogging (https://www.sqlite.org/wal.html) the original content is preserved in the database file and the changes are appended into the separate WAL file, so when I launch the app for the first time the Core Data Stack is build, the persistentStore.sqlite is created but it's empty and every time I add, delete or modify a record, changes are stored in the persistentStore.sqlite-wal file. So when I upload the Whole Store this is always empty:
#pragma mark - Core Data stack
// Returns the managed object context for the application.
// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
- (NSManagedObjectContext *)managedObjectContext
{
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return _managedObjectContext;
}
// Returns the managed object model for the application.
// If the model doesn't already exist, it is created from the application's model.
- (NSManagedObjectModel *)managedObjectModel
{
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppName" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
// Returns the persistent store coordinator for the application.
// If the coordinator doesn't already exist, it is created and the application's store added to it.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"persistentStore.sqlite"];
/* Add the check for an existing store here... */
if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path] == NO) {
self.downloadStoreAfterRegistering = NO;
}
NSError *error = nil;
NSDictionary *options = @{NSSQLitePragmasOption:@{@"journal_mode":@"DELETE"}};
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
return nil;
}
return _persistentStoreCoordinator;
}
from ticoredatasync.
It seems that the error was here because I didn't previuosly set the pragmaOptions also here but just in the main Core Data Stack:
- (void)documentSyncManager:(TICDSDocumentSyncManager *)aSyncManager didReplaceStoreWithDownloadedStoreAtURL:(NSURL *)aStoreURL{
NSError *anyError = nil;
NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];
[pragmaOptions setObject:@"delete" forKey:@"journal_mode"];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
pragmaOptions, NSSQLitePragmasOption,
nil];
id store = [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:aStoreURL options:options error:&anyError];
if (store == nil) {
NSLog(@"Failed to add persistent store at %@: %@", aStoreURL, anyError);
}
}
from ticoredatasync.
So did this remove the error for you?
Also, you can simplify your dictionary notation now in Objective-C:
NSDictionary *options = @{ NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES, NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" } };
I find the new notation much easier to read and understand as well.
from ticoredatasync.
It seems that WAL has been completely switched off but I'll make more tests tomorrow to confirm that, maybe it should be added to the documentation since WAL is ON by default in iOS7. I'll also simplified the dictionary notation as you suggested and it's ok, much easier to read, thanks.
from ticoredatasync.
I confirm I removed the problem as I told above, so summarizing it I had to set the pragmaOptions both in the Core Data stack and in the didReplaceStoreWithDownloadedStoreAtURL delegate method.
from ticoredatasync.
Related Issues (20)
- Synchronizing devices after a crash (or new devices). HOT 1
- Undoing added objects HOT 1
- Downloading the list of available documents in NSEventTrackingRunLoopMode HOT 2
- Integrating TICoreDataSync with Cocoapds
- New Device does not getting latest data since CoreData Model Update. HOT 1
- How to reset all Sync data to get a clean whole store upload? HOT 6
- Downloading current document's data after deleting local file HOT 5
- Avoid sync of some elements HOT 1
- Impossible to register new clients for existing database in Dropbox HOT 1
- Excessive memory usage when applying numerous change sets HOT 4
- Property attributes warnings HOT 7
- TICoreDataSync first run and sync loop HOT 6
- documentSyncManagerDidFinishSynchronizing executed 2 times HOT 6
- Mac client and managedObjectContext changes not reflected to arrayController HOT 1
- (503) Rate limiting oauth_accesses_per_access_token HOT 1
- kTICDSClientDeviceIdentifier and ClientDevices directory
- iCloud branch behind a few commits
- TICDSLog() unsafe
- TICDSDropboxSDKBasedPreSynchronizationOperation's failedDownloadRetryDictionary uses different keys
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ticoredatasync.