• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Back with weird problems: PK generation keeps generating same PK... up to a moment.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Back with weird problems: PK generation keeps generating same PK... up to a moment.


  • Subject: Back with weird problems: PK generation keeps generating same PK... up to a moment.
  • From: OC <email@hidden>
  • Date: Tue, 12 May 2015 22:56:50 +0200

Hello there,

my application, among others, generates and stores audit records. The appropriate code is comparatively straightforward; it boils down to something like

===
... ec might contain unsaved objects at this moment ...
DBAudit audit=new DBAudit()
ec.insertObject(audit)
audit.takeValuesFromDictionary(... couple of plain attributes ...)
for (;;) { // see below the specific situation which causes a retry
  try {
    ec.saveChanges()
  } catch (exception) {
    // EC might contain an object which needs a sequentially numbered attribute
    // it should be reliable through all instances
    // there is a DB unique constraint to ensure that
    // the constraint exception is detected and served essentially this way:
    if (exceptionIsNotUniqueConstraint(exception)) throw exception
    SomeClass culprit=findTheObjectWhichCausedTheUniqueException(ec,exception)
    culprit.theSequentialNumber++
    // and try again...
  }
}
===

It might be somewhat convoluted way to solve that (though I am afraid I can't see any easier), but it worked for many months, about a zillion times without the exception, sometimes with the exception and retry, always without the slightest glitch.

Then it so happened that

- the EC indeed did contain an object with wrong (already occupied) sequential number
- a DBAudit with PK=1015164 was inserted
- first time saveChanges did throw and the transaction was rolled back; the second time (with incremented sequential number) it saved all right.

So far so good, this did happen before often and never led to problems.

This time though it did. The next time the above code was performed (no sequentials, just the audit), the newly created audit was assigned _again_ PK=1015164! Of course it failed. Well, we thought, perhaps there's some ugly mess inside the EO stack; let's restart the application!

After restart, the very first time the above code was called -- which is pretty soon -- it happened again: regardless there was properly saved row with PK=1015164 in the DB, EOF again assigned the same PK to the newly created EO. I've tried it about five times (at first I did not believe my eyes), it behaved consistently: restart, first time a DBAudit is created, it gets PK=1015164 and saving (naturally) fails.

Then I've prepared a version with extended logs; for start, I've simply added a log of audit.permanentGlobalID() just before saveChanges.

It worked without a glitch, assigning (and logging) PK=1015165, and (naturally) saving without a problem.

I have immediately stopped the app, returned to the original version -- the one which used to consistently fail -- and from that moment on, it worked all right too, assigning PK=1015166, and then PK=1015167, and so forth, as it should. Without a need to log audit.permanentGlobalID() first.

Well. Gremlins?

Might perhaps anyone have the slightest glitch of an idea what the b. h. might have been the culprit, and how to prevent the problem to occur again in the future?

Thanks a lot,
OC


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Back with weird problems: PK generation keeps generating same PK... up to a moment.
      • From: Chuck Hill <email@hidden>
  • Prev by Date: Re: WebObjects Caching Proxy
  • Next by Date: Re: Back with weird problems: PK generation keeps generating same PK... up to a moment.
  • Previous by thread: Re: Help finding framework dependencies
  • Next by thread: Re: Back with weird problems: PK generation keeps generating same PK... up to a moment.
  • Index(es):
    • Date
    • Thread