Commit Graph

467 Commits

Author SHA1 Message Date
Salvatore Sanfilippo
b0a90d8fa8
Merge pull request #4980 from yossigo/rm-assert
Add RedisModule_Assert() API call.
2019-09-26 11:39:29 +02:00
filipecosta90
af15b285fa [fix] fixed the un-refactor bug. 2019-09-25 17:28:42 +01:00
filipecosta90
733280d9cb [fix] un-refactor the code. [perf] replyWithStatus now makes usage of addReplyProto 2019-09-23 23:45:31 +01:00
filipecosta90
4a30a26f8f [add] improved performance of RM_ReplyWithSimpleString and RM_ReplyWithError by making usage addReplyProto instead of addReplySds 2019-09-15 21:16:30 +01:00
Doug Nelson
cc8f06ece9 Typo fixes in API documentation 2019-09-05 16:25:06 +01:00
Oran Agra
78bbb9b58d Modlue fork is killed when the parent exists 2019-08-25 10:11:48 +03:00
Oran Agra
61853ad8de Module INFO, support default section for simple modules 2019-08-18 10:01:57 +03:00
Oran Agra
1d6e5dc4dc Module INFO, add support for dict fields, rename API to have common prefix 2019-08-18 09:41:45 +03:00
Oran Agra
0a97149dec RM_ReplyWithCString was missing registration 2019-08-07 13:06:11 +03:00
Oran Agra
e5187ad2ae Merge remote-tracking branch 'oss/unstable' into module_rdb_load_errors 2019-07-30 15:14:08 +03:00
Oran Agra
4339706e07 Avoid diskelss-load if modules did not declare they handle read errors 2019-07-30 15:11:57 +03:00
Salvatore Sanfilippo
f42846e8c7
Merge pull request #6264 from oranagra/modules_api_aux_rdb
Implement module api for aux data in rdb
2019-07-30 11:50:44 +02:00
Oran Agra
e91d9a6fff Extend modules API to allow modules report to redis INFO
this implements #6012
2019-07-24 12:58:15 +03:00
Oran Agra
3b6aeea44c Implement module api for aux data in rdb
Other changes:
* fix memory leak in error handling of rdb loading of type OBJ_MODULE
2019-07-22 21:15:33 +03:00
Oran Agra
d7d028a7a7 Allow modules to handle RDB loading errors.
This is especially needed in diskless loading, were a short read could have
caused redis to exit. now the module can handle the error and return to the
caller gracefully.

this fixes #5326
2019-07-21 18:19:32 +03:00
John Sully
ff682d7902 Modules must have execute permissions to load 2019-07-19 15:28:31 -04:00
John Sully
70534846d1 Modules must have execute permissions to load 2019-07-19 01:37:34 -04:00
Oran Agra
56258c6b7d Module API for Forking
* create module API for forking child processes.
* refactor duplicate code around creating and tracking forks by AOF and RDB.
* child processes listen to SIGUSR1 and dies exitFromChild in order to
  eliminate a valgrind warning of unhandled signal.
* note that BGSAVE error reply has changed.

valgrind error is:
  Process terminating with default action of signal 10 (SIGUSR1)
2019-07-17 16:40:24 +03:00
Oran Agra
6e07fac405 RM_Log - add support for logging without a context or context without module
for instance detached thread safe contexts, or various callbacks that don't
provide a context.
2019-07-17 15:08:18 +03:00
Salvatore Sanfilippo
677e95e2f5
Merge pull request #6161 from swilly22/redismodule-loading-ctx-flag
Extend REDISMODULE_CTX_FLAGS to indicate if redis is  loading
2019-07-07 17:01:29 +02:00
Salvatore Sanfilippo
a714004738
Merge pull request #6022 from itamarhaber/RedisModule_ReplyWithCString
Adds RedisModule_ReplyWithCString
2019-07-05 20:25:18 +02:00
swilly22
f54d95e803 Extend REDISMODULE_CTX_FLAGS to indicate if redis is currently loading from either RDB or AOF 2019-06-12 15:37:19 +03:00
Yossi Gottlieb
9f3679880a Preserve client->id for blocked clients. 2019-05-05 20:32:53 +03:00
Itamar Haber
52686f4866 Adds a "Modules" section to INFO
Fixes #6012.

As long as "INFO is broken", this should be adequate IMO. Once we rework
`INFO`, perhaps into RESP3, this implementation should be revisited.
2019-04-16 22:16:12 +03:00
Itamar Haber
c184b32d4c Uses addReplyBulkCString
Signed-off-by: Itamar Haber <itamar@redislabs.com>
2019-04-16 17:38:33 +03:00
Itamar Haber
26d9d4ec2c Adds RedisModule_ReplyWithCString
Signed-off-by: Itamar Haber <itamar@redislabs.com>
2019-04-16 17:15:23 +03:00
Salvatore Sanfilippo
d044e33c20
Merge pull request #5961 from yossigo/modules-tests
Modules tests
2019-04-11 07:56:23 -07:00
antirez
9e67691ffb Aesthetic change to #5962 to conform to Redis style. 2019-04-10 18:53:35 +02:00
Oran Agra
acba2fc9b4 slave corrupts replication stream when module blocked client uses large reply (or POSTPONED_ARRAY)
when redis appends the blocked client reply list to the real client, it didn't
bother to check if it is in fact the master client. so a slave executing that
module command will send replies to the master, causing the master to send the
slave error responses, which will mess up the replication offset
(slave will advance it's replication offset, and the master does not)
2019-03-24 14:17:37 +02:00
Yossi Gottlieb
822a992f91 fix: missing initialization. 2019-03-24 12:00:33 +02:00
Salvatore Sanfilippo
5e8caca036
Merge pull request #5944 from yossigo/command-filtering
Command Filtering API
2019-03-22 17:43:49 +01:00
Yossi Gottlieb
6c0a5fde3d CommandFilter API: REDISMODULE_CMDFILTER_NOSELF.
Add a flag to automatically protect filters from being called
recursively by their own module.
2019-03-21 19:53:12 +02:00
Yossi Gottlieb
4ea3ed896b CommandFilter API: fix UnregisterCommandFilter. 2019-03-21 19:45:41 +02:00
Yossi Gottlieb
e2626f69ec CommandFilter API: Add unregister option.
A filter handle is returned and can be used to unregister a filter.  In
the future it can also be used to further configure or manipulate the
filter.

Filters are now automatically unregistered when a module unloads.
2019-03-21 14:44:49 +02:00
Yossi Gottlieb
dd8b4be46b CommandFilter API: Extend documentation. 2019-03-19 19:48:47 +02:00
Yossi Gottlieb
325fc1cb2e CommandFilter API: Support Lua and RM_call() flows. 2019-03-18 23:06:38 +02:00
Yossi Gottlieb
2a5aeef79f CommandFilter API: More cleanup. 2019-03-18 23:05:52 +02:00
Yossi Gottlieb
6711132083 Add command filtering argument handling API. 2019-03-18 18:36:46 +02:00
Yossi Gottlieb
c3e187190b Initial command filter experiment. 2019-03-18 13:50:34 +02:00
Yossi Gottlieb
a88264d934 Add RedisModule_GetKeyNameFromIO(). 2019-03-15 10:23:27 +02:00
Yossi Gottlieb
68fd59056b Add RedisModule_Assert() API call. 2019-03-14 15:00:31 +02:00
antirez
d292a51618 Improve comments after merging #5834. 2019-03-14 12:47:36 +01:00
Salvatore Sanfilippo
0cce98f2f9
Merge pull request #5834 from guybe7/trim_module_sds
Trim SDS free space of retained module strings
2019-03-14 12:41:31 +01:00
Salvatore Sanfilippo
01ace0b240
Merge pull request #5694 from guybe7/rm_log_args
Check server.verbosity in RM_LogRaw
2019-03-14 11:32:03 +01:00
antirez
6fd4af1f12 Merge branch 'sharedapi' into unstable 2019-03-14 11:24:48 +01:00
Jim Brunner
283d6cfd58 Addition of OnUnload function 2019-03-13 16:31:24 +00:00
swilly22
89bf4db4fa document additional flag of RM_GetContextFlags 2019-03-13 08:22:40 +02:00
swilly22
468860ae18 Extend REDISMODULE_CTX_FLAGS to indicate if command was sent by master 2019-03-11 10:02:19 +02:00
Guy Benoish
bdd9a8002a Trim SDS free space of retained module strings
In some cases processMultibulkBuffer uses sdsMakeRoomFor to
expand the querybuf, but later in some cases it uses that query
buffer as is for an argv element (see "Optimization"), which means
that the sds in argv may have a lot of wasted space, and then in case
modules keep that argv RedisString inside their data structure, this
space waste will remain for long (until restarted from rdb).
2019-02-12 14:21:21 +01:00
antirez
1769c22248 ACL: set modules help clients to the root user.
It does not make much sense to limit what modules can do: the admin
should instead limit what module commnads an user may call. So
RedisModule_Call() and other module operations should be able to execute
everything they want: the limitation should be posed by the API exported
by the module itself.
2019-02-01 11:37:28 +01:00
antirez
b6372f16c4 ACL: assign ACL command ID to modules commands. 2019-02-01 08:17:24 +01:00
antirez
709a6612eb RESP3: addReplyString() -> addReplyProto().
The function naming was totally nuts. Let's fix it as we break PRs
anyway with RESP3 refactoring and changes.
2019-01-09 17:00:30 +01:00
antirez
4f0860cbfd RESP3: initial implementation of the HELLO command. 2019-01-09 17:00:29 +01:00
antirez
baf5b3f93a RESP3: module.c updated. 2019-01-09 17:00:29 +01:00
antirez
8a87de130f Modules shared API: export new core APIs. 2018-12-20 17:57:49 +01:00
antirez
d3eb0028e9 Modules shared API: also unregister the module as user. 2018-12-20 17:57:46 +01:00
antirez
9403b3d7a3 Modules shared API: prevent unloading of used modules. 2018-12-20 17:57:43 +01:00
antirez
6bb8cdaebe Modules shared API: unregister APIs function. 2018-12-20 17:57:40 +01:00
antirez
27f6e9bb9b Modules shared API: initial core functions.
Based on ideas and code in PR #5560 by @MeirShpilraien.
2018-12-20 17:57:35 +01:00
antirez
850b64c116 Revert shared APIs to modify the design. 2018-12-20 17:56:38 +01:00
MeirShpilraien
ab37289fa6 added module ability to register api to be used by other modules 2018-12-20 17:55:18 +01:00
Guy Benoish
ed88f77d6d Check server.verbosity in RM_LogRaw 2018-12-13 13:57:38 +01:00
Hamid Alaei
87264235cc fix timer context selected database 2018-10-04 17:02:10 +03:30
Hamid Alaei
86fb7b20bf fix dict get on not found 2018-10-01 13:57:25 +03:30
antirez
0aecb135c9 Modules: Modules: dictionary API WIP #13: Compare API exported. 2018-09-27 11:46:22 +02:00
antirez
80bde9844b Modules: Modules: dictionary API WIP #12: DictCompare API. 2018-09-27 11:44:25 +02:00
antirez
7af83a0c11 Modules: Modules: dictionary API WIP #11: DictCompareC API. 2018-09-27 11:44:16 +02:00
antirez
1e585d01de Modules: dictionary API WIP #10: export API to modules. 2018-09-26 13:39:01 +02:00
antirez
3ff82790e1 Modules: dictionary API WIP #9: iterator returning string object. 2018-09-25 16:49:46 +02:00
antirez
fb1d5717de Modules: dictionary API WIP #8: Iterator next/prev. 2018-09-25 16:25:46 +02:00
antirez
58ac1f8bbe Modules: dictionary API WIP #7: don't store the context.
Storing the context is useless, because we can't really reuse that
later. For instance in the API RM_DictNext() that returns a
RedisModuleString for the next key iterated, the user should pass the
new context, because we may run the keys of the dictionary in a
different context of the one where the dictionary was created. Also the
dictionary may be created without a context, but we may still demand
automatic memory management for the returned strings while iterating.
2018-09-25 12:58:16 +02:00
antirez
b6c794acf6 Modules: dictionary API WIP #6: implement automatic memory management. 2018-09-25 12:45:08 +02:00
antirez
448d696549 Modules: dictionary API work in progress #5: rename API for consistency.
By using the "C" suffix for functions getting pointer/len, we can do the
same in the future for other modules APIs that need a variant with
pointer/len and that are now accepting a RedisModuleString.
2018-09-25 12:31:46 +02:00
antirez
c7e0c410d6 Modules: change RedisModuleString API to allow NULL context.
The burden of having to always create RedisModuleString objects within a
module context was too much, especially now that we have threaded
operations and modules are doing more interesting things. The context in
the string API is currently only used for automatic memory managemnet,
so now the API was modified so that the user can opt-out this feature by
passing a NULL context.
2018-09-24 17:20:00 +02:00
antirez
3968550135 Modules: dictionary API work in progress #4: reseek API. 2018-09-24 16:43:47 +02:00
antirez
14b2f7b033 Modules: dictionary API work in progress #3: Iterator creation. 2018-09-24 11:44:49 +02:00
antirez
bb64c7d8b2 Modules: dictionary API work in progress #2: Del API. 2018-09-24 11:16:58 +02:00
antirez
c5e0bc1070 Modules: dictionary API work in progress #1. 2018-09-21 17:54:09 +02:00
antirez
0d6f11f4d1 Module cluster flags: use RM_SetClusterFlags() in the example. 2018-09-19 16:17:20 +02:00
antirez
3213e8de92 Module cluster flags: add RM_SetClusterFlags() API. 2018-09-19 12:02:37 +02:00
antirez
7cdf272d46 Modules: rename the reused static client to something more general. 2018-09-18 13:22:05 +02:00
antirez
9df1f73e4c Modules: associate a fake client to timer context callback. 2018-09-18 13:19:33 +02:00
antirez
bf18044082 Modules: associate a fake client to cluster message context callback.
Fixes #5354.
2018-09-18 13:15:40 +02:00
Guy Korland
3176f8e955
Merge pull request #1 from gkorland/patch-5
Fix few typos
2018-09-17 14:15:39 +03:00
Guy Korland
3b0f008615
Fix few typos 2018-09-17 14:13:46 +03:00
Guy Korland
44f9e0d7c7
RedisModule_HashSet call must end with NULL
Extended the RedisModule_HashSet doc to mark that each call must end with NULL
2018-09-17 13:54:56 +03:00
Guy Korland
acaa18f1d1
Few typo fixes 2018-07-30 16:18:56 +03:00
Oran Agra
bf680b6f8c slave buffers were wasteful and incorrectly counted causing eviction
A) slave buffers didn't count internal fragmentation and sds unused space,
   this caused them to induce eviction although we didn't mean for it.

B) slave buffers were consuming about twice the memory of what they actually needed.
- this was mainly due to sdsMakeRoomFor growing to twice as much as needed each time
  but networking.c not storing more than 16k (partially fixed recently in 237a38737).
- besides it wasn't able to store half of the new string into one buffer and the
  other half into the next (so the above mentioned fix helped mainly for small items).
- lastly, the sds buffers had up to 30% internal fragmentation that was wasted,
  consumed but not used.

C) inefficient performance due to starting from a small string and reallocing many times.

what i changed:
- creating dedicated buffers for reply list, counting their size with zmalloc_size
- when creating a new reply node from, preallocate it to at least 16k.
- when appending a new reply to the buffer, first fill all the unused space of the
  previous node before starting a new one.

other changes:
- expose mem_not_counted_for_evict info field for the benefit of the test suite
- add a test to make sure slave buffers are counted correctly and that they don't cause eviction
2018-07-16 16:43:42 +03:00
Jack Drogon
93238575f7 Fix typo 2018-07-03 18:19:46 +02:00
antirez
2edcafb35d addReplySubSyntaxError() renamed to addReplySubcommandSyntaxError(). 2018-07-02 18:49:34 +02:00
Salvatore Sanfilippo
bc6a004588
Merge pull request #4998 from itamarhaber/module_command_help
Module command help
2018-07-02 18:46:56 +02:00
shenlongxing
ec55df117f fix typo 2018-06-21 22:08:09 +08:00
antirez
4848fbec8b Modules: convert hash to hash table for big objects. 2018-06-19 16:03:00 +02:00
Itamar Haber
21ef0376fe
Capitalizes subscommands 2018-06-09 20:54:05 +03:00
Itamar Haber
76ad23d012 Adds MODULE HELP and implements addReplySubSyntaxError 2018-06-07 18:34:58 +03:00
zhaozhao.zz
775adf544c Modules Timer API: fix wrong raxInsert() usage 2018-04-14 01:20:02 +08:00
antirez
e07af6a2b7 Modules API: Add call to get the blocked client handle from the context.
This is useful in the reply and timeout callback, if the module wants to
do some cleanup of the blocked client handle that may be stored around
in the module-private data structures.
2018-04-13 13:48:11 +02:00
antirez
da0e192277 Modules API: moduleGetReplyClient() refactoring. 2018-04-13 13:42:49 +02:00
antirez
404160a271 Modules API: blocked client disconnection callback. 2018-04-12 13:21:48 +02:00
antirez
4e53624052 Modules API: fix OOM_WARNING flag implementation. 2018-04-11 16:25:54 +02:00
antirez
0afac6939a Modules API: OOM_WARNING flags.
In some modules it may be useful to have an idea about being near to
OOM. Anyway additionally an explicit call to get the fill ratio will be
added in the future.
2018-04-11 16:22:52 +02:00
antirez
de7de53e64 getMaxmemoryState() fixed and improved. 2018-04-11 12:48:26 +02:00
antirez
f97efe0cac Modules: context flags now include OOM flag.
Plus freeMemoryIfNeeded() refactoring to improve legibility.
Please review this commit for sanity.
2018-04-09 17:44:30 +02:00
antirez
9a0dbbb594 Modules: remove trailing empty spaces. 2018-04-09 17:16:55 +02:00
antirez
49e098234a Modules API: blocked client free callback modified to get a context.
Note that this was an experimental API that can only be enabled with
REIDSMODULE_EXPERIMENTAL_API, so it is subject to change until its
promoted to stable API. Sorry for the breakage, it is trivial to
resolve btw. This change will not be back ported to Redis 4.0.
2018-04-09 11:54:44 +02:00
antirez
b2868c7b9c Modules API: RM_GetRandomBytes() / GetRandomHexChars(). 2018-04-05 13:24:22 +02:00
antirez
c75582889a Modules Cluster API: GetClusterSize() added. 2018-04-01 16:36:32 +02:00
antirez
27f9c8108c Modules Cluster API: GetMyClusterID() added. 2018-04-01 16:20:57 +02:00
antirez
ee982f4031 Modules Timer API: Wait at least 1 ms per iteration. Convert to ms. 2018-03-31 10:11:30 +02:00
antirez
4c11bc6cf0 Modules Timer API: fix wrong raxRemove() key argument. 2018-03-31 09:58:43 +02:00
antirez
2f7da0fd1a Modules Timer API: fix infinite loop and export API. 2018-03-31 00:44:46 +02:00
antirez
b85a465c25 Modules Timer API: timer handling implemented. 2018-03-30 22:50:21 +02:00
antirez
561039c125 Modules Timer API: initial implementation. 2018-03-30 20:40:35 +02:00
antirez
192361b562 Modules Cluster API: node API exported, example improved. 2018-03-30 17:00:45 +02:00
antirez
16178b692e Modules Cluster API: nodes list and info API. 2018-03-30 16:16:47 +02:00
antirez
83ec35770e Modules Cluster API: node information struct and flags. 2018-03-30 13:16:55 +02:00
antirez
a97df1a6e1 Modules Cluster API: make node IDs pointers constant. 2018-03-30 13:16:07 +02:00
antirez
82004f9dbe Modules Cluster API: fix new API calls exporting. 2018-03-30 12:49:16 +02:00
antirez
b4dc782e4e Modules Cluster API: sending / receiving API first implementation. 2018-03-30 11:06:08 +02:00
antirez
0701cad3de Modules Cluster API: message bus implementation. 2018-03-29 15:13:31 +02:00
charsyam
51a03f6356 fix dlopen leak 2018-03-01 21:22:42 +09:00
antirez
aa57481d8c Remove non semantical spaces from module.c. 2018-02-15 21:41:03 +01:00
Dvir Volk
0a36196ce4 Add doc comment about notification flags 2018-02-14 21:54:00 +02:00
Dvir Volk
f27a64232e Use one static client for all keyspace notification callbacks 2018-02-14 21:40:10 +02:00
Dvir Volk
3aab12414f Remove the NOTIFY_MODULE flag and simplify the module notification flow if there aren't subscribers 2018-02-14 21:40:10 +02:00
Dvir Volk
a8e2e99a88 Document flags for notifications 2018-02-14 21:38:58 +02:00
Dvir Volk
2136035e47 finished implementation of notifications. Tests unfinished 2018-02-14 21:38:58 +02:00
Salvatore Sanfilippo
72187fa8a5
Merge pull request #4581 from dvirsky/module_unlink
Added RM_UnlinkKey - a low level analog to UNLINK command
2018-01-12 17:41:09 +01:00
Dvir Volk
e76dfc90a7 Added RM_UnlinkKey - a low level analog to UNLINK command 2018-01-07 16:41:43 +02:00
Oran Agra
60a4f12f8b fix processing of large bulks (above 2GB)
- protocol parsing (processMultibulkBuffer) was limitted to 32big positions in the buffer
  readQueryFromClient potential overflow
- rioWriteBulkCount used int, although rioWriteBulkString gave it size_t
- several places in sds.c that used int for string length or index.
- bugfix in RM_SaveAuxField (return was 1 or -1 and not length)
- RM_SaveStringBuffer was limitted to 32bit length
2017-12-29 12:24:19 +02:00
antirez
7229fa8d6d Modules: fix memory leak in RM_IsModuleNameBusy(). 2017-11-24 13:29:54 +01:00
Salvatore Sanfilippo
f739c27229
Merge pull request #4344 from soloestoy/fix-module-name-conflict
Fix module name conflict
2017-11-24 09:37:06 +01:00
antirez
de914ede93 Modules: fix for scripting replication of modules commands.
See issue #4466 / #4467.
2017-11-23 15:14:17 +01:00
Yossi Gottlieb
2c70d28295 Nested MULTI/EXEC may replicate in different cases.
For example:
1. A module command called within a MULTI section.
2. A Lua script with replicate_commands() called within a MULTI section.
3. A module command called from a Lua script in the above context.
2017-11-22 22:02:51 +02:00
antirez
2bf8c2c130 Limit statement in RM_BlockClient() to 80 cols. 2017-09-28 23:15:34 +02:00
zhaozhao.zz
6dffc1b7a3 Modules: handle the busy module name 2017-09-28 17:38:40 +08:00
zhaozhao.zz
cb9dde3280 Modules: handle the conflict of registering commands 2017-09-28 16:21:21 +08:00
Dvir Volk
7393fd814e Added safety net preventing redis from crashing if a module decide to block in MULTI 2017-09-27 15:17:53 +03:00
Dvir Volk
b246635d6d Renamed GetCtxFlags to GetContextFlags 2017-09-27 11:58:16 +03:00
Dvir Volk
616c546b01 Added support for module context flags with RM_GetCtxFlags 2017-09-27 11:58:07 +03:00
antirez
314043552b Modules: don't crash when Lua calls a module blocking command.
Lua scripting does not support calling blocking commands, however all
the native Redis commands are flagged as "s" (no scripting flag), so
this is not possible at all. With modules there is no such mechanism in
order to flag a command as non callable by the Lua scripting engine,
moreover we cannot trust the modules users from complying all the times:
it is likely that modules will be released to have blocking commands
without such commands being flagged correctly, even if we provide a way to
signal this fact.

This commit attempts to address the problem in a short term way, by
detecting that a module is trying to block in the context of the Lua
scripting engine client, and preventing to do this. The module will
actually believe to block as usually, but what happens is that the Lua
script receives an error immediately, and the background call is ignored
by the Redis engine (if not for the cleanup callbacks, once it
unblocks).

Long term, the more likely solution, is to introduce a new call called
RedisModule_GetClientFlags(), so that a command can detect if the caller
is a Lua script, and return an error, or avoid blocking at all.

Being the blocking API experimental right now, more work is needed in
this regard in order to reach a level well blocking module commands and
all the other Redis subsystems interact peacefully.

Now the effect is like the following:

    127.0.0.1:6379> eval "redis.call('hello.block',1,5000)" 0
    (error) ERR Error running script (call to
    f_b5ba35ff97bc1ef23debc4d6e9fd802da187ed53): @user_script:1: ERR
    Blocking module command called from Lua script

This commit fixes issue #4127 in the short term.
2017-07-23 12:55:37 +02:00
antirez
5bfdfbe174 Fix typo in unblockClientFromModule() top comment. 2017-07-23 12:41:26 +02:00
antirez
b1c2e1a19c Fix two bugs in moduleTypeLookupModuleByID().
The function cache was not working at all, and the function returned
wrong values if there where two or more modules exporting native data
types.

See issue #4131 for more details.
2017-07-20 14:59:42 +02:00
antirez
bd1782fa0a Modules: fix thread safe context DB selection.
Before this fix the DB currenty selected by the client blocked was not
respected and operations were always performed on DB 0.
2017-07-14 13:02:15 +02:00
antirez
43aaf96163 Markdown generation of Redis Modules API reference improved. 2017-07-14 11:29:31 +02:00
antirez
e203a46cf3 Clients blocked in modules: free argv/argc later.
See issue #3844 for more information.
2017-07-11 12:33:01 +02:00
Guy Benoish
dfb68cd235 Modules: Fix io->bytes calculation in RDB save 2017-07-10 14:41:57 +03:00
Salvatore Sanfilippo
6b0670daad Merge pull request #3853 from itamarhaber/issue-3851
Sets up fake client to select current db in RM_Call()
2017-07-06 15:02:11 +02:00
antirez
51ffd062d3 Modules: DEBUG DIGEST interface. 2017-07-06 11:04:46 +02:00
antirez
413c2bc180 Modules: no MULTI/EXEC for commands replicated from async contexts.
They are technically like commands executed from external clients one
after the other, and do not constitute a single atomic entity.
2017-07-05 10:10:20 +02:00
Dvir Volk
86e564e9ff fixed #4100 2017-07-04 00:02:19 +03:00
antirez
365dd037dc RDB modules values serialization format version 2.
The original RDB serialization format was not parsable without the
module loaded, becuase the structure was managed only by the module
itself. Moreover RDB is a streaming protocol in the sense that it is
both produce di an append-only fashion, and is also sometimes directly
sent to the socket (in the case of diskless replication).

The fact that modules values cannot be parsed without the relevant
module loaded is a problem in many ways: RDB checking tools must have
loaded modules even for doing things not involving the value at all,
like splitting an RDB into N RDBs by key or alike, or just checking the
RDB for sanity.

In theory module values could be just a blob of data with a prefixed
length in order for us to be able to skip it. However prefixing the values
with a length would mean one of the following:

1. To be able to write some data at a previous offset. This breaks
stremaing.
2. To bufferize values before outputting them. This breaks performances.
3. To have some chunked RDB output format. This breaks simplicity.

Moreover, the above solution, still makes module values a totally opaque
matter, with the fowllowing problems:

1. The RDB check tool can just skip the value without being able to at
least check the general structure. For datasets composed mostly of
modules values this means to just check the outer level of the RDB not
actually doing any checko on most of the data itself.
2. It is not possible to do any recovering or processing of data for which a
module no longer exists in the future, or is unknown.

So this commit implements a different solution. The modules RDB
serialization API is composed if well defined calls to store integers,
floats, doubles or strings. After this commit, the parts generated by
the module API have a one-byte prefix for each of the above emitted
parts, and there is a final EOF byte as well. So even if we don't know
exactly how to interpret a module value, we can always parse it at an
high level, check the overall structure, understand the types used to
store the information, and easily skip the whole value.

The change is backward compatible: older RDB files can be still loaded
since the new encoding has a new RDB type: MODULE_2 (of value 7).
The commit also implements the ability to check RDB files for sanity
taking advantage of the new feature.
2017-06-27 13:19:16 +02:00
antirez
9b01b64430 Modules TSC: put the client in the pending write list. 2017-05-03 14:54:48 +02:00
antirez
7127f15ebe Module: fix RedisModule_Call() "l" specifier to create a raw string. 2017-05-03 14:07:10 +02:00
antirez
3fcf959e60 Modules TSC: Release the GIL for all the time we are blocked.
Instead of giving the module background operations just a small time to
run in the beforeSleep() function, we can have the lock released for all
the time we are blocked in the multiplexing syscall.
2017-05-03 11:26:21 +02:00
antirez
ba4a5a3255 Modules TSC: Export symbols of the new API. 2017-05-02 15:19:28 +02:00
antirez
275905b328 Modules TSC: Handling of RM_Reply* functions. 2017-05-02 15:05:39 +02:00
antirez
9c500b89fb Modules TSC: Basic TS context creeation and handling. 2017-05-02 12:53:10 +02:00
antirez
59b06b14c9 Modules TSC: GIL and cooperative multi tasking setup. 2017-04-28 18:41:10 +02:00
antirez
531647bb1b Make more obvious why there was issue #3843. 2017-04-10 13:17:05 +02:00
Salvatore Sanfilippo
01b6966afc Merge pull request #3843 from dvirsky/fix_bc_free
fixed free of blocked client before refering to it
2017-04-10 13:14:52 +02:00
antirez
ffefc9f92d Fix modules blocking commands awake delay.
If a thread unblocks a client blocked in a module command, by using the
RedisMdoule_UnblockClient() API, the event loop may not be awaken until
the next timeout of the multiplexing API or the next unrelated I/O
operation on other clients. We actually want the client to be served
ASAP, so a mechanism is needed in order for the unblocking API to inform
Redis that there is a client to serve ASAP.

This commit fixes the issue using the old trick of the pipe: when a
client needs to be unblocked, a byte is written in a pipe. When we run
the list of clients blocked in modules, we consume all the bytes
written in the pipe. Writes and reads are performed inside the context
of the mutex, so no race is possible in which we consume the bytes that
are actually related to an awake request for a client that should still
be put into the list of clients to unblock.

It was verified that after the fix the server handles the blocked
clients with the expected short delay.

Thanks to @dvirsky for understanding there was such a problem and
reporting it.
2017-04-10 09:33:21 +02:00
itamar
443f279a3a Sets up fake client to select current db in RM_Call() 2017-03-06 14:37:10 +02:00
Dvir Volk
4b2229e4b8 fixed free of blocked client before refering to it 2017-03-01 16:51:01 +02:00
antirez
adeed29a99 Use SipHash hash function to mitigate HashDos attempts.
This change attempts to switch to an hash function which mitigates
the effects of the HashDoS attack (denial of service attack trying
to force data structures to worst case behavior) while at the same time
providing Redis with an hash function that does not expect the input
data to be word aligned, a condition no longer true now that sds.c
strings have a varialbe length header.

Note that it is possible sometimes that even using an hash function
for which collisions cannot be generated without knowing the seed,
special implementation details or the exposure of the seed in an
indirect way (for example the ability to add elements to a Set and
check the return in which Redis returns them with SMEMBERS) may
make the attacker's life simpler in the process of trying to guess
the correct seed, however the next step would be to switch to a
log(N) data structure when too many items in a single bucket are
detected: this seems like an overkill in the case of Redis.

SPEED REGRESION TESTS:

In order to verify that switching from MurmurHash to SipHash had
no impact on speed, a set of benchmarks involving fast insertion
of 5 million of keys were performed.

The result shows Redis with SipHash in high pipelining conditions
to be about 4% slower compared to using the previous hash function.
However this could partially be related to the fact that the current
implementation does not attempt to hash whole words at a time but
reads single bytes, in order to have an output which is endian-netural
and at the same time working on systems where unaligned memory accesses
are a problem.

Further X86 specific optimizations should be tested, the function
may easily get at the same level of MurMurHash2 if a few optimizations
are performed.
2017-02-20 17:29:17 +01:00
antirez
baa9898821 MEMORY USAGE: support for modules data types.
As a side effect of supporting it, we no longer crash when MEMORY USAGE
is called against a module data type.

Close #3637.
2017-01-12 09:47:57 +01:00
Dvir Volk
7f9b9512b8 fixed stop condition in RM_ZsetRangeNext and RM_ZsetRangePrev 2016-12-15 00:07:20 +02:00
antirez
04542cff92 Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj

Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.

To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.

THE BUG

Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.

Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:

1. No DEL will be received from the master, which does not know about
such a key at all.

2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.

THE FIX

In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.

My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.

The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).

This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.

TODO

I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 10:59:54 +01:00
Salvatore Sanfilippo
3c4fe59e09 Merge pull request #3648 from dvirsky/fix_reply_crash
fix memory corruption on RM_FreeCallReply
2016-11-30 11:21:10 +01:00
antirez
71e8d15e49 Modules: change type registration API to use a struct of methods. 2016-11-30 11:14:01 +01:00
Dvir Volk
8521cde570 fix memory corruption on RM_FreeCallReply 2016-11-30 11:49:49 +02:00
antirez
1f55170b9c Modules: fix client blocking calls access to invalid struct field.
We already have reference to the client pointer, no need to access the
already freed structure.

Close #3634.
2016-11-24 11:05:19 +01:00
Dvir Volk
ec8fd6e5e4 fixed sizeof in allocating io RedisModuleCtx* 2016-10-31 18:48:16 +02:00
antirez
95c17c0cb2 Modules: AbortBlock() API implemented. 2016-10-13 16:57:40 +02:00
antirez
553aa0e259 module.c: trim comment to 80 cols. 2016-10-13 12:48:36 +02:00
antirez
34599691b3 Modules: fixes to the blocking commands API: examples now works. 2016-10-07 16:34:40 +02:00
antirez
f156038db8 Modules: RM_Milliseconds() API added. 2016-10-07 16:34:19 +02:00
antirez
ffb00fbcbe Modules: blocking commands WIP: API exported, a first example. 2016-10-07 13:48:14 +02:00
antirez
8fadfe52a2 Module: API to block clients with threading support.
Just a draft to align the main ideas, never executed code. Compiles.
2016-10-07 11:55:35 +02:00
antirez
152c1b6802 Module: Ability to get context from IO context.
It was noted by @dvirsky that it is not possible to use string functions
when writing the AOF file. This sometimes is critical since the command
rewriting may need to be built in the context of the AOF callback, and
without access to the context, and the limited types that the AOF
production functions will accept, this can be an issue.

Moreover there are other needs that we can't anticipate regarding the
ability to use Redis Modules APIs using the context in order to build
representations to emit AOF / RDB.

Because of this a new API was added that allows the user to get a
temporary context from the IO context. The context is auto released
if obtained when the RDB / AOF callback returns.

Calling multiple time the function to get the context, always returns
the same one, since it is invalid to have more than a single context.
2016-10-06 17:09:26 +02:00
antirez
72279e3ea4 Copyright notice added to module.c. 2016-10-06 08:48:21 +02:00
antirez
3dc84c5300 Modules: API to save/load single precision floating point numbers.
When double precision is not needed, to take 2x space in the
serialization is not good.
2016-10-03 00:08:35 +02:00
antirez
a1b1fd4f39 Modules: API to log from module I/O callbacks. 2016-10-02 16:51:37 +02:00
Dvir Volk
a91650fc57 added RM_CreateStringPrintf 2016-09-21 12:30:38 +03:00
oranagra
afcbcc0e58 dict.c: introduce dictUnlink().
Notes by @antirez:

This patch was picked from a larger commit by Oran and adapted to change
the API a bit. The basic idea is to avoid double lookups when there is
to use the value of the deleted entry.

BEFORE:

    entry = dictFind( ... ); /* 1st lookup. */
    /* Do somethjing with the entry. */
    dictDelete(...);         /* 2nd lookup. */

AFTER:

    entry = dictUnlink( ... ); /* 1st lookup. */
    /* Do somethjing with the entry. */
    dictFreeUnlinkedEntry(entry); /* No lookups!. */
2016-09-14 12:18:59 +02:00
wyx
f9c9b4bf4c fix memory error on module unload 2016-09-09 10:22:57 +08:00
antirez
13f18d2b17 Modules: handle NULL replies more gracefully.
After all crashing at every API misuse makes everybody's life more
complex.
2016-08-03 18:09:36 +02:00
antirez
04340e1ff1 Modules: initial draft for a testing module. 2016-08-03 10:23:03 +02:00
antirez
7829e4ed2c Modules: StringAppendBuffer() and ability to retain strings.
RedisModule_StringRetain() allows, when automatic memory management is
on, to keep string objects living after the callback returns. Can also
be used in order to use Redis reference counting of objects inside
modules.

The reason why this is useful is that sometimes when implementing new
data types we want to reference RedisModuleString objects inside the
module private data structures, so those string objects must be valid
after the callback returns even if not referenced inside the Redis key
space.
2016-08-02 15:29:04 +02:00
Salvatore Sanfilippo
3a0b776b94 Merge pull request #3335 from dvirsky/rm_calloc
added RM_Calloc implementation
2016-06-23 16:19:14 +02:00
antirez
c026b5cd3e Merge branch 'unstable' of github.com:/antirez/redis into unstable 2016-06-23 16:18:57 +02:00
antirez
0f484d8312 Actually remove static from #3331.
I forgot -a when amending in the previous commit.
2016-06-23 16:18:30 +02:00
Salvatore Sanfilippo
28ea585fce Merge pull request #3336 from yossigo/create_string_from_string
Add RedisModule_CreateStringFromString().
2016-06-23 16:16:28 +02:00
antirez
c0ca87dcc0 Minor change to conform PR #3331 to Redis code base style.
Also avoid "static" in order to have symbols during crashes.
2016-06-23 16:14:16 +02:00
Salvatore Sanfilippo
a66dd43331 Merge pull request #3331 from yossigo/fix_openkey_crash
Fix occasional RM_OpenKey() crashes.
2016-06-23 16:12:07 +02:00
Salvatore Sanfilippo
3d48c93122 Merge pull request #3330 from yossigo/fix_const
Use const in Redis Module API where possible.
2016-06-23 12:29:52 +02:00
antirez
4b12c6a360 Modules: changes to logging function.
This commit changes what provided by PR #3315 (merged) in order to
let the user specify the log level as a string.

The define could be also used, but when this happens, they must be
decoupled from the defines in the Redis core, like in the other part of
the Redis modules implementations, so that a switch statement (or a
function) remaps between the two, otherwise we are no longer free to
change the internal Redis defines.
2016-06-23 12:11:30 +02:00
Yossi Gottlieb
715794b829 Add RedisModule_Log() logging API function. 2016-06-23 12:01:44 +02:00
antirez
b507289750 Commit change in autoMemoryFreed(): first -> last.
It's more natural to call the last entry added as "last", the original
commet got me confused until I actually read the code.
2016-06-23 09:38:30 +02:00
antirez
f2dbc02f65 Modules: implement zig-zag scanning in autoMemoryFreed().
Most of the time to check the last element is the way to go, however
there are patterns where the contrary is the best choice. Zig-zag
scanning implemented in this commmit always checks the obvious element
first (the last added -- think at a loop where the last element
allocated gets freed again and again), and continues checking one
element in the head and one in the tail.

Thanks to @dvisrky that fixed the original implementation of the
function and proposed zig zag scanning.
2016-06-23 09:09:51 +02:00
Salvatore Sanfilippo
2fe9b79897 Merge pull request #3244 from dvirsky/optimize_autoMemoryFreed
Optimized autoMemoryFreed loop
2016-06-23 08:59:38 +02:00
Yossi Gottlieb
61172ed01e Add RedisModule_CreateStringFromString(). 2016-06-22 21:02:40 +03:00
Dvir Volk
dc7f3fefad added RM_Calloc implementation 2016-06-22 17:32:41 +03:00
Yossi Gottlieb
e22f3e40d5 Cleanup: remove zset reset function from RM_ZsetRangeStop(). 2016-06-22 07:34:14 +03:00
Yossi Gottlieb
a8e2034548 Fix occasional RM_OpenKey() crashes. 2016-06-21 10:22:19 +03:00
Yossi Gottlieb
8f3a4df775 Use const in Redis Module API where possible. 2016-06-20 23:08:06 +03:00
antirez
9a02dac2e8 Free module context after loading.
Now that modules receive RedisModuleString objects on loading, they are
allowed to call the String API, so the context must be released
correctly.

Related to #3293.
2016-06-13 09:45:53 +02:00
antirez
1ad5c22763 Minor changes to unifor C style to Redis code base for PR #3293. 2016-06-13 09:39:44 +02:00
Salvatore Sanfilippo
e8d5387a44 Merge pull request #3293 from yossigo/module_config
Allow passing arguments to modules on load.
2016-06-13 09:31:59 +02:00
Yossi Gottlieb
87312ff781 Fix MODULE UNLOAD crash and/or wrong error message. 2016-06-05 13:27:38 +03:00
Yossi Gottlieb
cc58f11ccc Use RedisModuleString for OnLoad argv. 2016-06-05 13:18:24 +03:00
Yossi Gottlieb
2bd13cf0eb Allow passing arguments to modules on load. 2016-06-05 11:37:24 +03:00
antirez
8ec28002be Modules: support for modules native data types. 2016-06-03 18:14:04 +02:00
Dvir Volk
137fd86a61 optimized amFree even further 2016-05-19 13:51:55 +03:00
Dvir Volk
46b07cbb5c Optimized autoMemoryFreed loop 2016-05-19 12:16:14 +03:00
antirez
e3edae957b Modules: RM_HashSet() SDS ownership business clarified in comments.
Related to #3239.
2016-05-18 16:30:20 +02:00
Dvir Volk
cfaef8d5d4 fixed bad transfer of ownership in HashSet causing a potential crash 2016-05-17 16:47:36 +03:00
antirez
9aff564045 Modules: initial pool allocator and a LEFTPAD usage example. 2016-05-14 19:42:31 +02:00
antirez
646c958bbd Modules: doc layout improved. 2016-05-10 18:54:58 +02:00
antirez
5daece2ec6 RM_ZsetRangeNext()/Prev() typo in define name leading to crash fixed. 2016-05-10 06:40:11 +02:00
antirez
5f977c3f8b Modules: commandFlagsFromString() top comment back to 80 cols max. 2016-05-10 06:40:11 +02:00
antirez
ef2b4f6496 Trailing spaces removed from moduleCreateArgvFromUserFormat(). 2016-05-10 06:40:11 +02:00
antirez
6250a6b11f Modules: RM_GetClientId() implemented. 2016-05-10 06:40:11 +02:00
Dvir Volk
9a71df505c fixed crash when calling CreateStringFromCallReply on array elements 2016-05-10 06:40:11 +02:00
Itamar Haber
3816f16a53 Avoids reallocating and double String on truncate 2016-05-10 06:40:11 +02:00
Dvir Volk
d41bd233d5 fixed comment formatting in RM_CreateCommand 2016-05-10 06:40:10 +02:00
Dvir Volk
a00e872560 another small comment fix 2016-05-10 06:40:10 +02:00
Dvir Volk
87de31f968 fixed comment 2016-05-10 06:40:10 +02:00
Dvir Volk
8fc67080a2 second attempt at vector formtting 2016-05-10 06:40:10 +02:00
antirez
7f5e1340f9 Modules: add ZADD_INCR flag to zset increment API. 2016-05-10 06:40:10 +02:00
Itamar Haber
1186f92b1b typo: %s/Emtpy/Empty/g 2016-05-10 06:40:10 +02:00
antirez
227d68094b Modules: command <-> core interface modified to get flags & keys. 2016-05-10 06:40:09 +02:00
Ramon Snir
676a6a4d19 tiny typo in Redis Modules API documentation 2016-05-10 06:40:09 +02:00
Dvir Volk
a1f8e22b79 fixed return value of HashGet (and a slight error in the documentation) 2016-05-10 06:40:09 +02:00
antirez
42f72210fd Modules: Hash API defines made more uniform. 2016-05-10 06:40:09 +02:00
antirez
9b0556cf10 Modules: Hash type API WIP #2. 2016-05-10 06:40:09 +02:00
antirez
10993ca0d5 Modules: Hash type API WIP #1. 2016-05-10 06:40:09 +02:00
antirez
5bf5fd24c6 Modules: a few fixes for the zset iterator. 2016-05-10 06:40:09 +02:00
antirez
33e1231e53 Modules: postponed array lengths. 2016-05-10 06:40:09 +02:00
antirez
00109e1113 Modules: zset lex iterator #3. 2016-05-10 06:40:09 +02:00
antirez
db3ade22eb Modules: zset lex iterator #2. 2016-05-10 06:40:09 +02:00
antirez
2b04f86ae5 Modules: zset lex iterator #1. 2016-05-10 06:40:08 +02:00
antirez
083f5277c5 Modules: zset iterator redesign #1. 2016-05-10 06:40:08 +02:00
antirez
0fd6d548ca Modules: fix top comments to be user-facing doc quality. About 33% done. 2016-05-10 06:40:08 +02:00
antirez
f362f7a18a Modules: sorted set iterators WIP #3. 2016-05-10 06:40:08 +02:00
antirez
bdbb5a0253 Modules: put zset iterator current element in auto memory pool. 2016-05-10 06:40:08 +02:00
antirez
6eeeda39e9 Modules: sorted set iterators WIP #2. 2016-05-10 06:40:08 +02:00
antirez
eac5a13cb7 Modules: sorted set iterators WIP. 2016-05-10 06:40:08 +02:00
antirez
556d593d37 Remove useless space. 2016-05-10 06:40:08 +02:00
antirez
d5ecedd185 Modules: ZSET API WIP #4. 2016-05-10 06:40:07 +02:00