Thanks Chuck and Robert. I'm currently catching, reverting and otherwise ignoring the exception being thrown. I just didn't know if there was anything else I should have been doing. I appreciate your time and help on this issue.
- Eric On 12/2/05, Chuck Hill <[EMAIL PROTECTED]> wrote: > Eric, > > As far as I know there is only one certain way to do this: > > 1. Add a unique constraint on descriptor in NewKeyword in the DB if > you don't have one already > 2. Keep the existing checks in place as they will catch much of the > attempts at duplication > 3. When a NewKeyword is saved, wrap the call to saveChanges() in an > try...catch and catch EOGeneralAdaptorException > 4. When you get an EOGeneralAdaptorException, inspect it to see if it > is a violation of the unique constraint. If so, revert the EC and go > on your way. > > Also, noticed that you checking for duplicates below only in > NewKeywords and not also in the existing ones. You have probably > handled that elsewhere, but I thought I would mention it. > > > Regards, > Chuck > > > On Dec 2, 2005, at 11:01 AM, Eric Stewart wrote: > > > Chuck, > > > > You are right on all accounts. > > > > Here's a little broader understanding of the system. It's a content > > finder, storage and retrieval system based on keywords. A client (a > > client in general terms not Java client, be it browser or other > > script) queries the system using a URL with the keyword in it (which > > hits a direct action). The system then tries to reply with whatever > > content it knows about that keyword. > > > > If the system has never seen the keyword, it is then stored in a > > "NewKeyword" table which is basically operating as a stack for finding > > content for keywords it's not aware of. Once an hour another > > application is fired off via cron and a direct action which then > > starts popping keywords out of the new keyword table, finds content > > for them via spidering and saves the keyword and data into the > > permanent keyword store tables. Then the system will be able to > > provide content for that particular keyword from that point on. > > > > This system has over 4.5 million keywords and recieves on average 2 > > million request a day. > > > > But as I said, some sort of race condition is happening. I can't > > figure out how to only make sure a new keyword isn't entered into the > > new keyword table more than once. > > > > - Eric > > > > On 12/2/05, Chuck Hill <[EMAIL PROTECTED]> wrote: > >> Hi Eric, > >> > >> I am not sure that I am following this correctly, so some questions > >> below. > >> > >> > >> On Dec 2, 2005, at 8:26 AM, Eric Stewart wrote: > >> > >>> Hello everyone, > >>> > >>> I'm having a problem where it appears I'm getting stale data from > >>> the > >>> editing context. > >>> > >>> I have a direct action that is inserting keywords into a database > >>> table. The word itself (called "descriptor") is unique because I > >>> don't > >>> want the same keyword in the system twice. > >>> > >>> When a direct action request comes in for information about that > >>> keyword, I check to see if that keyword is already in the system. If > >>> not I add it. > >>> > >>> Here is the code I use to check for that keyword. > >>> > >>> /** > >>> * Determines whether a new keyword with the given > >>> descriptor is > >>> present in the system. > >>> */ > >>> public static boolean isPresentByDescriptor > >>> (EOEditingContext ec, > >>> String descriptor) { > >>> NSDictionary args = new NSDictionary(descriptor, > >>> "descriptor"); > >>> EOQualifier qual = > >>> EOQualifier.qualifierToMatchAllValues(args); > >>> EOFetchSpecification fs = new EOFetchSpecification > >>> ("NewKeyword", > >>> qual, null); > >>> > >>> // Make sure we fetch fresh data > >>> fs.setRefreshesRefetchedObjects(true); > >>> > >>> // Find the keyword matching value > >>> NSArray keywords = ec.objectsWithFetchSpecification > >>> (fs); > >>> if (keywords.count() == 0) { > >>> // No match found > >>> return false; > >>> } else if (keywords.count() > 1) { > >>> // More than one match found > >>> if (NSLog.debugLoggingAllowedForLevel > >>> (NSLog.DebugLevelCritical)) { > >>> NSLog.debug.appendln("Duplicate new > >>> keyword found matching: " + > >>> descriptor); > >>> } > >>> return true; > >>> } else { > >>> // Match found return the keyword > >>> return true; > >>> } > >>> } > >>> > >>> What is happening is I'm getting a lot of exceptions complaining > >>> that > >>> a keyword being added to the system is not unique, hence I can only > >>> guess that data from the EC is stale and is not reflecting newly > >>> inserted keywords. > >>> > >> By exception do you mean the debug message above, a unique constraint > >> violation on the database, or something else? > >> > >> > >> > >>> This direct action is running on an application that has around 20 > >>> instances running. So some how one of the other instances is > >>> inserting > >>> a new keyword and the other instances continue to report it as not > >>> being there. > >>> > >> > >> You could have a race condition where two instances check the > >> database for the same keyword, and see that it is not there. They > >> they both insert it. The second one to commit will (attempt to) > >> duplicate the value in the database. Is that what you are seeing? > >> You can even see this on a single instance if you are dispatching > >> requests concurrently. > >> > >> > >>> Should I be using EditingContext.refaultAllObjects() or will this > >>> not > >>> solve my problem. What I don't want to happen is for this to > >>> severely > >>> degrade the performance of the application. I think I remember > >>> EditingContext.invalidateAllObjects() causing a pretty poor > >>> performance on high load applications, which this is. Is there some > >>> other way to check whether the keyword is in the system or not > >>> before > >>> it's added without incurring such a severe penalty? > >>> > >> I would not suggest any of those solutions. Are the instances > >> actually changing the descriptor of NewKeywords, just only inserting > >> new ones? If they are only inserting new ones, there should not be > >> an issue with actual stale data the way you are fetching it. I > >> suspect your problem may lie elsewhere. > >> > >> > >>> Is there anyway to refault JUST the data in a certain table or of a > >>> certain type of EO and not all the data in an EditingContext. > >>> > >> You can do it object by object, but again, that does not seem to be > >> the problem (or I am misunderstanding your situation). > >> > >> Chuck > >> > >> -- > >> Coming in 2006 - an introduction to web applications using WebObjects > >> and Xcode http://www.global-village.net/wointro > >> > >> Practical WebObjects - for developers who want to increase their > >> overall knowledge of WebObjects or who are trying to solve specific > >> problems. http://www.global-village.net/products/ > >> practical_webobjects > >> > >> > >> > >> > >> > > > > -- > Coming in 2006 - an introduction to web applications using WebObjects > and Xcode http://www.global-village.net/wointro > > Practical WebObjects - for developers who want to increase their > overall knowledge of WebObjects or who are trying to solve specific > problems. http://www.global-village.net/products/practical_webobjects > > > > > _______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to archive@mail-archive.com