Specialize type upon content creation within behaviour can result in invalid version history

A customer today reported a problem where version history was not what you would expect between the 1.0 and the 1.1 versions in Alfresco Share. A bit of background history to start with:

As soon as content is dropped into a site, it will get its type changed to rl:customType. This type adds a new properties such as rl:documentNumber and others. The rl:documentNumber is generated for all new content added to the site. All this is done in a behaviour listening at onCreateNode on Transaction commit.

@Override
public void afterPropertiesSet() throws Exception {
	super.afterPropertiesSet();
	Assert.notNull(policyComponent);
	if (!isInitialized()) {
	  if (LOG.isTraceEnabled())
	    LOG.trace("Initialized " + this.getClass().getName());
	  policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, ContentModel.TYPE_CONTENT, new JavaBehaviour(this, "onCreateNode", NotificationFrequency.TRANSACTION_COMMIT));
	}
}

The problem that appeared when a version 1.1 was created through editing the uploaded document. When browsing the version history you could see that the 1.0 version did not have a rl:documentNumber set, however, the 1.1 version did. So the conclusion was that the version 1.0 was actually created before transaction commit in the version store. If this is a feature or a bug, I don’t know, but the solution is simple. In your behaviour, bind on the first event instead of transaction commit as this will correctly make sure that everything written to the node in the behaviour also ends up in the versioning history.

@Override
public void afterPropertiesSet() throws Exception {
	super.afterPropertiesSet();
	Assert.notNull(policyComponent);
	if (!isInitialized()) {
	  if (LOG.isTraceEnabled())
	    LOG.trace("Initialized " + this.getClass().getName());
	  policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, ContentModel.TYPE_CONTENT, new JavaBehaviour(this, "onCreateNode", NotificationFrequency.FIRST_EVENT));
	}
}
This entry was posted in Alfresco, Behaviours, Version History. Bookmark the permalink.

82 Responses to Specialize type upon content creation within behaviour can result in invalid version history

  1. Axel Faust says:

    Hello Marcus,

    this is neither a feature nor a bug, just a misunderstanding of how auto-versioning works. Auto-versioning IS a TRANSACTION_COMMIT level behaviour and you can never guarantee that your custom TRANSACTION_COMMIT level behaviour will be called before the auto-versioning behaviour.
    In my point-of-view, TRANSACTION_COMMIT should be a highly discouraged notification frequency. We almost never use it in our projects, because there are too many pitfalls that developers simply do not consider (e.g. runAs and permission). For me, only EVERY_EVENT is a valid frequency and FIRST_EVENT is virtually useless – for OnCreateNodePolicy EVERY_EVENT and FIRST_EVENT are completely identical because a node can only be created once anyway.

    Regards, Axel

  2. Marcus Svensson says:

    Hi Axel,

    Great input, I had actually not looked into how auto-versioning is implemented.

    Transaction commit is as you say obviously a pitfall when it comes to auto versioning. To bind on transaction commit is used quite commonly among alfresco developers, and this case shows that you cannot blindly bind on transaction commit without understanding the underlying mechanics.

    Regards,
    Marcus

  3. Peter Monks says:

    Axel, the problem with EVERY_EVENT is that it can be called numerous times within a single transaction (a lot more than you might expect), so unless your behaviour logic is fast+in-repository-only (no RPCs, no external data access, etc.) or asynchronous, it’s easy to seriously impact Alfresco’s performance. Compounding this is that some of Alfresco’s access mechanisms (e.g. CIFS) can result in a lot of small Alfresco transactions for every “user transaction”. This quickly becomes a multiplicative problem.

    Personally speaking, I’ve found TRANSACTION_COMMIT behaviours the best compromise between the “uselessness” of FIRST_EVENT and the almost-certain performance penalties of EVERY_EVENT. You then just have to face up to the realities of auto-versioning (if present).

    It’s also worth pointing out that these characteristics of auto-versioning aren’t specific to custom behaviours – there are other ways that these kinds of corner cases can occur (e.g. CMIS).

  4. Axel Faust says:

    Peter:
    I require our devs to include the necessary “early check and bail out”, e.g. checking the affected store and actual change (if a property value has actually been modified or the correct aspect been applied). If you do that, then there is very limited chance of noticable performance penalty, because the actual state transitions that interest you should not occur multiple times in a transaction and also not without user interaction (which would exclude crazy stuff from CIFS et al).
    Unfortunately, I see a lot of people in the community (via their code) that have implemented their behaviours in a very naiive way, assuming only the use case they are working on will trigger the behaviour. Behaviours implemented that way will definitely be obliterated by performance penalties when switching to EVERY_EVENT.

    Behaviours in my point of view should / must almost never include any logic that is reliant on remote data, either external data sources or indices. That should be reserved for jobs or asynchronous actions that may merely be triggered by the behaviour. I have seen few use cases that really require transaction-scoped external data access/import with real-time data consistency.

    My preference for EVERY_EVENT is rooted in the experience that 4 out of 5 behaviour problems in past projects or found in reviews of customer code were due to TRANSACTION_COMMIT and could have easily been avoided. Also 1 in 10 workarounds/patches we have had to code to deal with Alfresco out-of-the-box features in the past were due to Alfresco default behaviours being TRANSACTION_COMMIT – most of the time, this meant auto-versioning (e.g. patches to SPP, versioning hacks for workflow runAsSystem logic).

    • Peter Monks says:

      Yeah early bail is a good strategy in all custom behaviours regardless of notification frequency, although of course those checks still have non-zero costs that get multiplied by the number of times an EVERY_EVENT custom behaviour is triggered. Accessing the node that the event is being triggered for (a common way that bail out logic is implemented) is usually ok (due to caching), but pretty much any repository operation can result in database I/O (especially when Alfresco is under load), so I usually err on the side of caution and assume that even that will be expensive (milliseconds).

      I’ve rarely seen the kinds of issues you’re describing with TRANSACTION_COMMIT, and when I have it’s almost always been due to assumptions about the order in which behaviours are invoked (which are always wrong – behaviour invocation order is non-deterministic). Ensuring that custom behaviours function correctly no matter what state the data is in at the time of invocation goes a long way towards avoiding these problems. This won’t fix issues in Alfresco’s own logic (such as the auto-versioning behaviour), but a support case should always be the first response when that kind of thing is observed.

      I’d suggest that the moral of this story is that the custom behaviours extension point has more subtle complexities than might meet the inexperienced eye, and they should therefore be used sparingly…

  5. Peter Monks says:

    I just remembered a functional limitation of EVERY_EVENT notifications that doesn’t exist for TRANSACTION_COMMIT (I don’t know and haven’t checked how this works for FIRST_EVENT notifications, since I don’t use them).

    The scenario is when a custom behaviour is supposed to veto certain operations – for example vetoing the removal of an aspect from a node if certain conditions aren’t met. A common way to do this (since behaviours don’t have return types to dictate subsequent control flow) is to throw an exception from within the custom behaviour – this should, in theory, bubble up to the logic that handles the enclosing transaction and result in a rollback, thereby achieving the requirement of vetoing the operation.

    It turns out that some (most? all?) of the logic responsible for firing behaviours on EVERY_EVENT swallows any exceptions thrown by custom behaviours, so the veto fails and the operation succeeds when it shouldn’t. This is not the case for TRANSACTION_COMMIT, which will let the exception bubble up and therefore cause the transaction to roll back (i.e. a successful veto).

    As a side note, the error messages in this case aren’t great – that’s an area that could do with improvement imho.

    • Terry says:

      You are right my only child is dead as well as my only sibling, a brother. I’m trying to make it home before taking drastic measures. Thanks so much for your concern and efforts. I am ovelwhermed. Oh how I wish I had a sister to walk with me through this. I feel so utterly alone.

    • Good morning,Your cake looks tempting and must tasted delicious. Definitely must try. We need to take care of ourselves and make exercise a priority. God be with you.

    • http://www./ says:

      Your piece is clever in expressing your pain. Hope all who read it get it. As for my piece, I thank you for your support for I do not think anyone else reads it.

    • You’ve impressed us all with that posting!

    • http://www./ says:

      sorry but i dis agree with all of u guys i think it shoulda uter shirt witha cute skirt and some long shoes tennis with the cuteset tote bag

    • Although… modern remixes do have hidden gems.Remember a bunch of kids on the corner listening to some rap. I stopped and listened for a moment, then nearly hurt myself from laughing. The underlying music was the theme from Knight Rider (the TV show). They had no clue.

    • zangeif is my dude…most ppl would under rate him like a mofo so i mastered that motherfucker then i would move in and immediately put em in a 360 flying pile drive and take over half they power…cats would be mad as shit they got flexed on by zangeif.he used to fight bears, G…BEARS.—————————————————————— A good Chun-Li player or Guile player would break you out of that.

    • Ciao Enrico, ecco qua:In ogni caso nelle prossime settimane posterò un’altra versione ri-adattata grazie ai vostri consigli sulla sicurezza! (sto studiando per voi hihi).

    • Hey TanjaIch habe Dir immer gesagt, dass das was Du machst mir gut gefällt, jetzt hast Du die Bestätigung, das ich da nicht alleine bin mit der Meinung Mach weiter so, ich freue mich immer auf die neuen Layouts, schön das ich Sie meistens auch als erstes zu sehen bekomme Dein Mann

    • You little sweet munchkin have really touched my heart even though I never knew you personally. I was thinking of you so much and then I saw the sad news. May you rest in peace little kitty. You were much loved..

    • elaine24 de fevereiro de 2010Eu paguei 120 e daria todo meu salário só para ver o Franz Ferdinand!! Seja com ou sem área vip, o que eu quero, como fã, é ver o show!! Nem aí para esse pessoal que fala mal da banda, acho que é puuuuura inveja, já que a banda que tanto gostam não tem nenhuma pretensão de pisar em Bsb…!!

    • Destrie says:

      It’s a plarusee to find someone who can think so clearly

  6. datxoichecom says:

    It’s a plarusee to find someone who can think so clearly

  7. Alan says:

    Thank you and your article. They are really good and useful. I hope to have similar articles. Here is my website, give me your comments. Tình Yêu

  8. I wanted to compose you this very little observation to finally thank you once again on the pleasant ideas you have discussed on this site. It has been generous of you to deliver easily what most of us would’ve supplied for an ebook to help with making some cash for themselves, principally seeing that you might well have tried it in the event you wanted. Those good ideas also acted to provide a great way to fully grasp the rest have the same passion much like mine to understand many more concerning this matter. I am sure there are numerous more pleasurable occasions in the future for those who discover your blog.

  9. You, my pal, ROCK! I found exactly the information I already searched everywhere and just couldn at locate it. What an ideal web-site.

  10. Regards for helping out, fantastic information. The laws of probability, so true in general, so fallacious in particular. by Edward Gibbon.

  11. Very good post. I absolutely love this website. Keep writing!

  12. You ave an incredibly nice layout for your blog i want it to use on my website too.

  13. choi da ga says:

    I’m trying to make it home before taking da ga online
    drastic measures. Thanks so much for your concern and efforts.

  14. Wow, great article.Thanks Again. Will read on

  15. Right now it appears like Movable Type is the preferred blogging platform out there right now. (from what I ave read) Is that what you are using on your blog?

  16. twitter ppc says:

    Magnificent web site. Plenty of helpful information here. I am sending it to several buddies ans also sharing in delicious. And certainly, thanks for your sweat!

  17. 부커취 says:

    Looking around While I was surfing yesterday I saw a excellent post about

  18. very good publish, i definitely love this web site, carry on it

  19. Just wanna remark that you have a very decent internet site , I love the design it really stands out.

  20. 관전클럽 says:

    You made some clear points there. I looked on the internet for the issue and found most guys will approve with your website.

  21. Im obliged for the blog.Much thanks again. Will read on

  22. Pinganillos says:

    Muchos Gracias for your post.Really looking forward to read more. Will read on

  23. Dating says:

    Wow, great post.Really thank you! Fantastic.

  24. sure, analysis is paying off. Seriously handy perspective, many thanks for sharing.. Truly handy point of view, many thanks for expression.. Fantastic beliefs you have here..

  25. Im thankful for the article post. Much obliged.

  26. ethereum dex says:

    Merely a smiling visitant here to share the love (:, btw great style and design.

  27. Im thankful for the blog article.Really thank you! Keep writing.

  28. Voyance web arnaque theme astrologique gratuit en ligne

  29. There as certainly a great deal to learn about this issue. I really like all of the points you ave made.

  30. Coco Lee says:

    This is such a great resource that you are providing and you give it away for free. Thank you so much for the post you do.

  31. Shine K says:

    I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.

  32. Queen Pia says:

    Incredible Article it its truly instructive and inventive update us as often as possible with new upgrades. its was truly important. much obliged.

  33. Thank you ever so for you blog article.Really thank you! Cool.

  34. for details says:

    pretty handy material, overall I think this is well worth a bookmark, thanks

  35. It as hard to find experienced people in this particular topic, however, you sound like you know what you are talking about! Thanks

  36. Elise says:

    I wish my web site loaded up as quickly as yours lol

  37. plumber seo says:

    I truly appreciate this article post.Really thank you! Want more.

  38. This can be a set of words, not an essay. you will be incompetent

  39. Louis Vuitton Purses Louis Vuitton Purses

  40. Rumor- bag Can Have A Main role In Almost Any Organization

  41. matka 420 says:

    Im thankful for the article.Thanks Again. Really Great.

  42. matka 420 says:

    Thanks for sharing, this is a fantastic article post.Really thank you! Fantastic.

  43. Thanks , I ave recently been looking for info about this subject for ages and yours is the best I have discovered till now. But, what about the bottom line? Are you sure about the source?

  44. is written by him as nobody else know such detailed about my problem.

  45. I reckon something truly special in this web site.

  46. Only a few blogger would discuss this topic the way you do.,:

  47. click here says:

    Very interesting information!Perfect just what I was looking for! аЂа‹аЂ Washington is the only place where sound travels faster than light.аЂ аЂа› by C. V. R. Thompson.

  48. to read more says:

    Thank you ever so for you blog post.Really looking forward to read more. Awesome.

  49. You are my breathing in, I possess few web logs and rarely run out from to brand.

  50. What would you like to see out of a creative writing short story?

  51. Đăng ký thành viên tại trang dagatructiep79.com có cơ hội nhận ngay 3.000.000 đồng tiền mặt. Mừng thành viên mới khuyến mãi khủng 125% lần nạp đầu tiên. Ngoài ra còn các chương trình khác như: mừng sinh nhật thành viên mới tặng 2.500.000 đồng.

  52. There is certainly a lot to find out about this topic. I like all of the points you made.

  53. Precisely what I was looking for, thanks for posting.

  54. There is certainly a great deal to know about this topic. I like all the points you made.

  55. great website always enjoy

  56. Thankѕ for sharing your thoughts. I truly appreciate you efforts and
    I will be waiting for your further write uᥙps thank you once
    again.

  57. toto365 says:

    To a great degree wonderful and entrancing post. I was hunting down this kind of information and had a great time examining this one.

  58. oncasino says:

    This is an awesome article, Given such an extraordinary measure of data in it, These sort of articles keeps the customers excitement for the site, and keep sharing more … favorable circumstances.

  59. Thanks You Good Blog

  60. magosucomwep says:

    One of the journeys a few authorities embrace is to attempt to locate their ideal cannabis seed. Each unique strain holds an alternate arrangement of characteristics which will join to give you the ideal seed that coordinates your taste.
    인터넷경마
    magosucowep

  61. Thanks For Sharing Information, I really Like Your Blog. Its Really Helpful For me And Please Keep Posting..

  62. racesitepro says:

    This is a great inspiring article.I am pretty pleased with your good work

  63. reelgamesite says:

    Great blog, thank you so much for sharing with us.

  64. I appreciate your post thanks for sharing the information.

Leave a Reply to situs judi terpercaya Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>