Core Data: Updating max pk failed

2020-05-09 18:01发布

问题:

I have a cocoa app which uses core data. Everything seems to be working fine.

However, in a very specific scenario the app was behaving very strangely for our client.

In particular the logs shows this appearing in the output many times (which I've never seen in my testing):

Core Data: annotation: -executeRequest: encountered exception = Updating max pk failed:  with userInfo = {
NSSQLiteErrorDomain = 14;
}

Has anyone ever seen this message and do you know what it means? I've tried googling it but found no information other than a few message boards regarding the Growl app having similar problems, with no solution yet available.

Sorry that I can't be more specific regarding what causes this as I'm not even sure myself. I know how to reproduce this on the client's machine but this message seems very random.

I was hoping someone could give me some more information as to what this error means exactly so that I can maybe narrow it down some more. Right now I'm pretty clueless.

Note: This appears on a macbook pro running 10.7.2 (if that matters).

Thanks for any kind of help you can provide, even something vague would help me at this point.

Update:

The managed context "save" method also fails with the following error:

The operation couldn’t be completed. (Cocoa error 134030.)

回答1:

This is not really a Core Data problem as such, but more an issue of you process running out of file descriptors.

Each process has a limited number of file descriptors. If you run out, Core Data (and many other things) will stop working, because they can no longer open files -- any they'll fail.

First of all, make sure you're not leaking file descriptors, i.e. make sure you close files when you no longer need them.

I'm not sure what kind of changes you're trying to track. Take a look at Tracking File-System Changes.

If you're on 10.7, take a look at dispatch sources and DISPATCH_SOURCE_TYPE_VNODE for a very powerful tool to track file system changes (corresponds to kqueue, but is easier to use).



回答2:

Core Data also gives this error in a Sandboxed app when it tries to save DB to a location where it doesn't have full read/write access to (if a user opens file for example, Core Data will be able to read/write this file, but not anything else to the same folder).

Core Data fails to write the temporary _journal file to this folder and reports this error.