Since it's very difficult, if not impossible, to guarantee the atomicity of any
action in a distributed system like Riak, you are very limited in your options.
1) Use an RDBMS. Since you're here, I'm guessing that you're already using Riak
or else that Riak has qualities that you want for your application.
2) As Alex suggests, you can implement this in your application. This could
also be difficult: the application must be aware of activity going on with
objects in your database AND be able to roll them back. In pseudocode you'd do
this:
orig = Riak.get('whatevs')
child = new Child(orig)
if Riak.put(child)
if !Riak.link(orig, child)
Riak.delete(child)
// error up the stack
else
// we don't care, the child didn't save. error up the stack
This is probably naive and is definitely tedious, even if you do implement your
own application layer to handle read/write operations.
3) Pre-Commit hooks. I don't recall if you are allowed to modify other keys in
a pre-commit hook, nor do I recall if it's a horrible idea, but it's always
something you can look into.
---
Jeremiah Peschka - Founder, Brent Ozar PLF, LLC
Microsoft SQL Server MVP
On Oct 28, 2011, at 6:28 PM, Alexander Sicular wrote:
> This would have to be implemented in application space... Or an rdbms that
> supports acid. Maybe a combination of the two.
>
> @siculars
> http://siculars.posterous.com
>
> Sent from my rotary phone.
>
> On Oct 28, 2011 8:56 PM, "Justin Karneges" <[email protected]> wrote:
> Hi,
>
> Suppose I've got a key A that points to a set of child keys. What's the best
> way to add child key B and update the reference in A, without the DB becoming
> inconsistent in a fail case?
>
> I imagine I want to do:
>
> set B (create the child)
> get A (to fetch the original key set)
> set A (resave A with an updated key set that includes B)
>
> However, if there's a failure applying the changes to A, then I end up with
> this orphaned B key with nobody pointing to it. Should the client try to
> perform a rollback then? That is, if setting A fails then delete B? What if
> there's a failure to delete B? Cron job garbage collectors that delete
> orphaned keys? How can I not make a mess of my DB? :)
>
> I know this is probably a KV 101 question that applies to everything, not just
> Riak, but nothing obvious came up on Google...
>
> Justin
>
> _______________________________________________
> riak-users mailing list
> [email protected]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
> _______________________________________________
> riak-users mailing list
> [email protected]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com