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
40194a2a
Commit
40194a2a
authored
Feb 12, 2020
by
antirez
Browse files
Tracking: BCAST: basic feature now works.
parent
71f3f3f1
Changes
3
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
40194a2a
...
@@ -2224,7 +2224,7 @@ NULL
...
@@ -2224,7 +2224,7 @@ NULL
* [PREFIX second] ... */
* [PREFIX second] ... */
long
long
redir
=
0
;
long
long
redir
=
0
;
int
bcast
=
0
;
int
bcast
=
0
;
robj
**
prefix
;
robj
**
prefix
=
NULL
;
size_t
numprefix
=
0
;
size_t
numprefix
=
0
;
/* Parse the options. */
/* Parse the options. */
...
...
src/server.c
View file @
40194a2a
...
@@ -2124,6 +2124,10 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
...
@@ -2124,6 +2124,10 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
if
(
listLength
(
server
.
unblocked_clients
))
if
(
listLength
(
server
.
unblocked_clients
))
processUnblockedClients
();
processUnblockedClients
();
/* Send the invalidation messages to clients participating to the
* client side caching protocol in broadcasting (BCAST) mode. */
trackingBroadcastInvalidationMessages
();
/* Write the AOF buffer on disk */
/* Write the AOF buffer on disk */
flushAppendOnlyFile
(
0
);
flushAppendOnlyFile
(
0
);
...
...
src/tracking.c
View file @
40194a2a
...
@@ -85,6 +85,8 @@ void disableTracking(client *c) {
...
@@ -85,6 +85,8 @@ void disableTracking(client *c) {
}
}
}
}
raxStop
(
&
ri
);
raxStop
(
&
ri
);
raxFree
(
c
->
client_tracking_prefixes
);
c
->
client_tracking_prefixes
=
NULL
;
}
}
/* Clear flags and adjust the count. */
/* Clear flags and adjust the count. */
...
@@ -108,6 +110,8 @@ void enableBcastTrackingForPrefix(client *c, char *prefix, size_t plen) {
...
@@ -108,6 +110,8 @@ void enableBcastTrackingForPrefix(client *c, char *prefix, size_t plen) {
raxInsert
(
PrefixTable
,(
unsigned
char
*
)
prefix
,
plen
,
bs
,
NULL
);
raxInsert
(
PrefixTable
,(
unsigned
char
*
)
prefix
,
plen
,
bs
,
NULL
);
}
}
if
(
raxTryInsert
(
bs
->
clients
,(
unsigned
char
*
)
&
c
,
sizeof
(
c
),
NULL
,
NULL
))
{
if
(
raxTryInsert
(
bs
->
clients
,(
unsigned
char
*
)
&
c
,
sizeof
(
c
),
NULL
,
NULL
))
{
if
(
c
->
client_tracking_prefixes
==
NULL
)
c
->
client_tracking_prefixes
=
raxNew
();
raxInsert
(
c
->
client_tracking_prefixes
,
raxInsert
(
c
->
client_tracking_prefixes
,
(
unsigned
char
*
)
prefix
,
plen
,
NULL
,
NULL
);
(
unsigned
char
*
)
prefix
,
plen
,
NULL
,
NULL
);
}
}
...
@@ -121,10 +125,10 @@ void enableBcastTrackingForPrefix(client *c, char *prefix, size_t plen) {
...
@@ -121,10 +125,10 @@ void enableBcastTrackingForPrefix(client *c, char *prefix, size_t plen) {
* inform it of the condition. Multiple clients can redirect the invalidation
* inform it of the condition. Multiple clients can redirect the invalidation
* messages to the same client ID. */
* messages to the same client ID. */
void
enableTracking
(
client
*
c
,
uint64_t
redirect_to
,
int
bcast
,
robj
**
prefix
,
size_t
numprefix
)
{
void
enableTracking
(
client
*
c
,
uint64_t
redirect_to
,
int
bcast
,
robj
**
prefix
,
size_t
numprefix
)
{
if
(
!
(
c
->
flags
&
CLIENT_TRACKING
))
server
.
tracking_clients
++
;
c
->
flags
|=
CLIENT_TRACKING
;
c
->
flags
|=
CLIENT_TRACKING
;
c
->
flags
&=
~
CLIENT_TRACKING_BROKEN_REDIR
;
c
->
flags
&=
~
(
CLIENT_TRACKING_BROKEN_REDIR
|
CLIENT_TRACKING_BCAST
)
;
c
->
client_tracking_redirection
=
redirect_to
;
c
->
client_tracking_redirection
=
redirect_to
;
if
(
!
(
c
->
flags
&
CLIENT_TRACKING
))
server
.
tracking_clients
++
;
if
(
TrackingTable
==
NULL
)
{
if
(
TrackingTable
==
NULL
)
{
TrackingTable
=
raxNew
();
TrackingTable
=
raxNew
();
PrefixTable
=
raxNew
();
PrefixTable
=
raxNew
();
...
@@ -229,8 +233,9 @@ void trackingRememberKeyToBroadcast(char *keyname, size_t keylen) {
...
@@ -229,8 +233,9 @@ void trackingRememberKeyToBroadcast(char *keyname, size_t keylen) {
raxStart
(
&
ri
,
PrefixTable
);
raxStart
(
&
ri
,
PrefixTable
);
raxSeek
(
&
ri
,
"^"
,
NULL
,
0
);
raxSeek
(
&
ri
,
"^"
,
NULL
,
0
);
while
(
raxNext
(
&
ri
))
{
while
(
raxNext
(
&
ri
))
{
if
(
keylen
>
ri
.
key_len
)
continue
;
if
(
ri
.
key_len
>
keylen
)
continue
;
if
(
memcmp
(
ri
.
key
,
keyname
,
ri
.
key_len
)
!=
0
)
continue
;
if
(
ri
.
key_len
!=
0
&&
memcmp
(
ri
.
key
,
keyname
,
ri
.
key_len
)
!=
0
)
continue
;
bcastState
*
bs
=
ri
.
data
;
bcastState
*
bs
=
ri
.
data
;
raxTryInsert
(
bs
->
keys
,(
unsigned
char
*
)
keyname
,
keylen
,
NULL
,
NULL
);
raxTryInsert
(
bs
->
keys
,(
unsigned
char
*
)
keyname
,
keylen
,
NULL
,
NULL
);
}
}
...
@@ -362,10 +367,15 @@ void trackingLimitUsedSlots(void) {
...
@@ -362,10 +367,15 @@ void trackingLimitUsedSlots(void) {
* notifications to each client in each prefix. */
* notifications to each client in each prefix. */
void
trackingBroadcastInvalidationMessages
(
void
)
{
void
trackingBroadcastInvalidationMessages
(
void
)
{
raxIterator
ri
,
ri2
;
raxIterator
ri
,
ri2
;
/* Return ASAP if there is nothing to do here. */
if
(
TrackingTable
==
NULL
||
!
server
.
tracking_clients
)
return
;
raxStart
(
&
ri
,
PrefixTable
);
raxStart
(
&
ri
,
PrefixTable
);
raxSeek
(
&
ri
,
"^"
,
NULL
,
0
);
raxSeek
(
&
ri
,
"^"
,
NULL
,
0
);
while
(
raxNext
(
&
ri
))
{
while
(
raxNext
(
&
ri
))
{
bcastState
*
bs
=
ri
.
data
;
bcastState
*
bs
=
ri
.
data
;
if
(
raxSize
(
bs
->
keys
))
{
/* Create the array reply with the list of keys once, then send
/* Create the array reply with the list of keys once, then send
* it to all the clients subscribed to this prefix. */
* it to all the clients subscribed to this prefix. */
char
buf
[
32
];
char
buf
[
32
];
...
@@ -379,7 +389,9 @@ void trackingBroadcastInvalidationMessages(void) {
...
@@ -379,7 +389,9 @@ void trackingBroadcastInvalidationMessages(void) {
raxSeek
(
&
ri2
,
"^"
,
NULL
,
0
);
raxSeek
(
&
ri2
,
"^"
,
NULL
,
0
);
while
(
raxNext
(
&
ri2
))
{
while
(
raxNext
(
&
ri2
))
{
len
=
ll2string
(
buf
,
sizeof
(
buf
),
ri2
.
key_len
);
len
=
ll2string
(
buf
,
sizeof
(
buf
),
ri2
.
key_len
);
sds
proto
=
sdsnewlen
(
"$"
,
1
);
proto
=
sdscatlen
(
proto
,
"$"
,
1
);
proto
=
sdscatlen
(
proto
,
buf
,
len
);
proto
=
sdscatlen
(
proto
,
"
\r\n
"
,
2
);
proto
=
sdscatlen
(
proto
,
ri2
.
key
,
ri2
.
key_len
);
proto
=
sdscatlen
(
proto
,
ri2
.
key
,
ri2
.
key_len
);
proto
=
sdscatlen
(
proto
,
"
\r\n
"
,
2
);
proto
=
sdscatlen
(
proto
,
"
\r\n
"
,
2
);
}
}
...
@@ -399,9 +411,8 @@ void trackingBroadcastInvalidationMessages(void) {
...
@@ -399,9 +411,8 @@ void trackingBroadcastInvalidationMessages(void) {
* want to only track the new keys that will be accumulated starting
* want to only track the new keys that will be accumulated starting
* from now. */
* from now. */
sdsfree
(
proto
);
sdsfree
(
proto
);
raxFree
(
bs
->
clients
);
}
raxFree
(
bs
->
keys
);
raxFree
(
bs
->
keys
);
bs
->
clients
=
raxNew
();
bs
->
keys
=
raxNew
();
bs
->
keys
=
raxNew
();
}
}
raxStop
(
&
ri
);
raxStop
(
&
ri
);
...
...
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