-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial work graph.copy * pipe serializer * abstract serializer * graph encoder switch to abstract serializer * switch decoder to abstract serializer * copy command wip * first copy * early flow test * additional tests * transition to worker thread execution * switch to worker thread * retry when fork failed * skip graph copy replication test when running under sanitizer * import SANITIZER * plant cloned key only after decoding is done * switch to CRON job * fork writes to file * add logs * fix leak * replicate via RESTORE, switch to FILE* * add graph.restore * fix unit-test wrong stream acquisition * fork requires gil * rename encoder/decoder v14 to latest
- Loading branch information
Showing
23 changed files
with
1,702 additions
and
216 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright FalkorDB Ltd. 2023 - present | ||
* Licensed under the Server Side Public License v1 (SSPLv1). | ||
*/ | ||
|
||
#include "RG.h" | ||
#include "../graph/graphcontext.h" | ||
#include "../serializers/serializer_io.h" | ||
#include "../serializers/decoders/current/v14/decode_v14.h" | ||
|
||
extern RedisModuleType *GraphContextRedisModuleType; | ||
|
||
// restore a graph from binary representation | ||
// this command is the counter part of GRAPH.COPY | ||
// which replicates the cloned graph via GRAPH.RESTORE | ||
// | ||
// usage: | ||
// GRAPH.RESTORE <graph> <payload> | ||
// | ||
// this function is ment to execute on redis main thread | ||
int Graph_Restore | ||
( | ||
RedisModuleCtx *ctx, // redis module context | ||
RedisModuleString **argv, // command argument | ||
int argc // number of argument | ||
) { | ||
// validations | ||
ASSERT(ctx != NULL); | ||
ASSERT(argv != NULL); | ||
|
||
// expecting exactly 3 arguments: | ||
// argv[0] command name | ||
// argv[1] graph key | ||
// argv[2] graph payload | ||
if(argc != 3) { | ||
return RedisModule_WrongArity(ctx); | ||
} | ||
|
||
// TODO: reject GRAPH.RESTORE if caller isn't the master | ||
|
||
//-------------------------------------------------------------------------- | ||
// make sure graph key doesn't exists | ||
//-------------------------------------------------------------------------- | ||
|
||
RedisModuleKey *key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); | ||
int key_type = RedisModule_KeyType(key); | ||
RedisModule_CloseKey(key); | ||
|
||
// key exists, fail | ||
if(key_type != REDISMODULE_KEYTYPE_EMPTY) { | ||
RedisModule_ReplyWithError(ctx, "restore graph failed, key already exists"); | ||
return REDISMODULE_OK; | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// decode payload | ||
//-------------------------------------------------------------------------- | ||
|
||
// create memory stream | ||
size_t len; | ||
const char *payload = RedisModule_StringPtrLen(argv[2], &len); | ||
|
||
FILE *stream = fmemopen((void*)payload, len, "r"); | ||
ASSERT(stream != NULL); | ||
|
||
SerializerIO io = SerializerIO_FromStream(stream); | ||
|
||
// decode graph | ||
GraphContext *gc = RdbLoadGraphContext_latest(io, argv[1]); | ||
ASSERT(gc != NULL); | ||
|
||
// add graph to keyspace | ||
key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_WRITE); | ||
|
||
// set value in key | ||
RedisModule_ModuleTypeSetValue(key, GraphContextRedisModuleType, gc); | ||
|
||
RedisModule_CloseKey(key); | ||
|
||
// register graph context for BGSave | ||
GraphContext_RegisterWithModule(gc); | ||
|
||
//-------------------------------------------------------------------------- | ||
// clean up | ||
//-------------------------------------------------------------------------- | ||
|
||
SerializerIO_Free(&io); | ||
|
||
fclose(stream); | ||
|
||
return REDISMODULE_OK; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.