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

Function _CreateGraphMetaKeys

src/module_event_handlers.c:115–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115static void _CreateGraphMetaKeys
116(
117 RedisModuleCtx *ctx,
118 GraphContext *gc
119) {
120 uint meta_key_count = _GraphContext_RequiredMetaKeys(gc);
121 bool graph_name_contains_tag = _GraphContext_NameContainsTag(gc);
122 for(uint i = 1; i <= meta_key_count; i++) {
123 char *uuid = UUID_New();
124 RedisModuleString *meta_rm_string;
125 // meta keys need to be in the exact shard/slot as the graph context key
126 // to avoid graph sharding at the target db
127 // we want to save all the graph keys on the same shard
128 // for that, we need to that them In so their tag hash value will be
129 // the same as the graph context key hash value
130 // if the graph name already contains a tag, we can duplicate
131 // the graph name completely for each meta key
132 // if not, the meta keys tag will be the graph name, so
133 // when hashing the graphcontext key name (graph name)
134 // and the graph meta key tag (graph name)
135 // the hash values will be the same
136 if(graph_name_contains_tag) {
137 // graph already has a tag, create a meta key of "graph_name_uuid"
138 meta_rm_string = RedisModule_CreateStringPrintf(ctx, "%s_%s",
139 gc->graph_name, uuid);
140 } else {
141 // graph is untagged, one must be introduced to ensure that
142 // keys are propagated to the same node
143 // create a meta key of "{graph_name}graph_name_i"
144 meta_rm_string = RedisModule_CreateStringPrintf(ctx, "{%s}%s_%s",
145 gc->graph_name, gc->graph_name, uuid);
146 }
147
148 const char *key_name = RedisModule_StringPtrLen(meta_rm_string, NULL);
149 GraphEncodeContext_AddMetaKey(gc->encoding_context, key_name);
150 RedisModuleKey *key = RedisModule_OpenKey(ctx, meta_rm_string,
151 REDISMODULE_WRITE);
152
153 // set value in key
154 RedisModule_ModuleTypeSetValue(key, GraphMetaRedisModuleType, gc);
155 RedisModule_CloseKey(key);
156
157 // increase graph context ref count for each virtual key
158 GraphContext_IncreaseRefCount(gc);
159 RedisModule_FreeString(ctx, meta_rm_string);
160 rm_free(uuid);
161 }
162
163 RedisModule_Log(ctx, "notice", "Created %d virtual keys for graph %s",
164 meta_key_count, gc->graph_name);
165}
166
167// delete meta keys, upon RDB encode or decode finished event triggering
168// the decode flag represent the event

Callers 1

_CreateKeySpaceMetaKeysFunction · 0.85

Calls 6

UUID_NewFunction · 0.85
rm_freeFunction · 0.85

Tested by

no test coverage detected