MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / GraphContext_New

Function GraphContext_New

src/graph/graphcontext.c:89–137  ·  view source on GitHub ↗

creates and initializes a graph context struct

Source from the content-addressed store, hash-verified

87
88// creates and initializes a graph context struct
89GraphContext *GraphContext_New
90(
91 const char *graph_name
92) {
93 GraphContext *gc = rm_malloc(sizeof(GraphContext));
94
95 gc->version = 0; // initial graph version
96 gc->slowlog = SlowLog_New();
97 gc->queries_log = QueriesLog_New();
98 gc->ref_count = 0; // no refences
99 gc->attributes = raxNew();
100 gc->index_count = 0; // no indicies
101 gc->string_mapping = array_new(char *, 64);
102 gc->encoding_context = GraphEncodeContext_New();
103 gc->decoding_context = GraphDecodeContext_New();
104
105 // read NODE_CREATION_BUFFER size from configuration
106 // this value controls how much extra room we're willing to spend for:
107 // 1. graph entity storage
108 // 2. matrices dimensions
109 size_t node_cap;
110 size_t edge_cap;
111 bool rc = Config_Option_get(Config_NODE_CREATION_BUFFER, &node_cap);
112 assert(rc);
113 edge_cap = node_cap;
114
115 gc->g = Graph_New(node_cap, edge_cap);
116 gc->graph_name = rm_strdup(graph_name);
117 gc->telemetry_stream = RedisModule_CreateStringPrintf(NULL,
118 TELEMETRY_FORMAT, gc->graph_name);
119
120 // allocate the default space for schemas and indices
121 gc->node_schemas = array_new(Schema *, GRAPH_DEFAULT_LABEL_CAP);
122 gc->relation_schemas = array_new(Schema *, GRAPH_DEFAULT_RELATION_TYPE_CAP);
123
124 // initialize the read-write lock to protect access to the attributes rax
125 int rc1 = pthread_rwlock_init(&gc->_attribute_rwlock, NULL);
126 assert(rc1 == 0);
127
128 // build the execution plans cache
129 uint64_t cache_size;
130 Config_Option_get(Config_CACHE_SIZE, &cache_size);
131 gc->cache = Cache_New(cache_size, (CacheEntryFreeFunc)ExecutionCtx_Free,
132 (CacheEntryCopyFunc)ExecutionCtx_Clone);
133
134 Graph_SetMatrixPolicy(gc->g, SYNC_POLICY_FLUSH_RESIZE);
135
136 return gc;
137}
138
139// _GraphContext_Create tries to get a graph context
140// and if it does not exists, create a new one

Callers 7

_GetOrCreateGraphContextFunction · 0.85
_GetOrCreateGraphContextFunction · 0.85
_GetOrCreateGraphContextFunction · 0.85
_GetOrCreateGraphContextFunction · 0.85
_GetOrCreateGraphContextFunction · 0.85
_GetOrCreateGraphContextFunction · 0.85
_GraphContext_CreateFunction · 0.85

Calls 10

rm_mallocFunction · 0.85
SlowLog_NewFunction · 0.85
QueriesLog_NewFunction · 0.85
GraphEncodeContext_NewFunction · 0.85
GraphDecodeContext_NewFunction · 0.85
Config_Option_getFunction · 0.85
Graph_NewFunction · 0.85
rm_strdupFunction · 0.85
Cache_NewFunction · 0.85
Graph_SetMatrixPolicyFunction · 0.85

Tested by

no test coverage detected