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

Function RdbSaveGraph_v13

src/serializers/encoder/v13/encode_graph.c:171–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void RdbSaveGraph_v13
172(
173 RedisModuleIO *rdb,
174 void *value
175) {
176 // Encoding format for graph context and graph meta key:
177 // Header
178 // Payload(s) count: N
179 // Key content X N:
180 // Payload type (Nodes / Edges / Deleted nodes/ Deleted edges/ Graph schema)
181 // Entities in payload
182 // Payload(s) X N
183 //
184 // This function will encode each payload type (if needed) in the following order:
185 // 1. Nodes
186 // 2. Deleted nodes
187 // 3. Edges
188 // 4. Deleted edges
189 // 5. Graph schema
190 //
191 // Each payload type can spread over one or more keys. For example:
192 // A graph with 200,000 nodes, and the number of entities per payload
193 // is 100,000 then there will be two nodes payloads,
194 // each containing 100,000 nodes, encoded into two different RDB meta keys
195
196 GraphContext *gc = value;
197
198 // TODO: remove, no need, as GIL is taken
199
200 // acquire a read lock if we're not in a thread-safe context
201 if(_shouldAcquireLocks()) Graph_AcquireReadLock(gc->g);
202
203 EncodeState current_state = GraphEncodeContext_GetEncodeState(gc->encoding_context);
204
205 if(current_state == ENCODE_STATE_INIT) {
206 // inital state, populate encoding context header
207 GraphEncodeContext_InitHeader(gc->encoding_context, gc->graph_name, gc->g);
208 }
209
210 // save header
211 _RdbSaveHeader(rdb, gc);
212
213 // save payloads info for this key and retrive the key schema
214 PayloadInfo *key_schema = _RdbSaveKeySchema(rdb, gc);
215
216 uint payloads_count = array_len(key_schema);
217 for(uint i = 0; i < payloads_count; i++) {
218 // if the current key encoding more than one payload type,
219 // payloads count >1 and we are in a new state, zero the entities count
220 if(i > 0) GraphEncodeContext_SetProcessedEntitiesOffset(gc->encoding_context, 0);
221 PayloadInfo payload = key_schema[i];
222 switch(payload.state) {
223 case ENCODE_STATE_NODES:
224 RdbSaveNodes_v13(rdb, gc, payload.entities_count);
225 break;
226 case ENCODE_STATE_DELETED_NODES:
227 RdbSaveDeletedNodes_v13(rdb, gc, payload.entities_count);
228 break;

Callers 1

RdbSaveGraphFunction · 0.85

Calls 15

_shouldAcquireLocksFunction · 0.85
Graph_AcquireReadLockFunction · 0.85
_RdbSaveHeaderFunction · 0.85
_RdbSaveKeySchemaFunction · 0.85
array_lenFunction · 0.85
RdbSaveNodes_v13Function · 0.85
RdbSaveDeletedNodes_v13Function · 0.85
RdbSaveEdges_v13Function · 0.85
RdbSaveDeletedEdges_v13Function · 0.85

Tested by

no test coverage detected