Skip to content

Commit

Permalink
deal with multiple concurrent writers, when graph does not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
swilly22 committed Feb 10, 2019
1 parent eb04ee5 commit 6339970
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/commands/cmd_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,23 @@ void _MGraph_Query(void *args) {
// Try to access the GraphContext
CommandCtx_ThreadSafeContextLock(qctx);
GraphContext *gc = GraphContext_Retrieve(ctx, qctx->graphName);
CommandCtx_ThreadSafeContextUnlock(qctx);

if(!gc) {
if (!ast->createNode && !ast->mergeNode) {
if(!ast->createNode && !ast->mergeNode) {
CommandCtx_ThreadSafeContextUnlock(qctx);
RedisModule_ReplyWithError(ctx, "key doesn't contains a graph object.");
goto cleanup;
}
assert(!readonly);

CommandCtx_ThreadSafeContextLock(qctx);
gc = GraphContext_New(ctx, qctx->graphName, GRAPH_DEFAULT_NODE_CAP, GRAPH_DEFAULT_EDGE_CAP);
CommandCtx_ThreadSafeContextUnlock(qctx);

if (!gc) {
if(!gc) {
CommandCtx_ThreadSafeContextUnlock(qctx);
RedisModule_ReplyWithError(ctx, "Graph name already in use as a Redis key.");
goto cleanup;
}
/* TODO: free graph if no entities were created. */
}
}
CommandCtx_ThreadSafeContextUnlock(qctx);

// Perform query validations before and after ModifyAST
if (AST_PerformValidations(ctx, ast) != AST_VALID) goto cleanup;
Expand Down

0 comments on commit 6339970

Please sign in to comment.