MCPcopy Create free account
hub / github.com/F-Stack/f-stack / replconfCommand

Function replconfCommand

app/redis-6.2.6/src/replication.c:924–1006  ·  view source on GitHub ↗

REPLCONF ... * This command is used by a replica in order to configure the replication * process before starting it with the SYNC command. * This command is also used by a master in order to get the replication * offset from a replica. * * Currently we support these options: * * - listening-port * - ip-address * What is the listening ip and p

Source from the content-addressed store, hash-verified

922 * - rdb-only
923 * Only wants RDB snapshot without replication buffer. */
924void replconfCommand(client *c) {
925 int j;
926
927 if ((c->argc % 2) == 0) {
928 /* Number of arguments must be odd to make sure that every
929 * option has a corresponding value. */
930 addReplyErrorObject(c,shared.syntaxerr);
931 return;
932 }
933
934 /* Process every option-value pair. */
935 for (j = 1; j < c->argc; j+=2) {
936 if (!strcasecmp(c->argv[j]->ptr,"listening-port")) {
937 long port;
938
939 if ((getLongFromObjectOrReply(c,c->argv[j+1],
940 &port,NULL) != C_OK))
941 return;
942 c->slave_listening_port = port;
943 } else if (!strcasecmp(c->argv[j]->ptr,"ip-address")) {
944 sds addr = c->argv[j+1]->ptr;
945 if (sdslen(addr) < NET_HOST_STR_LEN) {
946 if (c->slave_addr) sdsfree(c->slave_addr);
947 c->slave_addr = sdsdup(addr);
948 } else {
949 addReplyErrorFormat(c,"REPLCONF ip-address provided by "
950 "replica instance is too long: %zd bytes", sdslen(addr));
951 return;
952 }
953 } else if (!strcasecmp(c->argv[j]->ptr,"capa")) {
954 /* Ignore capabilities not understood by this master. */
955 if (!strcasecmp(c->argv[j+1]->ptr,"eof"))
956 c->slave_capa |= SLAVE_CAPA_EOF;
957 else if (!strcasecmp(c->argv[j+1]->ptr,"psync2"))
958 c->slave_capa |= SLAVE_CAPA_PSYNC2;
959 } else if (!strcasecmp(c->argv[j]->ptr,"ack")) {
960 /* REPLCONF ACK is used by slave to inform the master the amount
961 * of replication stream that it processed so far. It is an
962 * internal only command that normal clients should never use. */
963 long long offset;
964
965 if (!(c->flags & CLIENT_SLAVE)) return;
966 if ((getLongLongFromObject(c->argv[j+1], &offset) != C_OK))
967 return;
968 if (offset > c->repl_ack_off)
969 c->repl_ack_off = offset;
970 c->repl_ack_time = server.unixtime;
971 /* If this was a diskless replication, we need to really put
972 * the slave online when the first ACK is received (which
973 * confirms slave is online and ready to get more data). This
974 * allows for simpler and less CPU intensive EOF detection
975 * when streaming RDB files.
976 * There's a chance the ACK got to us before we detected that the
977 * bgsave is done (since that depends on cron ticks), so run a
978 * quick check first (instead of waiting for the next ACK. */
979 if (server.child_type == CHILD_TYPE_RDB && c->replstate == SLAVE_STATE_WAIT_BGSAVE_END)
980 checkChildrenDone();
981 if (c->repl_put_online_on_ack && c->replstate == SLAVE_STATE_ONLINE)

Callers

nothing calls this directly

Calls 13

addReplyErrorObjectFunction · 0.85
strcasecmpFunction · 0.85
getLongFromObjectOrReplyFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
sdsdupFunction · 0.85
addReplyErrorFormatFunction · 0.85
getLongLongFromObjectFunction · 0.85
checkChildrenDoneFunction · 0.85
putSlaveOnlineFunction · 0.85
replicationSendAckFunction · 0.85

Tested by

no test coverage detected