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
41ed85bd
Unverified
Commit
41ed85bd
authored
Jul 18, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Jul 18, 2019
Browse files
Merge pull request #6252 from soloestoy/tracking-flushdb
Tracking flushdb
parents
947319ca
f59119aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
41ed85bd
...
@@ -417,6 +417,7 @@ void signalModifiedKey(redisDb *db, robj *key) {
...
@@ -417,6 +417,7 @@ void signalModifiedKey(redisDb *db, robj *key) {
void
signalFlushedDb
(
int
dbid
)
{
void
signalFlushedDb
(
int
dbid
)
{
touchWatchedKeysOnFlush
(
dbid
);
touchWatchedKeysOnFlush
(
dbid
);
if
(
server
.
tracking_clients
)
trackingInvalidateKeysOnFlush
(
dbid
);
}
}
/*-----------------------------------------------------------------------------
/*-----------------------------------------------------------------------------
...
...
src/server.h
View file @
41ed85bd
...
@@ -1638,6 +1638,7 @@ void enableTracking(client *c, uint64_t redirect_to);
...
@@ -1638,6 +1638,7 @@ void enableTracking(client *c, uint64_t redirect_to);
void
disableTracking
(
client
*
c
);
void
disableTracking
(
client
*
c
);
void
trackingRememberKeys
(
client
*
c
);
void
trackingRememberKeys
(
client
*
c
);
void
trackingInvalidateKey
(
robj
*
keyobj
);
void
trackingInvalidateKey
(
robj
*
keyobj
);
void
trackingInvalidateKeysOnFlush
(
int
dbid
);
/* List data type */
/* List data type */
void
listTypeTryConversion
(
robj
*
subject
,
robj
*
value
);
void
listTypeTryConversion
(
robj
*
subject
,
robj
*
value
);
...
...
src/tracking.c
View file @
41ed85bd
...
@@ -117,6 +117,40 @@ void trackingRememberKeys(client *c) {
...
@@ -117,6 +117,40 @@ void trackingRememberKeys(client *c) {
getKeysFreeResult
(
keys
);
getKeysFreeResult
(
keys
);
}
}
void
sendTrackingMessage
(
client
*
c
,
long
long
hash
)
{
int
using_redirection
=
0
;
if
(
c
->
client_tracking_redirection
)
{
client
*
redir
=
lookupClientByID
(
c
->
client_tracking_redirection
);
if
(
!
redir
)
{
/* We need to signal to the original connection that we
* are unable to send invalidation messages to the redirected
* connection, because the client no longer exist. */
if
(
c
->
resp
>
2
)
{
addReplyPushLen
(
c
,
3
);
addReplyBulkCBuffer
(
c
,
"tracking-redir-broken"
,
21
);
addReplyLongLong
(
c
,
c
->
client_tracking_redirection
);
}
return
;
}
c
=
redir
;
using_redirection
=
1
;
}
/* Only send such info for clients in RESP version 3 or more. However
* if redirection is active, and the connection we redirect to is
* in Pub/Sub mode, we can support the feature with RESP 2 as well,
* by sending Pub/Sub messages in the __redis__:invalidate channel. */
if
(
c
->
resp
>
2
)
{
addReplyPushLen
(
c
,
2
);
addReplyBulkCBuffer
(
c
,
"invalidate"
,
10
);
addReplyLongLong
(
c
,
hash
);
}
else
if
(
using_redirection
&&
c
->
flags
&
CLIENT_PUBSUB
)
{
robj
*
msg
=
createStringObjectFromLongLong
(
hash
);
addReplyPubsubMessage
(
c
,
TrackingChannelName
,
msg
);
decrRefCount
(
msg
);
}
}
/* This function is called from signalModifiedKey() or other places in Redis
/* This function is called from signalModifiedKey() or other places in Redis
* when a key changes value. In the context of keys tracking, our task here is
* when a key changes value. In the context of keys tracking, our task here is
* to send a notification to every client that may have keys about such . */
* to send a notification to every client that may have keys about such . */
...
@@ -133,38 +167,8 @@ void trackingInvalidateKey(robj *keyobj) {
...
@@ -133,38 +167,8 @@ void trackingInvalidateKey(robj *keyobj) {
uint64_t
id
;
uint64_t
id
;
memcpy
(
&
id
,
ri
.
key
,
ri
.
key_len
);
memcpy
(
&
id
,
ri
.
key
,
ri
.
key_len
);
client
*
c
=
lookupClientByID
(
id
);
client
*
c
=
lookupClientByID
(
id
);
if
(
c
==
NULL
)
continue
;
if
(
c
==
NULL
||
!
(
c
->
flags
&
CLIENT_TRACKING
))
continue
;
int
using_redirection
=
0
;
sendTrackingMessage
(
c
,
hash
);
if
(
c
->
client_tracking_redirection
)
{
client
*
redir
=
lookupClientByID
(
c
->
client_tracking_redirection
);
if
(
!
redir
)
{
/* We need to signal to the original connection that we
* are unable to send invalidation messages to the redirected
* connection, because the client no longer exist. */
if
(
c
->
resp
>
2
)
{
addReplyPushLen
(
c
,
3
);
addReplyBulkCBuffer
(
c
,
"tracking-redir-broken"
,
21
);
addReplyLongLong
(
c
,
c
->
client_tracking_redirection
);
}
continue
;
}
c
=
redir
;
using_redirection
=
1
;
}
/* Only send such info for clients in RESP version 3 or more. However
* if redirection is active, and the connection we redirect to is
* in Pub/Sub mode, we can support the feature with RESP 2 as well,
* by sending Pub/Sub messages in the __redis__:invalidate channel. */
if
(
c
->
resp
>
2
)
{
addReplyPushLen
(
c
,
2
);
addReplyBulkCBuffer
(
c
,
"invalidate"
,
10
);
addReplyLongLong
(
c
,
hash
);
}
else
if
(
using_redirection
&&
c
->
flags
&
CLIENT_PUBSUB
)
{
robj
*
msg
=
createStringObjectFromLongLong
(
hash
);
addReplyPubsubMessage
(
c
,
TrackingChannelName
,
msg
);
decrRefCount
(
msg
);
}
}
}
raxStop
(
&
ri
);
raxStop
(
&
ri
);
...
@@ -173,3 +177,18 @@ void trackingInvalidateKey(robj *keyobj) {
...
@@ -173,3 +177,18 @@ void trackingInvalidateKey(robj *keyobj) {
raxFree
(
TrackingTable
[
hash
]);
raxFree
(
TrackingTable
[
hash
]);
TrackingTable
[
hash
]
=
NULL
;
TrackingTable
[
hash
]
=
NULL
;
}
}
void
trackingInvalidateKeysOnFlush
(
int
dbid
)
{
UNUSED
(
dbid
);
if
(
server
.
tracking_clients
==
0
)
return
;
listNode
*
ln
;
listIter
li
;
listRewind
(
server
.
clients
,
&
li
);
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
client
*
c
=
listNodeValue
(
ln
);
if
(
c
->
flags
&
CLIENT_TRACKING
)
{
sendTrackingMessage
(
c
,
-
1
);
}
}
}
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