Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
726a39c1
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
726a39c1
编写于
4月 07, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initial cluster config load code
上级
0b7f6d09
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
39 addition
and
4 deletion
+39
-4
src/cluster.c
src/cluster.c
+31
-4
src/sds.c
src/sds.c
+7
-0
src/sds.h
src/sds.h
+1
-0
未找到文件。
src/cluster.c
浏览文件 @
726a39c1
...
...
@@ -34,11 +34,32 @@ void clusterGetRandomName(char *p) {
int
clusterLoadConfig
(
char
*
filename
)
{
FILE
*
fp
=
fopen
(
filename
,
"r"
);
char
*
line
;
int
maxline
;
return
REDIS_ERR
;
if
(
fp
==
NULL
)
return
REDIS_ERR
;
/* Parse the file. Note that single liens of the cluster config file can
* be really long as they include all the hash slots of the node.
* This means in the worst possible case REDIS_CLUSTER_SLOTS/2 integers.
* To simplify we allocate 1024+REDIS_CLUSTER_SLOTS*16 bytes per line. */
maxline
=
1024
+
REDIS_CLUSTER_SLOTS
*
16
;
line
=
zmalloc
(
maxline
);
while
(
fgets
(
line
,
maxline
,
fp
)
!=
NULL
)
{
int
argc
;
sds
*
argv
=
sdssplitargs
(
line
,
&
argc
);
printf
(
"Node: %s
\n
"
,
argv
[
0
]);
sdssplitargs_free
(
argv
,
argc
);
}
zfree
(
line
);
fclose
(
fp
);
/* Config sanity check */
/* TODO: check that myself is set. */
return
REDIS_ERR
;
redisLog
(
REDIS_NOTICE
,
"Node configuration loaded, I'm %.40s"
,
server
.
cluster
.
myself
->
name
);
return
REDIS_OK
;
...
...
@@ -57,8 +78,8 @@ int clusterSaveConfig(void) {
sds
ci
=
clusterGenNodesDescription
();
int
fd
;
if
((
fd
=
open
(
server
.
cluster
.
configfile
,
O_WRONLY
|
O_CREAT
,
0644
))
==
-
1
)
goto
err
;
if
((
fd
=
open
(
server
.
cluster
.
configfile
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
)
)
==
-
1
)
goto
err
;
if
(
write
(
fd
,
ci
,
sdslen
(
ci
))
!=
(
ssize_t
)
sdslen
(
ci
))
goto
err
;
close
(
fd
);
sdsfree
(
ci
);
...
...
@@ -337,6 +358,7 @@ void clusterProcessGossipSection(clusterMsg *hdr, clusterLink *link) {
/* Broadcast the failing node name to everybody */
clusterSendFail
(
node
->
name
);
clusterUpdateState
();
clusterSaveConfigOrDie
();
}
}
else
{
/* If it's not in NOADDR state and we don't have it, we
...
...
@@ -522,7 +544,10 @@ int clusterProcessPacket(clusterLink *link) {
clusterProcessGossipSection
(
hdr
,
link
);
/* Update the cluster state if needed */
if
(
update
)
clusterUpdateState
();
if
(
update
)
{
clusterUpdateState
();
clusterSaveConfigOrDie
();
}
}
else
if
(
type
==
CLUSTERMSG_TYPE_FAIL
&&
sender
)
{
clusterNode
*
failing
;
...
...
@@ -534,6 +559,7 @@ int clusterProcessPacket(clusterLink *link) {
failing
->
flags
|=
REDIS_NODE_FAIL
;
failing
->
flags
&=
~
REDIS_NODE_PFAIL
;
clusterUpdateState
();
clusterSaveConfigOrDie
();
}
}
else
{
redisLog
(
REDIS_NOTICE
,
"Received unknown packet type: %d"
,
type
);
...
...
@@ -1047,6 +1073,7 @@ void clusterCommand(redisClient *c) {
}
zfree
(
slots
);
clusterUpdateState
();
clusterSaveConfigOrDie
();
addReply
(
c
,
shared
.
ok
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"info"
)
&&
c
->
argc
==
2
)
{
char
*
statestr
[]
=
{
"ok"
,
"fail"
,
"needhelp"
};
...
...
src/sds.c
浏览文件 @
726a39c1
...
...
@@ -554,6 +554,13 @@ err:
return
NULL
;
}
void
sdssplitargs_free
(
sds
*
argv
,
int
argc
)
{
int
j
;
for
(
j
=
0
;
j
<
argc
;
j
++
)
sdsfree
(
argv
[
j
]);
zfree
(
argv
);
}
#ifdef SDS_TEST_MAIN
#include <stdio.h>
#include "testhelp.h"
...
...
src/sds.h
浏览文件 @
726a39c1
...
...
@@ -74,5 +74,6 @@ void sdstoupper(sds s);
sds
sdsfromlonglong
(
long
long
value
);
sds
sdscatrepr
(
sds
s
,
char
*
p
,
size_t
len
);
sds
*
sdssplitargs
(
char
*
line
,
int
*
argc
);
void
sdssplitargs_free
(
sds
*
argv
,
int
argc
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录