Sunday, April 20, 2008

The mystery of the double emails

Since the last upgrade, the OpenSkills membership management system (MMS) has been sending out double email messages to some people in some cases.

Here's why:

The objects that make the MMS tick are Actions. There are actions for checking email addresses, confirming OpenPGP keys, checking account status ... in short everything that needs doing in the background is done by an Action object. Each action, when completed, can be followed by one or more other actions and these are held by each Action in a Set called responseActions.

The start of the trouble was that for older version of the MMS I needed an implementation of the messages "=" and "hash" for Actions to help with using a relational database as the primary persistence mechanism when reading responseActions back in.

Now that the MMS runs in the GemStone OODB, the "=" and "hash" are no longer needed (because the database understands object identity) ... but the methods were still there. To add a little spice note that the "=" and "hash" methods were based on the external ID of the action and the identity of the class of the action (there are many many kinds of, and thus classes of, Action).

Now we move forward to the last MMS upgrade which involved a schema migration within GemStone. At the point in time that the upgrade was in progress there were two Action classes in existence, the old one and the new one.

... and through a mix up with a time machine, class versions, hash and = and a schema migration some actions ended up with duplicate actions in their responseActions.

To use one concrete example to explain what happens next: Each account review action adds itself as a responseAction (since reviews automatically happen). In the broken case each account review had two instances of itself in the responseActions Set (oh, yes). This meant that for those cases the same account review messages were sent out twice. Every time.

The fix was to make responseActions an IdentitySet, remove the "=" and the "hash" methods from Action and run a quick fix script to have every action rebuild it's response actions. All fixed now.

And sorry to those people who have suffered from the mysterious double emails.

No comments: