Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
2fd3fc7f
Commit
2fd3fc7f
authored
Oct 27, 2014
by
antirez
Browse files
Added a function to get slave name for logs.
parent
e1c0a25c
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
2fd3fc7f
...
@@ -678,12 +678,8 @@ void freeClient(redisClient *c) {
...
@@ -678,12 +678,8 @@ void freeClient(redisClient *c) {
/* Log link disconnection with slave */
/* Log link disconnection with slave */
if
((
c
->
flags
&
REDIS_SLAVE
)
&&
!
(
c
->
flags
&
REDIS_MONITOR
))
{
if
((
c
->
flags
&
REDIS_SLAVE
)
&&
!
(
c
->
flags
&
REDIS_MONITOR
))
{
char
ip
[
REDIS_IP_STR_LEN
];
redisLog
(
REDIS_WARNING
,
"Connection with slave %s lost."
,
replicationGetSlaveName
(
c
));
if
(
anetPeerToString
(
c
->
fd
,
ip
,
sizeof
(
ip
),
NULL
)
!=
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Connection with slave %s:%d lost."
,
ip
,
c
->
slave_listening_port
);
}
}
}
/* Free the query buffer */
/* Free the query buffer */
...
...
src/redis.h
View file @
2fd3fc7f
...
@@ -1162,6 +1162,7 @@ void unblockClientWaitingReplicas(redisClient *c);
...
@@ -1162,6 +1162,7 @@ void unblockClientWaitingReplicas(redisClient *c);
int
replicationCountAcksByOffset
(
long
long
offset
);
int
replicationCountAcksByOffset
(
long
long
offset
);
void
replicationSendNewlineToMaster
(
void
);
void
replicationSendNewlineToMaster
(
void
);
long
long
replicationGetSlaveOffset
(
void
);
long
long
replicationGetSlaveOffset
(
void
);
char
*
replicationGetSlaveName
(
redisClient
*
c
);
/* Generic persistence functions */
/* Generic persistence functions */
void
startLoading
(
FILE
*
fp
);
void
startLoading
(
FILE
*
fp
);
...
...
src/replication.c
View file @
2fd3fc7f
...
@@ -41,6 +41,30 @@ void replicationDiscardCachedMaster(void);
...
@@ -41,6 +41,30 @@ void replicationDiscardCachedMaster(void);
void replicationResurrectCachedMaster(int newfd);
void replicationResurrectCachedMaster(int newfd);
void replicationSendAck(void);
void replicationSendAck(void);
/* --------------------------- Utility functions ---------------------------- */
/* Return the pointer to a string representing the slave ip:listening_port
* pair. Mostly useful for logging, since we want to log a slave using its
* IP address and it's listening port which is more clear for the user, for
* example: "Closing connection with slave 10.1.2.3:6380". */
char *replicationGetSlaveName(redisClient *c) {
static char buf[REDIS_PEER_ID_LEN];
char ip[REDIS_IP_STR_LEN];
ip[0] = '\0';
buf[0] = '\0';
if (anetPeerToString(c->fd,ip,sizeof(ip),NULL) != -1) {
if (c->slave_listening_port)
snprintf(buf,sizeof(buf),"%s:%d",ip,c->slave_listening_port);
else
snprintf(buf,sizeof(buf),"%s:<unknown-slave-port>",ip);
} else {
snprintf(buf,sizeof(buf),"client id #%llu",
(unsigned long long) c->id);
}
return buf;
}
/* ---------------------------------- MASTER -------------------------------- */
/* ---------------------------------- MASTER -------------------------------- */
void createReplicationBacklog(void) {
void createReplicationBacklog(void) {
...
@@ -1973,15 +1997,8 @@ void replicationCron(void) {
...
@@ -1973,15 +1997,8 @@ void replicationCron(void) {
if (slave->flags & REDIS_PRE_PSYNC) continue;
if (slave->flags & REDIS_PRE_PSYNC) continue;
if ((server.unixtime - slave->repl_ack_time) > server.repl_timeout)
if ((server.unixtime - slave->repl_ack_time) > server.repl_timeout)
{
{
char
ip
[
REDIS_IP_STR_LEN
];
redisLog(REDIS_WARNING, "Disconnecting timedout slave: %s",
int
port
;
replicationGetSlaveName(slave));
if
(
anetPeerToString
(
slave
->
fd
,
ip
,
sizeof
(
ip
),
&
port
)
!=
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Disconnecting timedout slave: %s:%d"
,
ip
,
slave
->
slave_listening_port
);
}
freeClient
(
slave
);
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment