Transactions: If I mutate a field of a node, will only the field get locked, or the whole node?

Mutations in dgraph are transactional. If I mutate a field of a node, will only the field get locked, or the whole node?

The database does not really ‘lock’ but any other mutations to that predicate (field) and value (depending on @noconflict and @upsert flags) that happen between readTS and commitTS will be aborted and need to be retried.

1 Like

thanks a lot buddy! one more last side question:

If I create 19000 nodes within one milliesecond, and all these 19000 nodes have a n:n edge to one single specific node;

Will that make a concurrency error? or will that work without any problem?

An edge from node A to node B is just a property of node A. So assuming you have the default settings for this edge predicate, it will just be like setting a value on a bunch of unrelated nodes. It also matters what your insert pattern is (upsert mutation, @upsert annotation on predicate, blind writes). If you read a unrelated field to make the connection (eg: xid) then that could cause an abort if it changes.

I also assume you mean from 19000 different connections concurrently, as opposed to one transaction which you could do all of these in and definitely avoid any transaction aborts.

1 Like

Thanks a lot!! I thought that there might be complications because the relationships are inversive, so that basically means dgraph would write under the hood 19000 edges to that single specific node

type Hashtag {
    ...
    posts: [Post] @hasInverse(field: hashtags)
}
type Post {
    ...
    hashtags: [Hashtag] @hasInverse(field: posts)
}

/// yes correct I mean 19000 different connections concurrently

so there won’t be any problems?

Um one caveat: I thought you were talking about DQL since you didn’t have the GraphQL badge on your topic. I don’t know much of what the GraphQL layer will do.

1 Like