Is it really wrong to version documents using CouchDB's default behaviour?

前端 未结 2 766
悲&欢浪女
悲&欢浪女 2021-01-19 02:43

This is one of those \"I know I shouldn\'t do this but it\'s oh so convenient.\" questions. Sorry about that.

I plan to use CouchDB for storing a bunch of documents

2条回答
  •  既然无缘
    2021-01-19 03:35

    If it's wrong, then I don't want to be right!

    Actually, no. It's wrong. Michael explained it well: best case scenario it makes your app very not future-proof, and worst-case you will get bad bugs that force you to re-architect at an inconvenient time.

    Consider Google App Engine. What is their suggested transaction pattern?

    1. Begin transaction
    2. Fetch your entities by key
    3. Modify entities and save them
    4. End transaction

    These form a function which re-runs if the transaction fails. Why? And why must fetch be within the transaction instead of hanging around in an outer scope?

    Because App Engine uses MVCC internally. If you get a collision (your revision is wrong because somebody else updated), then they just re-run your function. The next iteration will fetch the newer revision, update from the newer data, and re-put with a correct revision. The point is, Google does not expose this to users because it is not a suitable framework to build application-level versioning.

提交回复
热议问题