2022-05-16 17:13:01 +00:00
|
|
|
|
|
|
|
#ifndef REDIS_MIGRATE_REDIS_MIGRATE_H
|
|
|
|
#define REDIS_MIGRATE_REDIS_MIGRATE_H
|
|
|
|
|
|
|
|
#include "redismodule.h"
|
2022-06-05 14:53:47 +00:00
|
|
|
#include "ae.h"
|
|
|
|
#include "sds.h"
|
|
|
|
#include "sdscompat.h"
|
2022-05-16 17:13:01 +00:00
|
|
|
|
|
|
|
#define MODULE_NAME "redis-migrate"
|
|
|
|
#define REDIS_MIGRATE_VERSION 1
|
|
|
|
#define LRU_BITS 24
|
2022-05-25 12:10:07 +00:00
|
|
|
#define C_ERR -1
|
|
|
|
#define C_OK 1
|
2022-05-16 17:13:01 +00:00
|
|
|
|
2022-06-05 14:53:47 +00:00
|
|
|
/* Anti-warning macro... */
|
|
|
|
#define UNUSED(V) ((void) V)
|
|
|
|
|
2022-05-16 17:13:01 +00:00
|
|
|
typedef struct redisObject {
|
2022-05-25 12:10:07 +00:00
|
|
|
unsigned type: 4;
|
|
|
|
unsigned encoding: 4;
|
|
|
|
unsigned lru: LRU_BITS; /* LRU time (relative to global lru_clock) or
|
2022-05-16 17:13:01 +00:00
|
|
|
* LFU data (least significant 8 bits frequency
|
|
|
|
* and most significant 16 bits access time). */
|
|
|
|
int refcount;
|
|
|
|
void *ptr;
|
|
|
|
} robj;
|
|
|
|
|
2022-06-05 14:53:47 +00:00
|
|
|
typedef struct migrateObject {
|
|
|
|
char *address;
|
|
|
|
int repl_stat;
|
|
|
|
redisContext *source_cc;
|
|
|
|
char *host;
|
|
|
|
int port;
|
|
|
|
int begin_slot;
|
|
|
|
int end_slot;
|
2022-06-05 15:01:54 +00:00
|
|
|
char *psync_replid;
|
2022-06-05 14:53:47 +00:00
|
|
|
char psync_offset[32];
|
|
|
|
} migrateObj;
|
|
|
|
|
2022-05-25 12:10:07 +00:00
|
|
|
typedef enum {
|
|
|
|
REPL_STATE_NONE = 0, /* No active replication */
|
|
|
|
REPL_STATE_CONNECT, /* Must connect to master */
|
|
|
|
REPL_STATE_CONNECTING, /* Connecting to master */
|
|
|
|
/* --- Handshake states, must be ordered --- */
|
|
|
|
REPL_STATE_RECEIVE_PING_REPLY, /* Wait for PING reply */
|
|
|
|
REPL_STATE_SEND_HANDSHAKE, /* Send handshake sequence to master */
|
|
|
|
REPL_STATE_RECEIVE_AUTH_REPLY, /* Wait for AUTH reply */
|
|
|
|
REPL_STATE_RECEIVE_PORT_REPLY, /* Wait for REPLCONF reply */
|
|
|
|
REPL_STATE_RECEIVE_IP_REPLY, /* Wait for REPLCONF reply */
|
|
|
|
REPL_STATE_RECEIVE_CAPA_REPLY, /* Wait for REPLCONF reply */
|
|
|
|
REPL_STATE_SEND_PSYNC, /* Send PSYNC */
|
|
|
|
REPL_STATE_RECEIVE_PSYNC_REPLY, /* Wait for PSYNC reply */
|
|
|
|
/* --- End of handshake states --- */
|
|
|
|
REPL_STATE_TRANSFER, /* Receiving .rdb from master */
|
|
|
|
REPL_STATE_CONNECTED, /* Connected to master */
|
2022-06-05 14:53:47 +00:00
|
|
|
STATE_CONNECT_ERROR,
|
|
|
|
STATE_DISCONNECT
|
2022-05-25 12:10:07 +00:00
|
|
|
} repl_state;
|
|
|
|
|
|
|
|
long long ustime(void);
|
|
|
|
|
2022-06-05 14:53:47 +00:00
|
|
|
migrateObj *createMigrateObject(robj *host, int port, int begin_slot, int end_slot);
|
|
|
|
|
|
|
|
void freeMigrateObj(migrateObj *m);
|
|
|
|
|
|
|
|
int sendReplCommand(RedisModuleCtx *ctx, char *format, ...);
|
|
|
|
|
|
|
|
void *syncWithRedis(void *arg);
|
|
|
|
|
|
|
|
int connectRedis(RedisModuleCtx *ctx) ;
|
|
|
|
|
2022-05-16 17:13:01 +00:00
|
|
|
int rm_migrateCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
2022-05-25 12:10:07 +00:00
|
|
|
|
2022-05-16 17:13:01 +00:00
|
|
|
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
|
|
|
|
|
|
|
#endif //REDIS_MIGRATE_REDIS_MIGRATE_H
|