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
2ab6fef0
Commit
2ab6fef0
authored
Feb 22, 2021
by
Oran Agra
Browse files
Merge origin/unstable into 6.2
parents
2dba1e39
8e83bcd2
Changes
87
Hide whitespace changes
Inline
Side-by-side
.github/workflows/ci.yml
View file @
2ab6fef0
...
@@ -14,7 +14,7 @@ jobs:
...
@@ -14,7 +14,7 @@ jobs:
run
:
make REDIS_CFLAGS='-Werror' BUILD_TLS=yes
run
:
make REDIS_CFLAGS='-Werror' BUILD_TLS=yes
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get install tcl8.
5
sudo apt-get install tcl8.
6
./runtest --verbose
./runtest --verbose
-
name
:
module api test
-
name
:
module api test
run
:
./runtest-moduleapi --verbose
run
:
./runtest-moduleapi --verbose
...
@@ -58,14 +58,3 @@ jobs:
...
@@ -58,14 +58,3 @@ jobs:
run
:
|
run
:
|
yum -y install gcc make
yum -y install gcc make
make REDIS_CFLAGS='-Werror'
make REDIS_CFLAGS='-Werror'
build-freebsd
:
runs-on
:
macos-latest
steps
:
-
uses
:
actions/checkout@v2
-
name
:
make
uses
:
vmactions/freebsd-vm@v0.1.0
with
:
usesh
:
true
prepare
:
pkg install -y gmake
run
:
gmake
.github/workflows/daily.yml
View file @
2ab6fef0
...
@@ -20,8 +20,8 @@ jobs:
...
@@ -20,8 +20,8 @@ jobs:
run
:
make
run
:
make
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get install tcl8.
5
sudo apt-get install tcl8.
6
./runtest --accurate --verbose
./runtest --accurate --verbose
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
./runtest-moduleapi --verbose
run
:
./runtest-moduleapi --verbose
-
name
:
sentinel tests
-
name
:
sentinel tests
...
@@ -39,8 +39,8 @@ jobs:
...
@@ -39,8 +39,8 @@ jobs:
run
:
make MALLOC=libc
run
:
make MALLOC=libc
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get install tcl8.
5
sudo apt-get install tcl8.
6
./runtest --accurate --verbose
./runtest --accurate --verbose
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
./runtest-moduleapi --verbose
run
:
./runtest-moduleapi --verbose
-
name
:
sentinel tests
-
name
:
sentinel tests
...
@@ -60,8 +60,8 @@ jobs:
...
@@ -60,8 +60,8 @@ jobs:
make 32bit
make 32bit
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get install tcl8.
5
sudo apt-get install tcl8.
6
./runtest --accurate --verbose
./runtest --accurate --verbose
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
|
run
:
|
make -C tests/modules 32bit # the script below doesn't have an argument, we must build manually ahead of time
make -C tests/modules 32bit # the script below doesn't have an argument, we must build manually ahead of time
...
@@ -82,10 +82,10 @@ jobs:
...
@@ -82,10 +82,10 @@ jobs:
make BUILD_TLS=yes
make BUILD_TLS=yes
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get install tcl8.
5
tcl-tls
sudo apt-get install tcl8.
6
tcl-tls
./utils/gen-test-certs.sh
./utils/gen-test-certs.sh
./runtest --accurate --verbose --tls
./runtest --accurate --verbose --tls
--dump-logs
./runtest --accurate --verbose
./runtest --accurate --verbose
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
|
run
:
|
./runtest-moduleapi --verbose --tls
./runtest-moduleapi --verbose --tls
...
@@ -110,8 +110,8 @@ jobs:
...
@@ -110,8 +110,8 @@ jobs:
make
make
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get install tcl8.
5
tcl-tls
sudo apt-get install tcl8.
6
tcl-tls
./runtest --config io-threads 4 --config io-threads-do-reads yes --accurate --verbose --tags network
./runtest --config io-threads 4 --config io-threads-do-reads yes --accurate --verbose --tags network
--dump-logs
-
name
:
cluster tests
-
name
:
cluster tests
run
:
|
run
:
|
./runtest-cluster --config io-threads 4 --config io-threads-do-reads yes
./runtest-cluster --config io-threads 4 --config io-threads-do-reads yes
...
@@ -127,10 +127,10 @@ jobs:
...
@@ -127,10 +127,10 @@ jobs:
-
name
:
test
-
name
:
test
run
:
|
run
:
|
sudo apt-get update
sudo apt-get update
sudo apt-get install tcl8.
5
valgrind -y
sudo apt-get install tcl8.
6
valgrind -y
./runtest --valgrind --verbose --clients 1
./runtest --valgrind --verbose --clients 1
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
./runtest-moduleapi --valgrind --verbose --clients
1
run
:
./runtest-moduleapi --valgrind
--no-latency
--verbose --clients
1
test-centos7-jemalloc
:
test-centos7-jemalloc
:
runs-on
:
ubuntu-latest
runs-on
:
ubuntu-latest
...
@@ -146,7 +146,7 @@ jobs:
...
@@ -146,7 +146,7 @@ jobs:
-
name
:
test
-
name
:
test
run
:
|
run
:
|
yum -y install which tcl
yum -y install which tcl
./runtest --accurate --verbose
./runtest --accurate --verbose
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
./runtest-moduleapi --verbose
run
:
./runtest-moduleapi --verbose
-
name
:
sentinel tests
-
name
:
sentinel tests
...
@@ -170,8 +170,8 @@ jobs:
...
@@ -170,8 +170,8 @@ jobs:
run
:
|
run
:
|
yum -y install tcl tcltls
yum -y install tcl tcltls
./utils/gen-test-certs.sh
./utils/gen-test-certs.sh
./runtest --accurate --verbose --tls
./runtest --accurate --verbose --tls
--dump-logs
./runtest --accurate --verbose
./runtest --accurate --verbose
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
|
run
:
|
./runtest-moduleapi --verbose --tls
./runtest-moduleapi --verbose --tls
...
@@ -195,7 +195,7 @@ jobs:
...
@@ -195,7 +195,7 @@ jobs:
run
:
make
run
:
make
-
name
:
test
-
name
:
test
run
:
|
run
:
|
./runtest --accurate --verbose --no-latency
./runtest --accurate --verbose --no-latency
--dump-logs
-
name
:
module api test
-
name
:
module api test
run
:
./runtest-moduleapi --verbose
run
:
./runtest-moduleapi --verbose
-
name
:
sentinel tests
-
name
:
sentinel tests
...
@@ -210,13 +210,14 @@ jobs:
...
@@ -210,13 +210,14 @@ jobs:
steps
:
steps
:
-
uses
:
actions/checkout@v2
-
uses
:
actions/checkout@v2
-
name
:
test
-
name
:
test
uses
:
vmactions/freebsd-vm@v0.1.
0
uses
:
vmactions/freebsd-vm@v0.1.
2
with
:
with
:
usesh
:
true
usesh
:
true
prepare
:
pkg install -y gmake lang/tcl85
sync
:
rsync
run
:
|
prepare
:
pkg install -y bash gmake lang/tcl86
gmake
run
:
>
./runtest --accurate --verbose --no-latency
gmake &&
MAKE=gmake ./runtest-moduleapi --verbose
./runtest --accurate --verbose --no-latency --dump-logs &&
./runtest-sentinel
MAKE=gmake ./runtest-moduleapi --verbose &&
./runtest-sentinel &&
./runtest-cluster
./runtest-cluster
CONDUCT
0 → 100644
View file @
2ab6fef0
Contributor Covenant Code of Conduct
Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others’ private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
this email address: redis@redis.io.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
1. Correction
Community Impact: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
Consequence: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
2. Warning
Community Impact: A violation through a single incident or series
of actions.
Consequence: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
3. Temporary Ban
Community Impact: A serious violation of community standards, including
sustained inappropriate behavior.
Consequence: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
4. Permanent Ban
Community Impact: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
Consequence: A permanent ban from any sort of public interaction within
the community.
Attribution
This Code of Conduct is adapted from the Contributor Covenant,
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by Mozilla’s code of conduct
enforcement ladder.
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
\ No newline at end of file
runtest-moduleapi
View file @
2ab6fef0
...
@@ -32,5 +32,7 @@ $TCLSH tests/test_helper.tcl \
...
@@ -32,5 +32,7 @@ $TCLSH tests/test_helper.tcl \
--single
unit/moduleapi/getkeys
\
--single
unit/moduleapi/getkeys
\
--single
unit/moduleapi/test_lazyfree
\
--single
unit/moduleapi/test_lazyfree
\
--single
unit/moduleapi/defrag
\
--single
unit/moduleapi/defrag
\
--single
unit/moduleapi/hash
\
--single
unit/moduleapi/zset
\
--single
unit/moduleapi/stream
\
--single
unit/moduleapi/stream
\
"
${
@
}
"
"
${
@
}
"
src/acl.c
View file @
2ab6fef0
...
@@ -814,8 +814,6 @@ void ACLAddAllowedSubcommand(user *u, unsigned long id, const char *sub) {
...
@@ -814,8 +814,6 @@ void ACLAddAllowedSubcommand(user *u, unsigned long id, const char *sub) {
* invalid (contains non allowed characters).
* invalid (contains non allowed characters).
* ENOENT: The command name or command category provided with + or - is not
* ENOENT: The command name or command category provided with + or - is not
* known.
* known.
* EBUSY: The subcommand you want to add is about a command that is currently
* fully added.
* EEXIST: You are adding a key pattern after "*" was already added. This is
* EEXIST: You are adding a key pattern after "*" was already added. This is
* almost surely an error on the user side.
* almost surely an error on the user side.
* EISDIR: You are adding a channel pattern after "*" was already added. This is
* EISDIR: You are adding a channel pattern after "*" was already added. This is
...
@@ -976,22 +974,12 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
...
@@ -976,22 +974,12 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
return
C_ERR
;
return
C_ERR
;
}
}
/* The command should not be set right now in the command
* bitmap, because adding a subcommand of a fully added
* command is probably an error on the user side. */
unsigned
long
id
=
ACLGetCommandID
(
copy
);
unsigned
long
id
=
ACLGetCommandID
(
copy
);
if
(
ACLGetUserCommandBit
(
u
,
id
)
==
1
)
{
/* Add the subcommand to the list of valid ones, if the command is not set. */
zfree
(
copy
);
if
(
ACLGetUserCommandBit
(
u
,
id
)
==
0
)
{
errno
=
EBUSY
;
ACLAddAllowedSubcommand
(
u
,
id
,
sub
);
return
C_ERR
;
}
}
/* Add the subcommand to the list of valid ones. */
ACLAddAllowedSubcommand
(
u
,
id
,
sub
);
/* We have to clear the command bit so that we force the
* subcommand check. */
ACLSetUserCommandBit
(
u
,
id
,
0
);
zfree
(
copy
);
zfree
(
copy
);
}
}
}
else
if
(
op
[
0
]
==
'-'
&&
op
[
1
]
!=
'@'
)
{
}
else
if
(
op
[
0
]
==
'-'
&&
op
[
1
]
!=
'@'
)
{
...
@@ -1030,10 +1018,6 @@ const char *ACLSetUserStringError(void) {
...
@@ -1030,10 +1018,6 @@ const char *ACLSetUserStringError(void) {
errmsg
=
"Unknown command or category name in ACL"
;
errmsg
=
"Unknown command or category name in ACL"
;
else
if
(
errno
==
EINVAL
)
else
if
(
errno
==
EINVAL
)
errmsg
=
"Syntax error"
;
errmsg
=
"Syntax error"
;
else
if
(
errno
==
EBUSY
)
errmsg
=
"Adding a subcommand of a command already fully "
"added is not allowed. Remove the command to start. "
"Example: -DEBUG +DEBUG|DIGEST"
;
else
if
(
errno
==
EEXIST
)
else
if
(
errno
==
EEXIST
)
errmsg
=
"Adding a pattern after the * pattern (or the "
errmsg
=
"Adding a pattern after the * pattern (or the "
"'allkeys' flag) is not valid and does not have any "
"'allkeys' flag) is not valid and does not have any "
...
@@ -2253,7 +2237,7 @@ void authCommand(client *c) {
...
@@ -2253,7 +2237,7 @@ void authCommand(client *c) {
return
;
return
;
}
}
username
=
createStringObject
(
"default"
,
7
);
username
=
shared
.
default_username
;
password
=
c
->
argv
[
1
];
password
=
c
->
argv
[
1
];
}
else
{
}
else
{
username
=
c
->
argv
[
1
];
username
=
c
->
argv
[
1
];
...
@@ -2265,9 +2249,5 @@ void authCommand(client *c) {
...
@@ -2265,9 +2249,5 @@ void authCommand(client *c) {
}
else
{
}
else
{
addReplyError
(
c
,
"-WRONGPASS invalid username-password pair or user is disabled."
);
addReplyError
(
c
,
"-WRONGPASS invalid username-password pair or user is disabled."
);
}
}
/* Free the "default" string object we created for the two
* arguments form. */
if
(
c
->
argc
==
2
)
decrRefCount
(
username
);
}
}
src/aof.c
View file @
2ab6fef0
...
@@ -588,11 +588,10 @@ sds catAppendOnlyExpireAtCommand(sds buf, struct redisCommand *cmd, robj *key, r
...
@@ -588,11 +588,10 @@ sds catAppendOnlyExpireAtCommand(sds buf, struct redisCommand *cmd, robj *key, r
}
}
decrRefCount
(
seconds
);
decrRefCount
(
seconds
);
argv
[
0
]
=
createStringObject
(
"PEXPIREAT"
,
9
)
;
argv
[
0
]
=
shared
.
pexpireat
;
argv
[
1
]
=
key
;
argv
[
1
]
=
key
;
argv
[
2
]
=
createStringObjectFromLongLong
(
when
);
argv
[
2
]
=
createStringObjectFromLongLong
(
when
);
buf
=
catAppendOnlyGenericCommand
(
buf
,
3
,
argv
);
buf
=
catAppendOnlyGenericCommand
(
buf
,
3
,
argv
);
decrRefCount
(
argv
[
0
]);
decrRefCount
(
argv
[
2
]);
decrRefCount
(
argv
[
2
]);
return
buf
;
return
buf
;
}
}
...
@@ -1441,7 +1440,7 @@ int rewriteAppendOnlyFileRio(rio *aof) {
...
@@ -1441,7 +1440,7 @@ int rewriteAppendOnlyFileRio(rio *aof) {
size_t
processed
=
0
;
size_t
processed
=
0
;
int
j
;
int
j
;
long
key_count
=
0
;
long
key_count
=
0
;
long
long
cow_
updated_time
=
0
;
long
long
updated_time
=
0
;
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
char
selectcmd
[]
=
"*2
\r\n
$6
\r\n
SELECT
\r\n
"
;
char
selectcmd
[]
=
"*2
\r\n
$6
\r\n
SELECT
\r\n
"
;
...
@@ -1502,18 +1501,16 @@ int rewriteAppendOnlyFileRio(rio *aof) {
...
@@ -1502,18 +1501,16 @@ int rewriteAppendOnlyFileRio(rio *aof) {
aofReadDiffFromParent
();
aofReadDiffFromParent
();
}
}
/* Update
COW
info every 1 second (approximately).
/* Update info every 1 second (approximately).
* in order to avoid calling mstime() on each iteration, we will
* in order to avoid calling mstime() on each iteration, we will
* check the diff every 1024 keys */
* check the diff every 1024 keys */
if
((
key_count
&
1023
)
==
0
)
{
if
((
key_count
++
&
1023
)
==
0
)
{
key_count
=
0
;
long
long
now
=
mstime
();
long
long
now
=
mstime
();
if
(
now
-
cow_
updated_time
>=
1000
)
{
if
(
now
-
updated_time
>=
1000
)
{
sendChild
COW
Info
(
CHILD_TYPE_
AOF
,
0
,
"AOF rewrite"
);
sendChildInfo
(
CHILD_
INFO_
TYPE_
CURRENT_INFO
,
key_count
,
"AOF rewrite"
);
cow_
updated_time
=
now
;
updated_time
=
now
;
}
}
}
}
key_count
++
;
}
}
dictReleaseIterator
(
di
);
dictReleaseIterator
(
di
);
di
=
NULL
;
di
=
NULL
;
...
@@ -1614,7 +1611,7 @@ int rewriteAppendOnlyFile(char *filename) {
...
@@ -1614,7 +1611,7 @@ int rewriteAppendOnlyFile(char *filename) {
size_t
bytes_to_write
=
sdslen
(
server
.
aof_child_diff
);
size_t
bytes_to_write
=
sdslen
(
server
.
aof_child_diff
);
const
char
*
buf
=
server
.
aof_child_diff
;
const
char
*
buf
=
server
.
aof_child_diff
;
long
long
cow_updated_time
=
mstime
();
long
long
cow_updated_time
=
mstime
();
long
long
key_count
=
dbTotalServerKeyCount
();
while
(
bytes_to_write
)
{
while
(
bytes_to_write
)
{
/* We write the AOF buffer in chunk of 8MB so that we can check the time in between them */
/* We write the AOF buffer in chunk of 8MB so that we can check the time in between them */
size_t
chunk_size
=
bytes_to_write
<
(
8
<<
20
)
?
bytes_to_write
:
(
8
<<
20
);
size_t
chunk_size
=
bytes_to_write
<
(
8
<<
20
)
?
bytes_to_write
:
(
8
<<
20
);
...
@@ -1628,7 +1625,7 @@ int rewriteAppendOnlyFile(char *filename) {
...
@@ -1628,7 +1625,7 @@ int rewriteAppendOnlyFile(char *filename) {
/* Update COW info */
/* Update COW info */
long
long
now
=
mstime
();
long
long
now
=
mstime
();
if
(
now
-
cow_updated_time
>=
1000
)
{
if
(
now
-
cow_updated_time
>=
1000
)
{
sendChild
COW
Info
(
CHILD_TYPE_
AOF
,
0
,
"AOF rewrite"
);
sendChildInfo
(
CHILD_
INFO_
TYPE_
CURRENT_INFO
,
key_count
,
"AOF rewrite"
);
cow_updated_time
=
now
;
cow_updated_time
=
now
;
}
}
}
}
...
@@ -1762,7 +1759,7 @@ int rewriteAppendOnlyFileBackground(void) {
...
@@ -1762,7 +1759,7 @@ int rewriteAppendOnlyFileBackground(void) {
redisSetCpuAffinity
(
server
.
aof_rewrite_cpulist
);
redisSetCpuAffinity
(
server
.
aof_rewrite_cpulist
);
snprintf
(
tmpfile
,
256
,
"temp-rewriteaof-bg-%d.aof"
,
(
int
)
getpid
());
snprintf
(
tmpfile
,
256
,
"temp-rewriteaof-bg-%d.aof"
,
(
int
)
getpid
());
if
(
rewriteAppendOnlyFile
(
tmpfile
)
==
C_OK
)
{
if
(
rewriteAppendOnlyFile
(
tmpfile
)
==
C_OK
)
{
sendChildC
OW
Info
(
CHILD_TYPE_AOF
,
1
,
"AOF rewrite"
);
sendChildC
ow
Info
(
CHILD_
INFO_
TYPE_AOF
_COW_SIZE
,
"AOF rewrite"
);
exitFromChild
(
0
);
exitFromChild
(
0
);
}
else
{
}
else
{
exitFromChild
(
1
);
exitFromChild
(
1
);
...
...
src/childinfo.c
View file @
2ab6fef0
...
@@ -31,9 +31,10 @@
...
@@ -31,9 +31,10 @@
#include <unistd.h>
#include <unistd.h>
typedef
struct
{
typedef
struct
{
int
process_type
;
/* AOF or RDB child? */
size_t
keys
;
int
on_exit
;
/* COW size of active or exited child */
size_t
cow
;
size_t
cow_size
;
/* Copy on write size. */
double
progress
;
childInfoType
information_type
;
/* Type of information */
}
child_info_data
;
}
child_info_data
;
/* Open a child-parent channel used in order to move information about the
/* Open a child-parent channel used in order to move information about the
...
@@ -64,39 +65,49 @@ void closeChildInfoPipe(void) {
...
@@ -64,39 +65,49 @@ void closeChildInfoPipe(void) {
}
}
}
}
/* Send
COW
data to parent. */
/* Send
save
data to parent. */
void
sendChildInfo
(
int
process_t
ype
,
in
t
on_exit
,
size_t
cow_siz
e
)
{
void
sendChildInfo
Generic
(
childInfoT
ype
in
fo_type
,
size_t
keys
,
double
progress
,
char
*
pnam
e
)
{
if
(
server
.
child_info_pipe
[
1
]
==
-
1
)
return
;
if
(
server
.
child_info_pipe
[
1
]
==
-
1
)
return
;
child_info_data
buffer
=
{.
process_type
=
process_type
,
.
on_exit
=
on_exit
,
.
cow_size
=
cow_size
};
child_info_data
data
=
{
0
};
/* zero everything, including padding to sattisfy valgrind */
ssize_t
wlen
=
sizeof
(
buffer
);
data
.
information_type
=
info_type
;
data
.
keys
=
keys
;
data
.
cow
=
zmalloc_get_private_dirty
(
-
1
);
data
.
progress
=
progress
;
if
(
write
(
server
.
child_info_pipe
[
1
],
&
buffer
,
wlen
)
!=
wlen
)
{
if
(
data
.
cow
)
{
/* Nothing to do on error, this will be detected by the other side. */
serverLog
((
info_type
==
CHILD_INFO_TYPE_CURRENT_INFO
)
?
LL_VERBOSE
:
LL_NOTICE
,
"%s: %zu MB of memory used by copy-on-write"
,
pname
,
data
.
cow
/
(
1024
*
1024
));
}
}
}
/* Update COW data. */
ssize_t
wlen
=
sizeof
(
data
);
void
updateChildInfo
(
int
process_type
,
int
on_exit
,
size_t
cow_size
)
{
if
(
!
on_exit
)
{
if
(
write
(
server
.
child_info_pipe
[
1
],
&
data
,
wlen
)
!=
wlen
)
{
server
.
stat_current_cow_bytes
=
cow_size
;
/* Nothing to do on error, this will be detected by the other side. */
return
;
}
}
}
if
(
process_type
==
CHILD_TYPE_RDB
)
{
/* Update Child info. */
server
.
stat_rdb_cow_bytes
=
cow_size
;
void
updateChildInfo
(
childInfoType
information_type
,
size_t
cow
,
size_t
keys
,
double
progress
)
{
}
else
if
(
process_type
==
CHILD_TYPE_AOF
)
{
if
(
information_type
==
CHILD_INFO_TYPE_CURRENT_INFO
)
{
server
.
stat_aof_cow_bytes
=
cow_size
;
server
.
stat_current_cow_bytes
=
cow
;
}
else
if
(
process_type
==
CHILD_TYPE_MODULE
)
{
server
.
stat_current_save_keys_processed
=
keys
;
server
.
stat_module_cow_bytes
=
cow_size
;
if
(
progress
!=
-
1
)
server
.
stat_module_progress
=
progress
;
}
else
if
(
information_type
==
CHILD_INFO_TYPE_AOF_COW_SIZE
)
{
server
.
stat_aof_cow_bytes
=
cow
;
}
else
if
(
information_type
==
CHILD_INFO_TYPE_RDB_COW_SIZE
)
{
server
.
stat_rdb_cow_bytes
=
cow
;
}
else
if
(
information_type
==
CHILD_INFO_TYPE_MODULE_COW_SIZE
)
{
server
.
stat_module_cow_bytes
=
cow
;
}
}
}
}
/* Read
COW
info data from the pipe.
/* Read
child
info data from the pipe.
* if complete data read into the buffer,
process type, copy-on-write type and copy-on-write size
* if complete data read into the buffer,
*
are
stored into *
process_type, *on_exit and *cow_size respectively
and returns 1.
*
data is
stored into *
buffer,
and returns 1.
* otherwise, the partial data is left in the buffer, waiting for the next read, and returns 0. */
* otherwise, the partial data is left in the buffer, waiting for the next read, and returns 0. */
int
readChildInfo
(
int
*
process_type
,
int
*
on_exit
,
size_t
*
cow
_
size
)
{
int
readChildInfo
(
childInfoType
*
information_type
,
size_t
*
cow
,
size
_t
*
keys
,
double
*
progress
)
{
/* We are using here a static buffer in combination with the server.child_info_nread to handle short reads */
/* We are using here a static buffer in combination with the server.child_info_nread to handle short reads */
static
child_info_data
buffer
;
static
child_info_data
buffer
;
ssize_t
wlen
=
sizeof
(
buffer
);
ssize_t
wlen
=
sizeof
(
buffer
);
...
@@ -111,25 +122,27 @@ int readChildInfo(int *process_type, int *on_exit, size_t *cow_size) {
...
@@ -111,25 +122,27 @@ int readChildInfo(int *process_type, int *on_exit, size_t *cow_size) {
/* We have complete child info */
/* We have complete child info */
if
(
server
.
child_info_nread
==
wlen
)
{
if
(
server
.
child_info_nread
==
wlen
)
{
*
process_type
=
buffer
.
process_type
;
*
information_type
=
buffer
.
information_type
;
*
on_exit
=
buffer
.
on_exit
;
*
cow
=
buffer
.
cow
;
*
cow_size
=
buffer
.
cow_size
;
*
keys
=
buffer
.
keys
;
*
progress
=
buffer
.
progress
;
return
1
;
return
1
;
}
else
{
}
else
{
return
0
;
return
0
;
}
}
}
}
/* Receive
COW
data from child. */
/* Receive
info
data from child. */
void
receiveChildInfo
(
void
)
{
void
receiveChildInfo
(
void
)
{
if
(
server
.
child_info_pipe
[
0
]
==
-
1
)
return
;
if
(
server
.
child_info_pipe
[
0
]
==
-
1
)
return
;
int
process_type
;
size_t
cow
;
int
on_exit
;
size_t
keys
;
size_t
cow_size
;
double
progress
;
childInfoType
information_type
;
/* Drain the pipe and update child info so that we get the final message. */
/* Drain the pipe and update child info so that we get the final message. */
while
(
readChildInfo
(
&
process_type
,
&
on_exit
,
&
cow_size
))
{
while
(
readChildInfo
(
&
information_type
,
&
cow
,
&
keys
,
&
progress
))
{
updateChildInfo
(
process_type
,
on_exit
,
cow_size
);
updateChildInfo
(
information_type
,
cow
,
keys
,
progress
);
}
}
}
}
src/cli_common.c
View file @
2ab6fef0
...
@@ -54,7 +54,7 @@ int cliSecureConnection(redisContext *c, cliSSLconfig config, const char **err)
...
@@ -54,7 +54,7 @@ int cliSecureConnection(redisContext *c, cliSSLconfig config, const char **err)
goto
error
;
goto
error
;
}
}
SSL_CTX_set_options
(
ssl_ctx
,
SSL_OP_NO_SSLv2
|
SSL_OP_NO_SSLv3
);
SSL_CTX_set_options
(
ssl_ctx
,
SSL_OP_NO_SSLv2
|
SSL_OP_NO_SSLv3
);
SSL_CTX_set_verify
(
ssl_ctx
,
SSL_VERIFY_PEER
,
NULL
);
SSL_CTX_set_verify
(
ssl_ctx
,
config
.
skip_cert_verify
?
SSL_VERIFY_NONE
:
SSL_VERIFY_PEER
,
NULL
);
if
(
config
.
cacert
||
config
.
cacertdir
)
{
if
(
config
.
cacert
||
config
.
cacertdir
)
{
if
(
!
SSL_CTX_load_verify_locations
(
ssl_ctx
,
config
.
cacert
,
config
.
cacertdir
))
{
if
(
!
SSL_CTX_load_verify_locations
(
ssl_ctx
,
config
.
cacert
,
config
.
cacertdir
))
{
...
...
src/cli_common.h
View file @
2ab6fef0
...
@@ -10,6 +10,8 @@ typedef struct cliSSLconfig {
...
@@ -10,6 +10,8 @@ typedef struct cliSSLconfig {
char
*
cacert
;
char
*
cacert
;
/* Directory where trusted CA certificates are stored, or NULL */
/* Directory where trusted CA certificates are stored, or NULL */
char
*
cacertdir
;
char
*
cacertdir
;
/* Skip server certificate verification. */
int
skip_cert_verify
;
/* Client certificate to authenticate with, or NULL */
/* Client certificate to authenticate with, or NULL */
char
*
cert
;
char
*
cert
;
/* Private key file to authenticate with, or NULL */
/* Private key file to authenticate with, or NULL */
...
...
src/cluster.c
View file @
2ab6fef0
...
@@ -2126,7 +2126,7 @@ int clusterProcessPacket(clusterLink *link) {
...
@@ -2126,7 +2126,7 @@ int clusterProcessPacket(clusterLink *link) {
/* Don't bother creating useless objects if there are no
/* Don't bother creating useless objects if there are no
* Pub/Sub subscribers. */
* Pub/Sub subscribers. */
if
(
dictSize
(
server
.
pubsub_channels
)
||
if
(
dictSize
(
server
.
pubsub_channels
)
||
listLength
(
server
.
pubsub_patterns
))
dictSize
(
server
.
pubsub_patterns
))
{
{
channel_len
=
ntohl
(
hdr
->
data
.
publish
.
msg
.
channel_len
);
channel_len
=
ntohl
(
hdr
->
data
.
publish
.
msg
.
channel_len
);
message_len
=
ntohl
(
hdr
->
data
.
publish
.
msg
.
message_len
);
message_len
=
ntohl
(
hdr
->
data
.
publish
.
msg
.
message_len
);
...
@@ -2815,7 +2815,7 @@ void clusterPropagatePublish(robj *channel, robj *message) {
...
@@ -2815,7 +2815,7 @@ void clusterPropagatePublish(robj *channel, robj *message) {
* SLAVE node specific functions
* SLAVE node specific functions
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
/* This function sends a FAILOVE_AUTH_REQUEST message to every node in order to
/* This function sends a FAILOVE
R
_AUTH_REQUEST message to every node in order to
* see if there is the quorum for this slave instance to failover its failing
* see if there is the quorum for this slave instance to failover its failing
* master.
* master.
*
*
...
...
src/config.c
View file @
2ab6fef0
...
@@ -2517,7 +2517,7 @@ standardConfig configs[] = {
...
@@ -2517,7 +2517,7 @@ standardConfig configs[] = {
createLongLongConfig
(
"cluster-node-timeout"
,
NULL
,
MODIFIABLE_CONFIG
,
0
,
LLONG_MAX
,
server
.
cluster_node_timeout
,
15000
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"cluster-node-timeout"
,
NULL
,
MODIFIABLE_CONFIG
,
0
,
LLONG_MAX
,
server
.
cluster_node_timeout
,
15000
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"slowlog-log-slower-than"
,
NULL
,
MODIFIABLE_CONFIG
,
-
1
,
LLONG_MAX
,
server
.
slowlog_log_slower_than
,
10000
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"slowlog-log-slower-than"
,
NULL
,
MODIFIABLE_CONFIG
,
-
1
,
LLONG_MAX
,
server
.
slowlog_log_slower_than
,
10000
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"latency-monitor-threshold"
,
NULL
,
MODIFIABLE_CONFIG
,
0
,
LLONG_MAX
,
server
.
latency_monitor_threshold
,
0
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"latency-monitor-threshold"
,
NULL
,
MODIFIABLE_CONFIG
,
0
,
LLONG_MAX
,
server
.
latency_monitor_threshold
,
0
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"proto-max-bulk-len"
,
NULL
,
MODIFIABLE_CONFIG
,
1024
*
1024
,
L
LONG_MAX
,
server
.
proto_max_bulk_len
,
512ll
*
1024
*
1024
,
MEMORY_CONFIG
,
NULL
,
NULL
),
/* Bulk request max size */
createLongLongConfig
(
"proto-max-bulk-len"
,
NULL
,
MODIFIABLE_CONFIG
,
1024
*
1024
,
LONG_MAX
,
server
.
proto_max_bulk_len
,
512ll
*
1024
*
1024
,
MEMORY_CONFIG
,
NULL
,
NULL
),
/* Bulk request max size */
createLongLongConfig
(
"stream-node-max-entries"
,
NULL
,
MODIFIABLE_CONFIG
,
0
,
LLONG_MAX
,
server
.
stream_node_max_entries
,
100
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"stream-node-max-entries"
,
NULL
,
MODIFIABLE_CONFIG
,
0
,
LLONG_MAX
,
server
.
stream_node_max_entries
,
100
,
INTEGER_CONFIG
,
NULL
,
NULL
),
createLongLongConfig
(
"repl-backlog-size"
,
NULL
,
MODIFIABLE_CONFIG
,
1
,
LLONG_MAX
,
server
.
repl_backlog_size
,
1024
*
1024
,
MEMORY_CONFIG
,
NULL
,
updateReplBacklogSize
),
/* Default: 1mb */
createLongLongConfig
(
"repl-backlog-size"
,
NULL
,
MODIFIABLE_CONFIG
,
1
,
LLONG_MAX
,
server
.
repl_backlog_size
,
1024
*
1024
,
MEMORY_CONFIG
,
NULL
,
updateReplBacklogSize
),
/* Default: 1mb */
...
...
src/db.c
View file @
2ab6fef0
...
@@ -106,9 +106,8 @@ robj *lookupKeyReadWithFlags(redisDb *db, robj *key, int flags) {
...
@@ -106,9 +106,8 @@ robj *lookupKeyReadWithFlags(redisDb *db, robj *key, int flags) {
robj
*
val
;
robj
*
val
;
if
(
expireIfNeeded
(
db
,
key
)
==
1
)
{
if
(
expireIfNeeded
(
db
,
key
)
==
1
)
{
/* Key expired. If we are in the context of a master, expireIfNeeded()
/* If we are in the context of a master, expireIfNeeded() returns 1
* returns 0 only when the key does not exist at all, so it's safe
* when the key is no longer valid, so we can return NULL ASAP. */
* to return NULL ASAP. */
if
(
server
.
masterhost
==
NULL
)
if
(
server
.
masterhost
==
NULL
)
goto
keymiss
;
goto
keymiss
;
...
...
src/defrag.c
View file @
2ab6fef0
...
@@ -638,7 +638,7 @@ int defragRaxNode(raxNode **noderef) {
...
@@ -638,7 +638,7 @@ int defragRaxNode(raxNode **noderef) {
}
}
/* returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */
/* returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */
int
scanLaterStr
a
emListpacks
(
robj
*
ob
,
unsigned
long
*
cursor
,
long
long
endtime
,
long
long
*
defragged
)
{
int
scanLaterStre
a
mListpacks
(
robj
*
ob
,
unsigned
long
*
cursor
,
long
long
endtime
,
long
long
*
defragged
)
{
static
unsigned
char
last
[
sizeof
(
streamID
)];
static
unsigned
char
last
[
sizeof
(
streamID
)];
raxIterator
ri
;
raxIterator
ri
;
long
iterations
=
0
;
long
iterations
=
0
;
...
@@ -958,7 +958,7 @@ int defragLaterItem(dictEntry *de, unsigned long *cursor, long long endtime) {
...
@@ -958,7 +958,7 @@ int defragLaterItem(dictEntry *de, unsigned long *cursor, long long endtime) {
}
else
if
(
ob
->
type
==
OBJ_HASH
)
{
}
else
if
(
ob
->
type
==
OBJ_HASH
)
{
server
.
stat_active_defrag_hits
+=
scanLaterHash
(
ob
,
cursor
);
server
.
stat_active_defrag_hits
+=
scanLaterHash
(
ob
,
cursor
);
}
else
if
(
ob
->
type
==
OBJ_STREAM
)
{
}
else
if
(
ob
->
type
==
OBJ_STREAM
)
{
return
scanLaterStr
a
emListpacks
(
ob
,
cursor
,
endtime
,
&
server
.
stat_active_defrag_hits
);
return
scanLaterStre
a
mListpacks
(
ob
,
cursor
,
endtime
,
&
server
.
stat_active_defrag_hits
);
}
else
if
(
ob
->
type
==
OBJ_MODULE
)
{
}
else
if
(
ob
->
type
==
OBJ_MODULE
)
{
return
moduleLateDefrag
(
dictGetKey
(
de
),
ob
,
cursor
,
endtime
,
&
server
.
stat_active_defrag_hits
);
return
moduleLateDefrag
(
dictGetKey
(
de
),
ob
,
cursor
,
endtime
,
&
server
.
stat_active_defrag_hits
);
}
else
{
}
else
{
...
...
src/dict.c
View file @
2ab6fef0
...
@@ -126,7 +126,7 @@ int _dictInit(dict *d, dictType *type,
...
@@ -126,7 +126,7 @@ int _dictInit(dict *d, dictType *type,
d
->
type
=
type
;
d
->
type
=
type
;
d
->
privdata
=
privDataPtr
;
d
->
privdata
=
privDataPtr
;
d
->
rehashidx
=
-
1
;
d
->
rehashidx
=
-
1
;
d
->
iterators
=
0
;
d
->
pauserehash
=
0
;
return
DICT_OK
;
return
DICT_OK
;
}
}
...
@@ -264,7 +264,7 @@ long long timeInMilliseconds(void) {
...
@@ -264,7 +264,7 @@ long long timeInMilliseconds(void) {
* than 0, and is smaller than 1 in most cases. The exact upper bound
* than 0, and is smaller than 1 in most cases. The exact upper bound
* depends on the running time of dictRehash(d,100).*/
* depends on the running time of dictRehash(d,100).*/
int
dictRehashMilliseconds
(
dict
*
d
,
int
ms
)
{
int
dictRehashMilliseconds
(
dict
*
d
,
int
ms
)
{
if
(
d
->
iterators
>
0
)
return
0
;
if
(
d
->
pauserehash
>
0
)
return
0
;
long
long
start
=
timeInMilliseconds
();
long
long
start
=
timeInMilliseconds
();
int
rehashes
=
0
;
int
rehashes
=
0
;
...
@@ -276,8 +276,8 @@ int dictRehashMilliseconds(dict *d, int ms) {
...
@@ -276,8 +276,8 @@ int dictRehashMilliseconds(dict *d, int ms) {
return
rehashes
;
return
rehashes
;
}
}
/* This function performs just a step of rehashing, and only if
there are
/* This function performs just a step of rehashing, and only if
hashing has
* no
safe iterators bound to
our hash table. When we have iterators in the
* no
t been paused for
our hash table. When we have iterators in the
* middle of a rehashing we can't mess with the two hash tables otherwise
* middle of a rehashing we can't mess with the two hash tables otherwise
* some element can be missed or duplicated.
* some element can be missed or duplicated.
*
*
...
@@ -285,7 +285,7 @@ int dictRehashMilliseconds(dict *d, int ms) {
...
@@ -285,7 +285,7 @@ int dictRehashMilliseconds(dict *d, int ms) {
* dictionary so that the hash table automatically migrates from H1 to H2
* dictionary so that the hash table automatically migrates from H1 to H2
* while it is actively used. */
* while it is actively used. */
static
void
_dictRehashStep
(
dict
*
d
)
{
static
void
_dictRehashStep
(
dict
*
d
)
{
if
(
d
->
iterators
==
0
)
dictRehash
(
d
,
1
);
if
(
d
->
pauserehash
==
0
)
dictRehash
(
d
,
1
);
}
}
/* Add an element to the target hash table */
/* Add an element to the target hash table */
...
@@ -301,7 +301,7 @@ int dictAdd(dict *d, void *key, void *val)
...
@@ -301,7 +301,7 @@ int dictAdd(dict *d, void *key, void *val)
/* Low level add or find:
/* Low level add or find:
* This function adds the entry but instead of setting a value returns the
* This function adds the entry but instead of setting a value returns the
* dictEntry structure to the user, that will make sure to fill the value
* dictEntry structure to the user, that will make sure to fill the value
* field as he wish
es
.
* field as
t
he
y
wish.
*
*
* This function is also directly exposed to the user API to be called
* This function is also directly exposed to the user API to be called
* mainly in order to store non-pointers inside the hash value, example:
* mainly in order to store non-pointers inside the hash value, example:
...
@@ -593,7 +593,7 @@ dictEntry *dictNext(dictIterator *iter)
...
@@ -593,7 +593,7 @@ dictEntry *dictNext(dictIterator *iter)
dictht
*
ht
=
&
iter
->
d
->
ht
[
iter
->
table
];
dictht
*
ht
=
&
iter
->
d
->
ht
[
iter
->
table
];
if
(
iter
->
index
==
-
1
&&
iter
->
table
==
0
)
{
if
(
iter
->
index
==
-
1
&&
iter
->
table
==
0
)
{
if
(
iter
->
safe
)
if
(
iter
->
safe
)
iter
->
d
->
iterators
++
;
dictPauseRehashing
(
iter
->
d
)
;
else
else
iter
->
fingerprint
=
dictFingerprint
(
iter
->
d
);
iter
->
fingerprint
=
dictFingerprint
(
iter
->
d
);
}
}
...
@@ -625,7 +625,7 @@ void dictReleaseIterator(dictIterator *iter)
...
@@ -625,7 +625,7 @@ void dictReleaseIterator(dictIterator *iter)
{
{
if
(
!
(
iter
->
index
==
-
1
&&
iter
->
table
==
0
))
{
if
(
!
(
iter
->
index
==
-
1
&&
iter
->
table
==
0
))
{
if
(
iter
->
safe
)
if
(
iter
->
safe
)
iter
->
d
->
iterators
--
;
dictResumeRehashing
(
iter
->
d
)
;
else
else
assert
(
iter
->
fingerprint
==
dictFingerprint
(
iter
->
d
));
assert
(
iter
->
fingerprint
==
dictFingerprint
(
iter
->
d
));
}
}
...
@@ -896,9 +896,8 @@ unsigned long dictScan(dict *d,
...
@@ -896,9 +896,8 @@ unsigned long dictScan(dict *d,
if
(
dictSize
(
d
)
==
0
)
return
0
;
if
(
dictSize
(
d
)
==
0
)
return
0
;
/* Having a safe iterator means no rehashing can happen, see _dictRehashStep.
/* This is needed in case the scan callback tries to do dictFind or alike. */
* This is needed in case the scan callback tries to do dictFind or alike. */
dictPauseRehashing
(
d
);
d
->
iterators
++
;
if
(
!
dictIsRehashing
(
d
))
{
if
(
!
dictIsRehashing
(
d
))
{
t0
=
&
(
d
->
ht
[
0
]);
t0
=
&
(
d
->
ht
[
0
]);
...
@@ -966,8 +965,7 @@ unsigned long dictScan(dict *d,
...
@@ -966,8 +965,7 @@ unsigned long dictScan(dict *d,
}
while
(
v
&
(
m0
^
m1
));
}
while
(
v
&
(
m0
^
m1
));
}
}
/* undo the ++ at the top */
dictResumeRehashing
(
d
);
d
->
iterators
--
;
return
v
;
return
v
;
}
}
...
@@ -1056,7 +1054,7 @@ void dictEmpty(dict *d, void(callback)(void*)) {
...
@@ -1056,7 +1054,7 @@ void dictEmpty(dict *d, void(callback)(void*)) {
_dictClear
(
d
,
&
d
->
ht
[
0
],
callback
);
_dictClear
(
d
,
&
d
->
ht
[
0
],
callback
);
_dictClear
(
d
,
&
d
->
ht
[
1
],
callback
);
_dictClear
(
d
,
&
d
->
ht
[
1
],
callback
);
d
->
rehashidx
=
-
1
;
d
->
rehashidx
=
-
1
;
d
->
iterators
=
0
;
d
->
pauserehash
=
0
;
}
}
void
dictEnableResize
(
void
)
{
void
dictEnableResize
(
void
)
{
...
...
src/dict.h
View file @
2ab6fef0
...
@@ -82,7 +82,7 @@ typedef struct dict {
...
@@ -82,7 +82,7 @@ typedef struct dict {
void
*
privdata
;
void
*
privdata
;
dictht
ht
[
2
];
dictht
ht
[
2
];
long
rehashidx
;
/* rehashing not in progress if rehashidx == -1 */
long
rehashidx
;
/* rehashing not in progress if rehashidx == -1 */
unsigned
long
iterators
;
/* number of iterators currently running
*/
int16_t
pauserehash
;
/* If >0 rehashing is paused (<0 indicates coding error)
*/
}
dict
;
}
dict
;
/* If safe is set to 1 this is a safe iterator, that means, you can call
/* If safe is set to 1 this is a safe iterator, that means, you can call
...
@@ -150,6 +150,8 @@ typedef void (dictScanBucketFunction)(void *privdata, dictEntry **bucketref);
...
@@ -150,6 +150,8 @@ typedef void (dictScanBucketFunction)(void *privdata, dictEntry **bucketref);
#define dictSlots(d) ((d)->ht[0].size+(d)->ht[1].size)
#define dictSlots(d) ((d)->ht[0].size+(d)->ht[1].size)
#define dictSize(d) ((d)->ht[0].used+(d)->ht[1].used)
#define dictSize(d) ((d)->ht[0].used+(d)->ht[1].used)
#define dictIsRehashing(d) ((d)->rehashidx != -1)
#define dictIsRehashing(d) ((d)->rehashidx != -1)
#define dictPauseRehashing(d) (d)->pauserehash++
#define dictResumeRehashing(d) (d)->pauserehash--
/* If our unsigned long type can store a 64 bit number, use a 64 bit PRNG. */
/* If our unsigned long type can store a 64 bit number, use a 64 bit PRNG. */
#if ULONG_MAX >= 0xffffffffffffffff
#if ULONG_MAX >= 0xffffffffffffffff
...
...
src/evict.c
View file @
2ab6fef0
...
@@ -135,7 +135,7 @@ void evictionPoolAlloc(void) {
...
@@ -135,7 +135,7 @@ void evictionPoolAlloc(void) {
/* This is an helper function for performEvictions(), it is used in order
/* This is an helper function for performEvictions(), it is used in order
* to populate the evictionPool with a few entries every time we want to
* to populate the evictionPool with a few entries every time we want to
* expire a key. Keys with idle time
small
er than one of the current
* expire a key. Keys with idle time
bigg
er than one of the current
* keys are added. Keys are always added if there are free entries.
* keys are added. Keys are always added if there are free entries.
*
*
* We insert keys on place in ascending order, so keys with the smaller
* We insert keys on place in ascending order, so keys with the smaller
...
...
src/expire.c
View file @
2ab6fef0
...
@@ -83,9 +83,8 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
...
@@ -83,9 +83,8 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
* keys that can be removed from the keyspace.
* keys that can be removed from the keyspace.
*
*
* Every expire cycle tests multiple databases: the next call will start
* Every expire cycle tests multiple databases: the next call will start
* again from the next db, with the exception of exists for time limit: in that
* again from the next db. No more than CRON_DBS_PER_CALL databases are
* case we restart again from the last database we were processing. Anyway
* tested at every iteration.
* no more than CRON_DBS_PER_CALL databases are tested at every iteration.
*
*
* The function can perform more or less work, depending on the "type"
* The function can perform more or less work, depending on the "type"
* argument. It can execute a "fast cycle" or a "slow cycle". The slow
* argument. It can execute a "fast cycle" or a "slow cycle". The slow
...
@@ -141,7 +140,7 @@ void activeExpireCycle(int type) {
...
@@ -141,7 +140,7 @@ void activeExpireCycle(int type) {
/* This function has some global state in order to continue the work
/* This function has some global state in order to continue the work
* incrementally across calls. */
* incrementally across calls. */
static
unsigned
int
current_db
=
0
;
/*
Las
t DB test
ed
. */
static
unsigned
int
current_db
=
0
;
/*
Nex
t DB
to
test. */
static
int
timelimit_exit
=
0
;
/* Time limit hit in previous call? */
static
int
timelimit_exit
=
0
;
/* Time limit hit in previous call? */
static
long
long
last_fast_cycle
=
0
;
/* When last fast cycle ran. */
static
long
long
last_fast_cycle
=
0
;
/* When last fast cycle ran. */
...
@@ -507,10 +506,15 @@ void expireGenericCommand(client *c, long long basetime, int unit) {
...
@@ -507,10 +506,15 @@ void expireGenericCommand(client *c, long long basetime, int unit) {
if
(
getLongLongFromObjectOrReply
(
c
,
param
,
&
when
,
NULL
)
!=
C_OK
)
if
(
getLongLongFromObjectOrReply
(
c
,
param
,
&
when
,
NULL
)
!=
C_OK
)
return
;
return
;
int
negative_when
=
when
<
0
;
if
(
unit
==
UNIT_SECONDS
)
when
*=
1000
;
if
(
unit
==
UNIT_SECONDS
)
when
*=
1000
;
when
+=
basetime
;
when
+=
basetime
;
if
(((
when
<
0
)
&&
!
negative_when
)
||
((
when
-
basetime
>
0
)
&&
negative_when
))
{
/* EXPIRE allows negative numbers, but we can at least detect an
* overflow by either unit conversion or basetime addition. */
addReplyErrorFormat
(
c
,
"invalid expire time in %s"
,
c
->
cmd
->
name
);
return
;
}
/* No key, return zero. */
/* No key, return zero. */
if
(
lookupKeyWrite
(
c
->
db
,
key
)
==
NULL
)
{
if
(
lookupKeyWrite
(
c
->
db
,
key
)
==
NULL
)
{
addReply
(
c
,
shared
.
czero
);
addReply
(
c
,
shared
.
czero
);
...
...
src/geo.c
View file @
2ab6fef0
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include "geo.h"
#include "geo.h"
#include "geohash_helper.h"
#include "geohash_helper.h"
#include "debugmacro.h"
#include "debugmacro.h"
#include "pqsort.h"
/* Things exported from t_zset.c only for geo.c, since it is the only other
/* Things exported from t_zset.c only for geo.c, since it is the only other
* part of Redis that requires close zset introspection. */
* part of Redis that requires close zset introspection. */
...
@@ -174,10 +175,10 @@ int extractDistanceOrReply(client *c, robj **argv,
...
@@ -174,10 +175,10 @@ int extractDistanceOrReply(client *c, robj **argv,
* that should be in the form: <number> <number> <unit>, and return C_OK or C_ERR means success or failure
* that should be in the form: <number> <number> <unit>, and return C_OK or C_ERR means success or failure
* *conversions is populated with the coefficient to use in order to convert meters to the unit.*/
* *conversions is populated with the coefficient to use in order to convert meters to the unit.*/
int
extractBoxOrReply
(
client
*
c
,
robj
**
argv
,
double
*
conversion
,
int
extractBoxOrReply
(
client
*
c
,
robj
**
argv
,
double
*
conversion
,
double
*
height
,
double
*
width
)
{
double
*
width
,
double
*
height
)
{
double
h
,
w
;
double
h
,
w
;
if
((
getDoubleFromObjectOrReply
(
c
,
argv
[
0
],
&
h
,
"need numeric
height
"
)
!=
C_OK
)
||
if
((
getDoubleFromObjectOrReply
(
c
,
argv
[
0
],
&
w
,
"need numeric
width
"
)
!=
C_OK
)
||
(
getDoubleFromObjectOrReply
(
c
,
argv
[
1
],
&
w
,
"need numeric
width
"
)
!=
C_OK
))
{
(
getDoubleFromObjectOrReply
(
c
,
argv
[
1
],
&
h
,
"need numeric
height
"
)
!=
C_OK
))
{
return
C_ERR
;
return
C_ERR
;
}
}
...
@@ -223,8 +224,10 @@ int geoAppendIfWithinShape(geoArray *ga, GeoShape *shape, double score, sds memb
...
@@ -223,8 +224,10 @@ int geoAppendIfWithinShape(geoArray *ga, GeoShape *shape, double score, sds memb
if
(
!
geohashGetDistanceIfInRadiusWGS84
(
shape
->
xy
[
0
],
shape
->
xy
[
1
],
xy
[
0
],
xy
[
1
],
if
(
!
geohashGetDistanceIfInRadiusWGS84
(
shape
->
xy
[
0
],
shape
->
xy
[
1
],
xy
[
0
],
xy
[
1
],
shape
->
t
.
radius
*
shape
->
conversion
,
&
distance
))
return
C_ERR
;
shape
->
t
.
radius
*
shape
->
conversion
,
&
distance
))
return
C_ERR
;
}
else
if
(
shape
->
type
==
RECTANGLE_TYPE
)
{
}
else
if
(
shape
->
type
==
RECTANGLE_TYPE
)
{
if
(
!
geohashGetDistanceIfInRectangle
(
shape
->
bounds
,
shape
->
xy
[
0
],
shape
->
xy
[
1
],
if
(
!
geohashGetDistanceIfInRectangle
(
shape
->
t
.
r
.
width
*
shape
->
conversion
,
xy
[
0
],
xy
[
1
],
&
distance
))
return
C_ERR
;
shape
->
t
.
r
.
height
*
shape
->
conversion
,
shape
->
xy
[
0
],
shape
->
xy
[
1
],
xy
[
0
],
xy
[
1
],
&
distance
))
return
C_ERR
;
}
}
/* Append the new element. */
/* Append the new element. */
...
@@ -634,8 +637,8 @@ void georadiusGeneric(client *c, int srcKeyIndex, int flags) {
...
@@ -634,8 +637,8 @@ void georadiusGeneric(client *c, int srcKeyIndex, int flags) {
flags
&
GEOSEARCH
&&
flags
&
GEOSEARCH
&&
!
byradius
)
!
byradius
)
{
{
if
(
extractBoxOrReply
(
c
,
c
->
argv
+
base_args
+
i
+
1
,
&
shape
.
conversion
,
&
shape
.
t
.
r
.
height
,
if
(
extractBoxOrReply
(
c
,
c
->
argv
+
base_args
+
i
+
1
,
&
shape
.
conversion
,
&
shape
.
t
.
r
.
width
,
&
shape
.
t
.
r
.
width
)
!=
C_OK
)
return
;
&
shape
.
t
.
r
.
height
)
!=
C_OK
)
return
;
shape
.
type
=
RECTANGLE_TYPE
;
shape
.
type
=
RECTANGLE_TYPE
;
bybox
=
1
;
bybox
=
1
;
i
+=
3
;
i
+=
3
;
...
@@ -699,10 +702,20 @@ void georadiusGeneric(client *c, int srcKeyIndex, int flags) {
...
@@ -699,10 +702,20 @@ void georadiusGeneric(client *c, int srcKeyIndex, int flags) {
long
option_length
=
0
;
long
option_length
=
0
;
/* Process [optional] requested sorting */
/* Process [optional] requested sorting */
if
(
sort
==
SORT_ASC
)
{
if
(
sort
!=
SORT_NONE
)
{
qsort
(
ga
->
array
,
result_length
,
sizeof
(
geoPoint
),
sort_gp_asc
);
int
(
*
sort_gp_callback
)(
const
void
*
a
,
const
void
*
b
)
=
NULL
;
}
else
if
(
sort
==
SORT_DESC
)
{
if
(
sort
==
SORT_ASC
)
{
qsort
(
ga
->
array
,
result_length
,
sizeof
(
geoPoint
),
sort_gp_desc
);
sort_gp_callback
=
sort_gp_asc
;
}
else
if
(
sort
==
SORT_DESC
)
{
sort_gp_callback
=
sort_gp_desc
;
}
if
(
returned_items
==
result_length
)
{
qsort
(
ga
->
array
,
result_length
,
sizeof
(
geoPoint
),
sort_gp_callback
);
}
else
{
pqsort
(
ga
->
array
,
result_length
,
sizeof
(
geoPoint
),
sort_gp_callback
,
0
,
(
returned_items
-
1
));
}
}
}
if
(
storekey
==
NULL
)
{
if
(
storekey
==
NULL
)
{
...
...
src/geohash_helper.c
View file @
2ab6fef0
...
@@ -85,20 +85,16 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) {
...
@@ -85,20 +85,16 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) {
/* Return the bounding box of the search area by shape (see geohash.h GeoShape)
/* Return the bounding box of the search area by shape (see geohash.h GeoShape)
* bounds[0] - bounds[2] is the minimum and maximum longitude
* bounds[0] - bounds[2] is the minimum and maximum longitude
* while bounds[1] - bounds[3] is the minimum and maximum latitude.
* while bounds[1] - bounds[3] is the minimum and maximum latitude.
* since the higher the latitude, the shorter the arc length, the box shape is as follows
* (left and right edges are actually bent), as shown in the following diagram:
*
*
* This function does not behave correctly with very large radius values, for
* \-----------------/ -------- \-----------------/
* instance for the coordinates 81.634948934258375 30.561509253718668 and a
* \ / / \ \ /
* radius of 7083 kilometers, it reports as bounding boxes:
* \ (long,lat) / / (long,lat) \ \ (long,lat) /
*
* \ / / \ / \
* min_lon 7.680495, min_lat -33.119473, max_lon 155.589402, max_lat 94.242491
* --------- /----------------\ /--------------\
*
* Northern Hemisphere Southern Hemisphere Around the equator
* However, for instance, a min_lon of 7.680495 is not correct, because the
*/
* point -1.27579540014266968 61.33421815228281559 is at less than 7000
* kilometers away.
*
* Since this function is currently only used as an optimization, the
* optimization is not used for very big radiuses, however the function
* should be fixed. */
int
geohashBoundingBox
(
GeoShape
*
shape
,
double
*
bounds
)
{
int
geohashBoundingBox
(
GeoShape
*
shape
,
double
*
bounds
)
{
if
(
!
bounds
)
return
0
;
if
(
!
bounds
)
return
0
;
double
longitude
=
shape
->
xy
[
0
];
double
longitude
=
shape
->
xy
[
0
];
...
@@ -106,10 +102,14 @@ int geohashBoundingBox(GeoShape *shape, double *bounds) {
...
@@ -106,10 +102,14 @@ int geohashBoundingBox(GeoShape *shape, double *bounds) {
double
height
=
shape
->
conversion
*
(
shape
->
type
==
CIRCULAR_TYPE
?
shape
->
t
.
radius
:
shape
->
t
.
r
.
height
/
2
);
double
height
=
shape
->
conversion
*
(
shape
->
type
==
CIRCULAR_TYPE
?
shape
->
t
.
radius
:
shape
->
t
.
r
.
height
/
2
);
double
width
=
shape
->
conversion
*
(
shape
->
type
==
CIRCULAR_TYPE
?
shape
->
t
.
radius
:
shape
->
t
.
r
.
width
/
2
);
double
width
=
shape
->
conversion
*
(
shape
->
type
==
CIRCULAR_TYPE
?
shape
->
t
.
radius
:
shape
->
t
.
r
.
width
/
2
);
const
double
long_delta
=
rad_deg
(
width
/
EARTH_RADIUS_IN_METERS
/
cos
(
deg_rad
(
latitude
)));
const
double
lat_delta
=
rad_deg
(
height
/
EARTH_RADIUS_IN_METERS
);
const
double
lat_delta
=
rad_deg
(
height
/
EARTH_RADIUS_IN_METERS
);
bounds
[
0
]
=
longitude
-
long_delta
;
const
double
long_delta_top
=
rad_deg
(
width
/
EARTH_RADIUS_IN_METERS
/
cos
(
deg_rad
(
latitude
+
lat_delta
)));
bounds
[
2
]
=
longitude
+
long_delta
;
const
double
long_delta_bottom
=
rad_deg
(
width
/
EARTH_RADIUS_IN_METERS
/
cos
(
deg_rad
(
latitude
-
lat_delta
)));
/* The directions of the northern and southern hemispheres
* are opposite, so we choice different points as min/max long/lat */
int
southern_hemisphere
=
latitude
<
0
?
1
:
0
;
bounds
[
0
]
=
southern_hemisphere
?
longitude
-
long_delta_bottom
:
longitude
-
long_delta_top
;
bounds
[
2
]
=
southern_hemisphere
?
longitude
+
long_delta_bottom
:
longitude
+
long_delta_top
;
bounds
[
1
]
=
latitude
-
lat_delta
;
bounds
[
1
]
=
latitude
-
lat_delta
;
bounds
[
3
]
=
latitude
+
lat_delta
;
bounds
[
3
]
=
latitude
+
lat_delta
;
return
1
;
return
1
;
...
@@ -137,12 +137,10 @@ GeoHashRadius geohashCalculateAreasByShapeWGS84(GeoShape *shape) {
...
@@ -137,12 +137,10 @@ GeoHashRadius geohashCalculateAreasByShapeWGS84(GeoShape *shape) {
double
latitude
=
shape
->
xy
[
1
];
double
latitude
=
shape
->
xy
[
1
];
/* radius_meters is calculated differently in different search types:
/* radius_meters is calculated differently in different search types:
* 1) CIRCULAR_TYPE, just use radius.
* 1) CIRCULAR_TYPE, just use radius.
* 2) RECTANGLE_TYPE, in order to calculate accurately, we should use
* 2) RECTANGLE_TYPE, we use sqrt((width/2)^2 + (height/2)^2) to
* sqrt((width/2)^2 + (height/2)^2), so that the box is bound by a circle,
* calculate the distance from the center point to the corner */
* But the current code a simpler approach resulting in a smaller circle,
* which is safe because we search the 8 nearby boxes anyway. */
double
radius_meters
=
shape
->
type
==
CIRCULAR_TYPE
?
shape
->
t
.
radius
:
double
radius_meters
=
shape
->
type
==
CIRCULAR_TYPE
?
shape
->
t
.
radius
:
shape
->
t
.
r
.
width
>
shape
->
t
.
r
.
height
?
shape
->
t
.
r
.
width
/
2
:
shape
->
t
.
r
.
height
/
2
;
sqrt
((
shape
->
t
.
r
.
width
/
2
)
*
(
shape
->
t
.
r
.
width
/
2
)
+
(
shape
->
t
.
r
.
height
/
2
)
*
(
shape
->
t
.
r
.
height
/
2
))
;
radius_meters
*=
shape
->
conversion
;
radius_meters
*=
shape
->
conversion
;
steps
=
geohashEstimateStepsByRadius
(
radius_meters
,
latitude
);
steps
=
geohashEstimateStepsByRadius
(
radius_meters
,
latitude
);
...
@@ -245,14 +243,21 @@ int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2,
...
@@ -245,14 +243,21 @@ int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2,
return
geohashGetDistanceIfInRadius
(
x1
,
y1
,
x2
,
y2
,
radius
,
distance
);
return
geohashGetDistanceIfInRadius
(
x1
,
y1
,
x2
,
y2
,
radius
,
distance
);
}
}
/* Judge whether a point is in the axis-aligned rectangle.
/* Judge whether a point is in the axis-aligned rectangle, when the distance
* bounds : see geohash.h GeoShape::bounds
* between a searched point and the center point is less than or equal to
* height/2 or width/2 in height and width, the point is in the rectangle.
*
* width_m, height_m: the rectangle
* x1, y1 : the center of the box
* x1, y1 : the center of the box
* x2, y2 : the point to be searched
* x2, y2 : the point to be searched
*/
*/
int
geohashGetDistanceIfInRectangle
(
double
*
bounds
,
double
x1
,
double
y1
,
int
geohashGetDistanceIfInRectangle
(
double
width_m
,
double
height_m
,
double
x1
,
double
y1
,
double
x2
,
double
y2
,
double
*
distance
)
{
double
x2
,
double
y2
,
double
*
distance
)
{
if
(
x2
<
bounds
[
0
]
||
x2
>
bounds
[
2
]
||
y2
<
bounds
[
1
]
||
y2
>
bounds
[
3
])
return
0
;
double
lon_distance
=
geohashGetDistance
(
x2
,
y2
,
x1
,
y2
);
double
lat_distance
=
geohashGetDistance
(
x2
,
y2
,
x2
,
y1
);
if
(
lon_distance
>
width_m
/
2
||
lat_distance
>
height_m
/
2
)
{
return
0
;
}
*
distance
=
geohashGetDistance
(
x1
,
y1
,
x2
,
y2
);
*
distance
=
geohashGetDistance
(
x1
,
y1
,
x2
,
y2
);
return
1
;
return
1
;
}
}
src/geohash_helper.h
View file @
2ab6fef0
...
@@ -60,7 +60,7 @@ int geohashGetDistanceIfInRadius(double x1, double y1,
...
@@ -60,7 +60,7 @@ int geohashGetDistanceIfInRadius(double x1, double y1,
int
geohashGetDistanceIfInRadiusWGS84
(
double
x1
,
double
y1
,
double
x2
,
int
geohashGetDistanceIfInRadiusWGS84
(
double
x1
,
double
y1
,
double
x2
,
double
y2
,
double
radius
,
double
y2
,
double
radius
,
double
*
distance
);
double
*
distance
);
int
geohashGetDistanceIfInRectangle
(
double
*
bounds
,
double
x1
,
double
y1
,
int
geohashGetDistanceIfInRectangle
(
double
width_m
,
double
height_m
,
double
x1
,
double
y1
,
double
x2
,
double
y2
,
double
*
distance
);
double
x2
,
double
y2
,
double
*
distance
);
#endif
/* GEOHASH_HELPER_HPP_ */
#endif
/* GEOHASH_HELPER_HPP_ */
Prev
1
2
3
4
5
Next
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