Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
c15a3887
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
c15a3887
编写于
1月 03, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
diskstore bug fixing and negative cache proper implementation
上级
120b9ba8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
26 deletion
+53
-26
src/db.c
src/db.c
+10
-9
src/diskstore.c
src/diskstore.c
+1
-1
src/dscache.c
src/dscache.c
+41
-15
src/redis.h
src/redis.h
+1
-1
未找到文件。
src/db.c
浏览文件 @
c15a3887
...
...
@@ -93,9 +93,7 @@ int dbAdd(redisDb *db, robj *key, robj *val) {
}
else
{
sds
copy
=
sdsdup
(
key
->
ptr
);
dictAdd
(
db
->
dict
,
copy
,
val
);
if
(
server
.
ds_enabled
)
{
/* FIXME: remove entry from negative cache */
}
if
(
server
.
ds_enabled
)
cacheSetKeyMayExist
(
db
,
key
);
return
REDIS_OK
;
}
}
...
...
@@ -106,15 +104,18 @@ int dbAdd(redisDb *db, robj *key, robj *val) {
* On update (key already existed) 0 is returned. Otherwise 1. */
int
dbReplace
(
redisDb
*
db
,
robj
*
key
,
robj
*
val
)
{
robj
*
oldval
;
int
retval
;
if
((
oldval
=
dictFetchValue
(
db
->
dict
,
key
->
ptr
))
==
NULL
)
{
sds
copy
=
sdsdup
(
key
->
ptr
);
dictAdd
(
db
->
dict
,
copy
,
val
);
ret
urn
1
;
ret
val
=
1
;
}
else
{
dictReplace
(
db
->
dict
,
key
->
ptr
,
val
);
ret
urn
0
;
ret
val
=
0
;
}
if
(
server
.
ds_enabled
)
cacheSetKeyMayExist
(
db
,
key
);
return
retval
;
}
int
dbExists
(
redisDb
*
db
,
robj
*
key
)
{
...
...
@@ -152,10 +153,10 @@ int dbDelete(redisDb *db, robj *key) {
/* If diskstore is enabled make sure to awake waiting clients for this key
* as it is not really useful to wait for a key already deleted to be
* loaded from disk. */
if
(
server
.
ds_enabled
)
handleClientsBlockedOnSwappedKey
(
db
,
key
);
/* FIXME: we should mark this key as non existing on disk in the negative
* cache. */
if
(
server
.
ds_enabled
)
{
handleClientsBlockedOnSwappedKey
(
db
,
key
);
cacheSetKeyDoesNotExist
(
db
,
key
);
}
/* Deleting an entry from the expires dict will not free the sds of
* the key, because it is shared with the main dictionary. */
...
...
src/diskstore.c
浏览文件 @
c15a3887
...
...
@@ -298,7 +298,7 @@ void dsFlushOneDir(char *path, int dbid) {
id
[
len
]
=
'\0'
;
if
(
atoi
(
id
)
!=
dbid
)
continue
;
/* skip this file */
}
if
(
unlink
(
path
)
==
-
1
)
{
if
(
unlink
(
dp
->
d_name
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Can't unlink %s: %s"
,
path
,
strerror
(
errno
));
redisPanic
(
"Unrecoverable Disk store errore. Existing."
);
...
...
src/dscache.c
浏览文件 @
c15a3887
...
...
@@ -245,10 +245,10 @@ int cacheFreeOneEntry(void) {
}
}
if
(
best
==
NULL
)
{
/* FIXME: If there are objects
marked as DS_DIRTY or DS_SAVING
*
let's wait for this objects to be clear and retry...
*
*
Object cache vm limit is considered a
n hard limit. */
/* FIXME: If there are objects
that are in the write queue
*
so we can't delete them we should block here, at the cost of
*
slowness as the object cache memory limit is considered
* n hard limit. */
return
REDIS_ERR
;
}
key
=
dictGetEntryKey
(
best
);
...
...
@@ -306,6 +306,38 @@ void cacheSetKeyDoesNotExist(redisDb *db, robj *key) {
}
}
/* Remove one entry from negative cache using approximated LRU. */
int
negativeCacheEvictOneEntry
(
void
)
{
struct
dictEntry
*
de
;
robj
*
best
=
NULL
;
redisDb
*
best_db
=
NULL
;
time_t
time
,
best_time
=
0
;
int
j
;
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
redisDb
*
db
=
server
.
db
+
j
;
int
i
;
if
(
dictSize
(
db
->
io_negcache
)
==
0
)
continue
;
for
(
i
=
0
;
i
<
3
;
i
++
)
{
de
=
dictGetRandomKey
(
db
->
io_negcache
);
time
=
(
time_t
)
dictGetEntryVal
(
de
);
if
(
best
==
NULL
||
time
<
best_time
)
{
best
=
dictGetEntryKey
(
de
);
best_db
=
db
;
best_time
=
time
;
}
}
}
if
(
best
)
{
dictDelete
(
best_db
->
io_negcache
,
best
);
return
REDIS_OK
;
}
else
{
return
REDIS_ERR
;
}
}
/* ================== Disk store cache - Threaded I/O ====================== */
void
freeIOJob
(
iojob
*
j
)
{
...
...
@@ -361,20 +393,11 @@ void vmThreadedIOCompletedJob(aeEventLoop *el, int fd, void *privdata,
incrRefCount
(
j
->
val
);
if
(
j
->
expire
!=
-
1
)
setExpire
(
j
->
db
,
j
->
key
,
j
->
expire
);
}
}
else
{
/* The key does not exist. Create a negative cache entry
* for this key. */
cacheSetKeyDoesNotExist
(
j
->
db
,
j
->
key
);
}
cacheScheduleIODelFlag
(
j
->
db
,
j
->
key
,
REDIS_IO_LOADINPROG
);
handleClientsBlockedOnSwappedKey
(
j
->
db
,
j
->
key
);
freeIOJob
(
j
);
}
else
if
(
j
->
type
==
REDIS_IOJOB_SAVE
)
{
if
(
j
->
val
)
{
cacheSetKeyMayExist
(
j
->
db
,
j
->
key
);
}
else
{
cacheSetKeyDoesNotExist
(
j
->
db
,
j
->
key
);
}
cacheScheduleIODelFlag
(
j
->
db
,
j
->
key
,
REDIS_IO_SAVEINPROG
);
freeIOJob
(
j
);
}
...
...
@@ -740,8 +763,11 @@ void cacheCron(void) {
while
(
server
.
ds_enabled
&&
zmalloc_used_memory
()
>
server
.
cache_max_memory
)
{
if
(
cacheFreeOneEntry
()
==
REDIS_ERR
)
break
;
/* FIXME: also free negative cache entries here. */
int
done
=
0
;
if
(
cacheFreeOneEntry
()
==
REDIS_OK
)
done
++
;
if
(
negativeCacheEvictOneEntry
()
==
REDIS_OK
)
done
++
;
if
(
done
==
0
)
break
;
/* nothing more to free */
}
}
...
...
src/redis.h
浏览文件 @
c15a3887
...
...
@@ -814,7 +814,7 @@ int cacheScheduleIOGetFlags(redisDb *db, robj *key);
void
cacheScheduleIO
(
redisDb
*
db
,
robj
*
key
,
int
type
);
void
cacheCron
(
void
);
int
cacheKeyMayExist
(
redisDb
*
db
,
robj
*
key
);
void
cacheSetKey
Exists
(
redisDb
*
db
,
robj
*
key
);
void
cacheSetKey
MayExist
(
redisDb
*
db
,
robj
*
key
);
void
cacheSetKeyDoesNotExist
(
redisDb
*
db
,
robj
*
key
);
/* Set data type */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录