Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
5f6e1183
Commit
5f6e1183
authored
Dec 29, 2010
by
antirez
Browse files
implemented complete job handling
parent
f34a6cd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dscache.c
View file @
5f6e1183
...
...
@@ -240,6 +240,7 @@ int dsCanTouchDiskStore(void) {
void
freeIOJob
(
iojob
*
j
)
{
decrRefCount
(
j
->
key
);
decrRefCount
(
j
->
val
);
zfree
(
j
);
}
...
...
@@ -282,68 +283,13 @@ void vmThreadedIOCompletedJob(aeEventLoop *el, int fd, void *privdata,
de
=
dictFind
(
j
->
db
->
dict
,
j
->
key
->
ptr
);
redisAssert
(
de
!=
NULL
);
if
(
j
->
type
==
REDIS_IOJOB_LOAD
)
{
redisDb
*
db
;
vmpointer
*
vp
=
dictGetEntryVal
(
de
);
/* Key loaded, bring it at home */
vmMarkPagesFree
(
vp
->
page
,
vp
->
usedpages
);
redisLog
(
REDIS_DEBUG
,
"VM: object %s loaded from disk (threaded)"
,
(
unsigned
char
*
)
j
->
key
->
ptr
);
server
.
vm_stats_swapped_objects
--
;
server
.
vm_stats_swapins
++
;
dictGetEntryVal
(
de
)
=
j
->
val
;
incrRefCount
(
j
->
val
);
db
=
j
->
db
;
/* Handle clients waiting for this key to be loaded. */
handleClientsBlockedOnSwappedKey
(
db
,
j
->
key
);
dbAdd
(
j
->
db
,
j
->
key
,
j
->
val
);
freeIOJob
(
j
);
zfree
(
vp
);
}
else
if
(
j
->
type
==
REDIS_IOJOB_DO_SWAP
)
{
vmpointer
*
vp
;
/* Key swapped. We can finally free some memory. */
if
(
j
->
val
->
storage
!=
REDIS_VM_SWAPPING
)
{
vmpointer
*
vp
=
(
vmpointer
*
)
j
->
id
;
printf
(
"storage: %d
\n
"
,
vp
->
storage
);
printf
(
"key->name: %s
\n
"
,(
char
*
)
j
->
key
->
ptr
);
printf
(
"val: %p
\n
"
,(
void
*
)
j
->
val
);
printf
(
"val->type: %d
\n
"
,
j
->
val
->
type
);
printf
(
"val->ptr: %s
\n
"
,(
char
*
)
j
->
val
->
ptr
);
}
redisAssert
(
j
->
val
->
storage
==
REDIS_VM_SWAPPING
);
vp
=
createVmPointer
(
j
->
val
->
type
);
vp
->
page
=
j
->
page
;
vp
->
usedpages
=
j
->
pages
;
dictGetEntryVal
(
de
)
=
vp
;
/* Fix the storage otherwise decrRefCount will attempt to
* remove the associated I/O job */
j
->
val
->
storage
=
REDIS_VM_MEMORY
;
decrRefCount
(
j
->
val
);
redisLog
(
REDIS_DEBUG
,
"VM: object %s swapped out at %lld (%lld pages) (threaded)"
,
(
unsigned
char
*
)
j
->
key
->
ptr
,
(
unsigned
long
long
)
j
->
page
,
(
unsigned
long
long
)
j
->
pages
);
server
.
vm_stats_swapped_objects
++
;
server
.
vm_stats_swapouts
++
;
/* FIXME: notify clients waiting for this key */
}
else
if
(
j
->
type
==
REDIS_IOJOB_SAVE
)
{
redisAssert
(
j
->
val
->
storage
==
REDIS_DS_SAVING
);
j
->
val
->
storage
=
REDIS_DS_MEMORY
;
freeIOJob
(
j
);
/* Put a few more swap requests in queue if we are still
* out of memory */
if
(
trytoswap
&&
vmCanSwapOut
()
&&
zmalloc_used_memory
()
>
server
.
vm_max_memory
)
{
int
more
=
1
;
while
(
more
)
{
lockThreadedIO
();
more
=
listLength
(
server
.
io_newjobs
)
<
(
unsigned
)
server
.
vm_max_threads
;
unlockThreadedIO
();
/* Don't waste CPU time if swappable objects are rare. */
if
(
vmSwapOneObjectThreaded
()
==
REDIS_ERR
)
{
trytoswap
=
0
;
break
;
}
}
}
}
processed
++
;
if
(
processed
==
toprocess
)
return
;
...
...
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