Skip to content

Commit

Permalink
Deleted entity access (#3163)
Browse files Browse the repository at this point in the history
* initial tests

* error when returning a deleted entity

* read only access to deleted entities

* address PR comments
  • Loading branch information
swilly22 committed Aug 22, 2023
1 parent 446ac5e commit 5183395
Show file tree
Hide file tree
Showing 63 changed files with 699 additions and 175 deletions.
16 changes: 16 additions & 0 deletions src/RG.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
#include <stdbool.h>
#include "redismodule.h"

//------------------------------------------------------------------------------
// common bitwise operations
//------------------------------------------------------------------------------

// Mask with most significant bit on 10000...
#define MSB_MASK (1UL << (sizeof(uint64_t) * 8 - 1))

// Mask complement 01111...
#define MSB_MASK_CMP ~MSB_MASK

// Set X's most significant bit on.
#define SET_MSB(x) (x) | MSB_MASK

// Clear X's most significant bit.
#define CLEAR_MSB(x) (x) & MSB_MASK_CMP

//------------------------------------------------------------------------------
// code development settings
//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/aggregate_funcs/agg_precentile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "RG.h"
#include "agg_funcs.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../errors/errors.h"
#include <math.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/arithmetic_expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "../RG.h"
#include "funcs.h"
#include "rax.h"
#include "../errors.h"
#include "../util/arr.h"
#include "../query_ctx.h"
#include "../graph/graph.h"
#include "../util/rmalloc.h"
#include "../errors/errors.h"
#include "../graph/graphcontext.h"
#include "../datatypes/temporal_value.h"
#include "../datatypes/array.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/arithmetic_expression_construct.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "arithmetic_expression_construct.h"
#include "RG.h"
#include "funcs.h"
#include "../errors.h"
#include "../query_ctx.h"
#include "../util/rmalloc.h"
#include "../errors/errors.h"
#include "../datatypes/array.h"
#include "../configuration/config.h"
#include "../ast/ast_build_filter_tree.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/boolean_funcs/boolean_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

#include "boolean_funcs.h"
#include "../../errors.h"
#include "../func_desc.h"
#include "../../util/arr.h"
#include "../../query_ctx.h"
#include "../../errors/errors.h"
#include "../../datatypes/map.h"
#include "../../datatypes/array.h"

Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/comprehension_funcs/comprehension_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "RG.h"
#include "../../value.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../query_ctx.h"
#include "../../errors/errors.h"
#include "../../datatypes/array.h"
#include "../../util/rax_extensions.h"
#include "../../execution_plan/record.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/entity_funcs/entity_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#include "entity_funcs.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../query_ctx.h"
#include "../../datatypes/map.h"
#include "../../errors/errors.h"
#include "../../datatypes/array.h"
#include "../../graph/graphcontext.h"
#include "../../datatypes/datatypes.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/list_funcs/list_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "list_funcs.h"
#include "RG.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../query_ctx.h"
#include "../../util/dict.h"
#include "../../util/strutil.h"
#include "../../errors/errors.h"
#include "../../datatypes/array.h"
#include "../../util/rax_extensions.h"
#include "../string_funcs/string_funcs.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/map_funcs/map_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "map_funcs.h"
#include "RG.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../datatypes/map.h"
#include "../../errors/errors.h"
#include "../../datatypes/array.h"
#include "../../graph/entities/graph_entity.h"

Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/numeric_funcs/numeric_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "numeric_funcs.h"
#include "RG.h"
#include "../../errors.h"
#include "../../errors/errors.h"
#include "../func_desc.h"
#include "../../util/arr.h"
#include "../../util/rmalloc.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/point_funcs/point_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "RG.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../errors/errors.h"
#include "../../datatypes/map.h"
#include <math.h>

Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/string_funcs/string_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#include "string_funcs.h"
#include "../func_desc.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../util/uuid.h"
#include "utf8proc/utf8proc.h"
#include "../../util/rmalloc.h"
#include "../../util/strutil.h"
#include "../../errors/errors.h"
#include "../../datatypes/array.h"
#include "../../util/json_encoder.h"
#include "../deps/oniguruma/src/oniguruma.h"
Expand Down
4 changes: 2 additions & 2 deletions src/ast/ast_build_filter_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* the Server Side Public License v1 (SSPLv1).
*/

#include "RG.h"
#include "ast_build_filter_tree.h"
#include "ast_shared.h"
#include "../RG.h"
#include "../errors.h"
#include "../util/arr.h"
#include "../errors/errors.h"
#include "../arithmetic/arithmetic_expression_construct.h"

// Forward declaration
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast_build_op_contexts.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

#include "ast_build_op_contexts.h"
#include "../errors.h"
#include "ast_shared.h"
#include "../util/arr.h"
#include "../errors/errors.h"
#include "../util/rax_extensions.h"
#include "../arithmetic/arithmetic_expression_construct.h"
#include "../query_ctx.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast_rewrite_same_clauses.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

#include "ast.h"
#include "../errors.h"
#include "../util/arr.h"
#include "../query_ctx.h"
#include "../util/qsort.h"
#include "../util/sds/sds.h"
#include "../errors/errors.h"
#include "../procedures/procedure.h"

// forward declarations
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast_rewrite_star_projections.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

#include "ast.h"
#include "../errors.h"
#include "ast_shared.h"
#include "../util/arr.h"
#include "../query_ctx.h"
#include "../util/sds/sds.h"
#include "../errors/errors.h"
#include "../util/rax_extensions.h"
#include "../procedures/procedure.h"

Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma once

#include "ast.h"
#include "../errors.h"
#include "../errors/errors.h"
#include "../arithmetic/arithmetic_expression.h"

struct AR_ExpNode;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast_validations.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include "ast.h"
#include "util.h"
#include "astnode.h"
#include "../errors.h"
#include "ast_shared.h"
#include "../util/arr.h"
#include "ast_visitor.h"
#include "../errors/errors.h"
#include "../util/rax_extensions.h"
#include "../procedures/procedure.h"
#include "../execution_plan/ops/op.h"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_explain.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* the Server Side Public License v1 (SSPLv1).
*/

#include "../errors.h"
#include "cmd_context.h"
#include "../globals.h"
#include "../query_ctx.h"
#include "execution_ctx.h"
#include "../index/index.h"
#include "../util/rmalloc.h"
#include "../errors/errors.h"
#include "../execution_plan/execution_plan.h"

// builds an execution plan but does not execute it
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include "RG.h"
#include "../errors.h"
#include "../ast/ast.h"
#include "cmd_context.h"
#include "../util/arr.h"
Expand All @@ -15,6 +14,7 @@
#include "execution_ctx.h"
#include "../graph/graph.h"
#include "../util/rmalloc.h"
#include "../errors/errors.h"
#include "../index/indexer.h"
#include "../effects/effects.h"
#include "../util/cache/cache.h"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/execution_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "execution_ctx.h"
#include "RG.h"
#include "../errors.h"
#include "../query_ctx.h"
#include "../errors/errors.h"
#include "../execution_plan/execution_plan_clone.h"

static ExecutionType _GetExecutionTypeFromAST
Expand Down
8 changes: 4 additions & 4 deletions src/effects/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static void EffectsBuffer_WriteAttributeSet
// write attribute count
//--------------------------------------------------------------------------

ushort attr_count = ATTRIBUTE_SET_COUNT(attrs);
ushort attr_count = AttributeSet_Count(attrs);
EffectsBuffer_WriteBytes(&attr_count, sizeof(attr_count), buff);

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -341,7 +341,7 @@ void EffectsBuffer_AddCreateNodeEffect

ResultSetStatistics *stats = QueryCtx_GetResultSetStatistics();
stats->nodes_created++;
stats->properties_set += ATTRIBUTE_SET_COUNT(*n->attributes);
stats->properties_set += AttributeSet_Count(*n->attributes);

EffectType t = EFFECT_CREATE_NODE;
EffectsBuffer_WriteBytes(&t, sizeof(t), buff);
Expand Down Expand Up @@ -389,7 +389,7 @@ void EffectsBuffer_AddCreateEdgeEffect

ResultSetStatistics *stats = QueryCtx_GetResultSetStatistics();
stats->relationships_created++;
stats->properties_set += ATTRIBUTE_SET_COUNT(*edge->attributes);
stats->properties_set += AttributeSet_Count(*edge->attributes);

EffectType t = EFFECT_CREATE_EDGE;
EffectsBuffer_WriteBytes(&t, sizeof(t), buff);
Expand Down Expand Up @@ -599,7 +599,7 @@ void EffectsBuffer_AddEntityRemoveAttributeEffect
) {
// attribute was deleted
int n = (attr_id == ATTRIBUTE_ID_ALL)
? ATTRIBUTE_SET_COUNT(*entity->attributes)
? AttributeSet_Count(*entity->attributes)
: 1;

ResultSetStatistics *stats = QueryCtx_GetResultSetStatistics();
Expand Down
10 changes: 10 additions & 0 deletions src/errors/error_msgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Redis Ltd. 2018 - present
* Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or
* the Server Side Public License v1 (SSPLv1).
*/

#pragma once

// TODO: migrate error messages here

File renamed without changes.
1 change: 1 addition & 0 deletions src/errors.h → src/errors/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stddef.h>
#include "rax.h"
#include "value.h"
#include "error_msgs.h"
#include "cypher-parser.h"

extern pthread_key_t _tlsErrorCtx; // Error-handling context held in thread-local storage.
Expand Down
2 changes: 1 addition & 1 deletion src/execution_plan/execution_plan.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "execution_plan.h"
#include "../RG.h"
#include "./ops/ops.h"
#include "../errors.h"
#include "../util/arr.h"
#include "../query_ctx.h"
#include "../util/rmalloc.h"
#include "../errors/errors.h"
#include "./optimizations/optimizer.h"
#include "../ast/ast_build_filter_tree.h"
#include "execution_plan_build/execution_plan_modify.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

#include "../ops/ops.h"
#include "../../errors.h"
#include "../../query_ctx.h"
#include "../execution_plan.h"
#include "../../errors/errors.h"
#include "execution_plan_util.h"
#include "execution_plan_modify.h"
#include "execution_plan_construct.h"
Expand Down
25 changes: 17 additions & 8 deletions src/execution_plan/ops/op_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "op_create.h"
#include "RG.h"
#include "../../errors.h"
#include "../../util/arr.h"
#include "../../query_ctx.h"
#include "../../errors/errors.h"

// forward declarations
static Record CreateConsume(OpBase *opBase);
Expand Down Expand Up @@ -94,11 +94,14 @@ static void _CreateEdges
EdgeCreateCtx *e = op->pending.edges_to_create + i;

// retrieve source and dest nodes
Node *src_node = Record_GetNode(r, e->src_idx);
Node *dest_node = Record_GetNode(r, e->dest_idx);
// verify that the endpoints of the new edge resolved properly
// fail otherwise
if(!src_node || !dest_node) {
GraphEntity *src_node = (GraphEntity*)Record_GetNode(r, e->src_idx);
GraphEntity *dest_node = (GraphEntity*)Record_GetNode(r, e->dest_idx);

// verify edge endpoints resolved properly, fail otherwise
if(unlikely(!src_node ||
!dest_node ||
GraphEntity_IsDeleted(src_node) ||
GraphEntity_IsDeleted(dest_node))) {
ErrorCtx_RaiseRuntimeException(
"Failed to create relationship; endpoint was not found.");
}
Expand Down Expand Up @@ -126,11 +129,17 @@ static void _CreateEdges
}

// Return mode, emit a populated Record.
static Record _handoff(OpCreate *op) {
static Record _handoff
(
OpCreate *op
) {
return array_pop(op->records);
}

static Record CreateConsume(OpBase *opBase) {
static Record CreateConsume
(
OpBase *opBase
) {
OpCreate *op = (OpCreate *)opBase;
Record r;

Expand Down
Loading

0 comments on commit 5183395

Please sign in to comment.