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

Function _RdbSaveKeySchema

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

this function saves the key content schema and returns it so the encoder can know how to encode the key

Source from the content-addressed store, hash-verified

111// this function saves the key content schema
112// and returns it so the encoder can know how to encode the key
113static PayloadInfo *_RdbSaveKeySchema
114(
115 RedisModuleIO *rdb,
116 GraphContext *gc
117) {
118 // Format:
119 // #Number of payloads info - N
120 // N * Payload info:
121 // Encode state
122 // Number of entities encoded in this state
123
124 PayloadInfo *payloads = array_new(PayloadInfo, 1);
125
126 // get current encoding state
127 EncodeState current_state = GraphEncodeContext_GetEncodeState(gc->encoding_context);
128
129 // if this is the start of the encodeing, set the state to be NODES
130 if(current_state == ENCODE_STATE_INIT) current_state = ENCODE_STATE_NODES;
131
132 uint64_t remaining_entities;
133 Config_Option_get(Config_VKEY_MAX_ENTITY_COUNT, &remaining_entities);
134
135 // check if this is the last key
136 bool last_key = GraphEncodeContext_GetProcessedKeyCount(gc->encoding_context) ==
137 (GraphEncodeContext_GetKeyCount(gc->encoding_context) - 1);
138 if(last_key) remaining_entities = VKEY_ENTITY_COUNT_UNLIMITED;
139
140 // get the current state encoded entities count
141 uint64_t offset = GraphEncodeContext_GetProcessedEntitiesOffset(gc->encoding_context);
142
143 // while there are still remaining entities to encode in this key
144 // and the state is valid
145 while(remaining_entities > 0 && current_state < ENCODE_STATE_FINAL) {
146 // get the current state payload info, with respect to offset
147 PayloadInfo current_state_payload_info = _StatePayloadInfo(gc,
148 current_state, offset, remaining_entities);
149 array_append(payloads, current_state_payload_info);
150 if(!last_key) remaining_entities -= current_state_payload_info.entities_count;
151 if(remaining_entities > 0) {
152 offset = 0; // new state offset is 0
153 current_state++; // advance in the states
154 }
155 }
156
157 // save the number of payloads
158 uint payloads_count = array_len(payloads);
159 RedisModule_SaveUnsigned(rdb, payloads_count);
160 for(uint i = 0; i < payloads_count; i++) {
161 // for each payload
162 // save its type and the number of entities it contains
163 PayloadInfo payload_info = payloads[i];
164 RedisModule_SaveUnsigned(rdb, payload_info.state);
165 RedisModule_SaveUnsigned(rdb, payload_info.entities_count);
166 }
167
168 return payloads;
169}
170

Callers 1

RdbSaveGraph_v13Function · 0.85

Tested by

no test coverage detected