[Developers] multiple create unless_exists in one query
Kurt Bollacker
kurt at metaweb.com
Thu Dec 20 16:51:18 UTC 2007
On Thu, Dec 20, 2007 at 07:53:46AM -0800, Arthur van Hoff wrote:
> Hi JG,
>
> The problem is a I have a complex write query that writes Internet Radio
> streams which each have a stream format, which are often the same. I ran
> into a case where the same stream format got created multiple times. I
> could not figure out how that could happen until I realized that this
> can happen if you create multiple new objects with the same name in the
> same query even when using "create":"unless_exists". In my opinion this
> is a bug.
>
> It will be very difficult to ensure that all child objects exist before
> I use "create":"unless_exists" (and it kind of defeats the purpose). I
> would rather have it create one object and have any subsequent
> "create":"unless_exists" in the same query refer to the newly created
> object.
It is fair to say that their ought to be an easy and obvious way to
handle multiple inserts (in the same query) of the same topic.
However,currently it is My understanding is that in processing a MQL
query envelope, all verifying reads (e.g. does foo2 exist?) are done
before any writes are done. Thus, you can't count on dependencies
between queries in the same envelope being satistfied. If you want to
avoid dependency problems, you can break your writes into simpler
query envelopes. I give the mod to your example below. In your
earlier example, just perform the sub-query inserts as their own
query.
This is not perfect, but it will work, and should not affect
performance significantly.
Kurt :-)
> Below is an even simpler example that illustrates the problem using
> "create":"unless_exists" at the top level. It creates multiple foo2s if
> no foo2 existed. Perhaps this can be fixed so that both cases produces a
> single foo2, which seems the most natural outcome.
>
> "query": [{
> "type": "/user/avh/default_domain/foo",
> "name": "foo2",
> "create":"unless_exists",
> "id":null
> },{
> "type": "/user/avh/default_domain/foo",
> "name": "foo2",
> "create":"unless_exists",
> "id":null
> }]
Just do this query twice:
{
"query" : {
"create" : "unless_exists",
"id" : null,
"name" : "foo002",
"type" : "/user/avh/default_domain/foo"
}
}
1st RESULT:
{
"code" : "/api/status/ok",
"result" : {
"create" : "created",
"id" : "/guid/9202a8c04000641f8000000006e601c3",
"name" : "foo002",
"type" : "/user/avh/default_domain/foo"
}
}
2nd RESULT:
{
"code" : "/api/status/ok",
"result" : {
"create" : "existed",
"id" : "/guid/9202a8c04000641f8000000006e601c3",
"name" : "foo002",
"type" : "/user/avh/default_domain/foo"
}
}
More information about the Developers
mailing list