Commit Graph

731 Commits

Author SHA1 Message Date
Oran Agra a37cca3644 fix leak in RM_LoadDataTypeFromString, and save 2019-12-11 12:35:00 +02:00
Oran Agra 173cca5413 fix possible warning on incomplete struct init 2019-12-10 11:16:13 +02:00
antirez e4b6070c0f Modules: more clarification about disconnection callback. 2019-12-09 12:15:38 +01:00
antirez 2271cf03f5 Modules: clarify when the disconnection callback is called. 2019-12-05 10:38:18 +01:00
antirez 7b5f4b175b Modules: create timers in contexts without a client. 2019-12-03 16:21:23 +01:00
zhaozhao.zz 2c970532dc Propagation: flag module client as CLIENT_MULTI if needed
in case of nested MULTI/EXEC
2019-11-22 16:20:30 +08:00
zhaozhao.zz 37a10cef02 Propagation: wrap commands in also_propagate array with MULIT/EXEC
Random command like SPOP with count is replicated as
some SREM operations, and store them in also_propagate
array to propagate after the call, but this would break
atomicity.

To keep the command's atomicity, wrap also_propagate
array with MULTI/EXEC.
2019-11-22 15:42:49 +08:00
Salvatore Sanfilippo 64c2508ee3
Merge branch 'unstable' into rm_get_server_info 2019-11-21 10:06:15 +01:00
Salvatore Sanfilippo f1f259de5b
Merge pull request #6547 from guybe7/module_api_streams
Support streams in general module API functions
2019-11-21 10:03:50 +01:00
antirez da47d52c79 Recomment PR #6346. 2019-11-21 10:01:49 +01:00
Salvatore Sanfilippo 70469b76d6
Merge branch 'unstable' into expose_zmalloc_capabilities 2019-11-21 09:57:19 +01:00
Salvatore Sanfilippo e7144fbed8
Merge branch 'unstable' into module-long-double 2019-11-19 12:15:45 +01:00
Salvatore Sanfilippo e916058f0b
Merge pull request #6557 from oranagra/rm_lru_lfu_revized
rename RN_SetLRUOrLFU -> RM_SetLRU and RN_SetLFU
2019-11-19 11:58:07 +01:00
Salvatore Sanfilippo 06a24b9cfa
Merge pull request #6597 from yossigo/rm-call-extended-errors
Improve RM_Call() errno classification.
2019-11-19 11:41:32 +01:00
Yossi Gottlieb 2d1e893b3e Improve RM_Call() errno classification.
RM_Call() will now use EBADF and ENONET in addition to EINVAL in order
to provide more information about errors (i.e. when return value is
NULL).
2019-11-19 12:10:48 +02:00
Salvatore Sanfilippo 656e40eed2
Merge branch 'unstable' into scan_module_impl 2019-11-19 11:08:02 +01:00
Salvatore Sanfilippo 1530a3cfc6
Merge pull request #6577 from oranagra/module_doc
module docs, missing LOADING flag
2019-11-19 11:02:58 +01:00
Salvatore Sanfilippo 32a8301073
Merge pull request #4076 from yossigo/add_mt_replacevalue
Add RM_ModuleTypeReplaceValue.
2019-11-19 11:00:01 +01:00
Salvatore Sanfilippo 3d89210477
Merge pull request #3383 from yossigo/datatype_load_save
Redis Module API calls to allow re-use of data type RDB save/load.
2019-11-19 10:55:42 +01:00
Oran Agra c426bbf3a5 Slightly more efficient RM_ReplyWithEmptyString
trimming talk about RESP protocol from API docs (should be independent to that anyway)
2019-11-14 09:46:46 +02:00
Oran Agra 2d30afc45f module docs, missing LOADING flag 2019-11-14 09:09:10 +02:00
Yossi Gottlieb 9c76875f41 Add RM_ModuleTypeReplaceValue.
This is a light-weight replace function, useful for use cases such as
realloc()ing an existing value, etc.  Using RM_ModuleTypeSetValue() in
such cases is wasteful and complex as it attempts to delete the old
value, call its destructor, etc.
2019-11-14 08:50:11 +02:00
Oran Agra 0f8692b464 Add RM_ScanKey to scan hash, set, zset, changes to RM_Scan API
- Adding RM_ScanKey
- Adding tests for RM_ScanKey
- Refactoring RM_Scan API

Changes in RM_Scan
- cleanup in docs and coding convention
- Moving out of experimantal Api
- Adding ctx to scan callback
- Dont use cursor of -1 as an indication of done (can be a valid cursor)
- Set errno when returning 0 for various reasons
- Rename Cursor to ScanCursor
- Test filters key that are not strings, and opens a key if NULL
2019-11-11 16:05:55 +02:00
meir@redislabs.com 11c6ce812a Added scan implementation to module api.
The implementation expose the following new functions:
1. RedisModule_CursorCreate - allow to create a new cursor object for
keys scanning
2. RedisModule_CursorRestart - restart an existing cursor to restart the
scan
3. RedisModule_CursorDestroy - destroy an existing cursor
4. RedisModule_Scan - scan keys

The RedisModule_Scan function gets a cursor object, a callback and void*
(used as user private data).
The callback will be called for each key in the database proving the key
name and the value as RedisModuleKey.
2019-11-11 16:01:41 +02:00
Oran Agra 28c20b4ef9 rename RN_SetLRUOrLFU -> RM_SetLRU and RN_SetLFU
- the API name was odd, separated to two apis one for LRU and one for LFU
- the LRU idle time was in 1 second resolution, which might be ok for RDB
  and RESTORE, but i think modules may need higher resolution
- adding tests for LFU and for handling maxmemory policy mismatch
2019-11-10 09:27:01 +02:00
meir@redislabs.com e45239e350 fix documentation 2019-11-06 12:26:03 +02:00
Guy Benoish 1833d008b3 Support streams in general module API functions
Fixes GitHub issue #6492
Added stream support in RM_KeyType and RM_ValueLength.
Also moduleDelKeyIfEmpty was updated, even though it has
no effect now (It will be relevant when stream type direct
API will be coded - i.e. RM_StreamAdd)
2019-11-06 15:52:19 +05:30
meir@redislabs.com c032dc45d1 changed GetUsedMemoryPresentage -> GetUsedMemoryRatio and return value between 0 and 1. 2019-11-06 12:17:09 +02:00
meir@redislabs.com aded138a59 return value between 0 to 100 instead of 0 to 1. 2019-11-06 11:28:52 +02:00
meir@redislabs.com 089ee5979d expose used memory via redismodule api
The exposed functions:
1. RedisModule_GetUsedMemoryPercentage - return the used memory
2. RedisModue_MallocSize - return for a given pointer, the amount of memory allocated for this pointer
2019-11-06 11:28:52 +02:00
Yossi Gottlieb 5350e7669e Add ModuleDataType to/from string serialization.
Add two new functions that leverage the RedisModuleDataType mechanism
for RDB serialization/deserialization and make it possible to use it
to/from arbitrary strings:

* RM_SaveDataTypeToString()
* RM_LoadDataTypeFromString()
2019-11-04 21:53:59 +02:00
artix a68c19df6c RM_CreateStringFromLongDouble: use new ld2string 'mode' type 2019-11-04 18:49:56 +01:00
artix 60ec2b78b3 Start support for long double in modules
New API:

- RedisModule_StringToLongDouble
- RedisModule_CreateStringFromLongDouble
- RedisModule_ReplyWithLongDouble
2019-11-04 18:49:42 +01:00
Salvatore Sanfilippo bbdbfabf9e
Merge pull request #6531 from oranagra/rm_save_long_double
Module API for loading and saving long double
2019-11-04 17:33:35 +01:00
Salvatore Sanfilippo 18b62a51e2
Merge branch 'unstable' into module_lru_lfu 2019-11-04 11:04:49 +01:00
Salvatore Sanfilippo 327cb45ed5
Merge pull request #6532 from oranagra/rm_misc_commands
Module API for PUBLISH, FLUSHALL, RANDOMKEY, DBSIZE
2019-11-04 11:02:37 +01:00
Salvatore Sanfilippo da44c54897
Merge branch 'unstable' into module_hooks 2019-11-04 10:37:06 +01:00
Oran Agra 0423309768 Add RM_ServerInfoGetFieldUnsigned
rename RM_ServerInfoGetFieldNumerical RM_ServerInfoGetFieldSigned
move string2ull to util.c
fix leak in RM_GetServerInfo when duplicate info fields exist
2019-11-04 08:50:29 +02:00
Oran Agra deebed23e1 Adding RM_ServerInfoGetFieldC 2019-11-04 07:57:52 +02:00
Oran Agra 87332ce524 Module API for PUBLISH, FLUSHALL, RANDOMKEY, DBSIZE 2019-11-04 07:40:52 +02:00
Oran Agra 779aebc91c Module API for loading and saving long double
looks like each platform implements long double differently (different bit count)
so we can't save them as binary, and we also want to avoid creating a new RDB
format version, so we save these are hex strings using "%La".

This commit includes a change in the arguments of ld2string to support this.
as well as tests for coverage and short reads.

coded by @guybe7
2019-11-03 16:42:31 +02:00
Oran Agra 4d580438b0 Add module api for looking into INFO fields
- Add RM_GetServerInfo and friends
- Add auto memory for new opaque struct
- Add tests for new APIs

other minor fixes:
- add const in various char pointers
- requested_section in modulesCollectInfo was actually not sds but char*
- extract new string2d out of getDoubleFromObject for code reuse

Add module API for
2019-11-03 15:02:25 +02:00
antirez fdaea2a7a7 Modules: fix thread safe context creation crash.
See #6525, this likely creates a NULL deference if the client was
terminated by Redis between the creation of the blocked client and the
creation of the thread safe context.
2019-10-31 18:07:33 +01:00
antirez 1ee195d255 Merge branch 'unstable' of github.com:/antirez/redis into unstable 2019-10-31 17:55:18 +01:00
antirez 825adcf3f5 Modules: block on keys: finish implementing RM_UnblockClient(). 2019-10-31 17:39:05 +01:00
antirez 66f55bc5c1 Modules: block on keys: fix bugs in processing order. 2019-10-31 12:23:55 +01:00
antirez 629081f839 Modules: block on keys: fix the top comments. 2019-10-31 11:43:45 +01:00
antirez 91f4bdc9f9 Modules: block on keys: use a better interface.
Using the is_key_ready() callback plus the reply callback later, creates
different issues AFAIK:

1. More complex API.
2. We need to call the reply callback() ASAP if the is_key_ready()
interface returned success, however the internals do not work in that
way, so when the reply callback is called the setup could be different.
To fix that, there is to break the current design that handles the
unblocked clients asyncrhonously, and run the list ASAP.
2019-10-31 11:35:07 +01:00
antirez 4534960b29 Modules: remove spurious call from moduleHandleBlockedClients().
Now we handle propagation when we free the context.
2019-10-31 10:32:59 +01:00
antirez 215b72c0ba Modules: block on keys: implement the internals. 2019-10-30 10:57:44 +01:00
antirez fb6110ac20 Modules: block on keys: export APIs. 2019-10-30 10:20:28 +01:00
antirez 3649568ff2 Modules: block on keys functions layout and mechanism. 2019-10-30 10:11:58 +01:00
Oran Agra 51c3ff8d75 Modules hooks: complete missing hooks for the initial set of hooks
* replication hooks: role change, master link status, replica online/offline
* persistence hooks: saving, loading, loading progress
* misc hooks: cron loop, shutdown, module loaded/unloaded
* change the way hooks test work, and add tests for all of the above

startLoading() now gets flag indicating what is loaded.
stopLoading() now gets an indication of success or failure.
adding startSaving() and stopSaving() with similar args and role.
2019-10-29 17:59:09 +02:00
Oran Agra e978bdf9ef Module API for controlling LRU and LFU, and OpenKey without TOUCH
Some commands would want to open a key without touching it's LRU/LFU
similarly to the OBJECT or DEBUG command do.

Other commands may want to implement logic similar to what RESTORE
does (and in the future MIGRATE) and get/set the LRU or LFU.
2019-10-29 15:03:05 +02:00
Salvatore Sanfilippo 764b420f5f
Merge pull request #6487 from oranagra/module_modified_key
Module API for explicit SignalModifiedKey instead of implicit one.
2019-10-29 10:40:22 +01:00
Salvatore Sanfilippo 90169cdf16
Merge pull request #6495 from oranagra/rm_call_argv
Module api RM_CallArgv and test
2019-10-29 10:07:05 +01:00
Oran Agra 0399b5a27e Module api tests for RM_Call
Adding a test for coverage for RM_Call in a new "misc" unit
to be used for various short simple tests

also solves compilation warnings in redismodule.h and fork.c
2019-10-28 12:39:57 +02:00
Guy Benoish cee6dead3c Modules: Allow notifying custom keyspace events
Also, add an API for getting server.notify_keyspace_events

Other (unrelated) changes:
Add RM_GetKeynameFromModuleKey
2019-10-28 15:53:35 +05:30
Oran Agra a12f07792f Module API for explicit SignalModifiedKey instead of implicit one.
This commit also fixes an uninitialized module struct member (that luckily never got released)
2019-10-28 12:09:25 +02:00
Salvatore Sanfilippo 5aab012676
Merge pull request #6498 from oranagra/rm_latency_add_sample
Module API for LatencyAddSample
2019-10-28 09:59:26 +01:00
Salvatore Sanfilippo d070221707
Merge pull request #6505 from swilly22/replaywith-module-API-additions
Introduce ReplyWithVerbatimString, ReplyWithEmptyArray, ReplyWithNull…
2019-10-28 09:56:56 +01:00
swilly22 56a7c45521 Introduce ReplyWithVerbatimString, ReplyWithEmptyArray, ReplyWithNullArray and ReplyWithEmptyString to redis module API 2019-10-28 08:50:25 +02:00
zhaozhao.zz c74398e130 Modules: make unloading module more safe
As we know if a module exports module-side data types,
unload it is not allowed. This rule is the same with
blocked clients in module, because we use background
threads to implement module blocked clients, and it's
not safe to unload a module if there are background
threads running. So it's necessary to check if any
blocked clients running in this module when unload it.

Moreover, after that we can ensure that if no modules,
then no module blocked clients even module unloaded.
So, we can call moduleHandleBlockedClients only when
we have installed modules.
2019-10-28 11:31:58 +08:00
Oran Agra e3b1d6d3ad Module API for LatencyAddSample 2019-10-24 14:24:55 +03:00
antirez 6e98214f74 Modules hooks: test flush event. 2019-10-24 10:51:03 +02:00
antirez 7cefbeaad5 Modules hooks: select DB zero by default. 2019-10-23 18:51:44 +02:00
antirez 61ac2aef2b Modules hooks: for nested calls, create new fake clients.
We can't use the same client at the same time when re-entering the hook.
2019-10-23 18:39:53 +02:00
antirez 83de18805c Modules hooks: do not re-enter in hooks.
Calling a module hook callback may result in callback operations in turn
triggering other events the module is subscribed too. We don't want to
trigger those, it's unsafe and quite confusing, and to do it correcly we
would need to maintain an event list: quite a more complex
implementation.
2019-10-23 18:39:53 +02:00
antirez 89af7e4c85 Modules hooks: select the right DB for FLUSHDB events. 2019-10-23 18:39:53 +02:00
antirez bc1ef48e56 Modules hooks: FLUSHDB event example. 2019-10-23 18:39:53 +02:00
antirez ed833c9f99 Modules hooks: implement the FLUSHDB event. 2019-10-23 18:39:53 +02:00
antirez 8ec2fc3969 Modules hooks: unify structures definitions. 2019-10-23 18:39:53 +02:00
antirez db8c9a8520 Modules hooks: document what yet to implement WIP 2. 2019-10-23 18:39:53 +02:00
antirez 18d1607f5e Modules hooks: document what yet to implement WIP 1. 2019-10-23 18:39:53 +02:00
antirez cf52e0ad44 Module hooks: fixes and an example module. 2019-10-23 18:39:53 +02:00
antirez 019ac37e9c Modules hooks: fix define / linker issues. Implement one test event. 2019-10-23 18:39:53 +02:00
antirez d54652682d Modules hooks: handle module unloading + API export. 2019-10-23 18:39:53 +02:00
antirez 1e78681df8 Modules hooks: fix a leak and a few more issues. 2019-10-23 18:39:53 +02:00
antirez b9af7e24e4 Modules hooks: event firing logic. 2019-10-23 18:39:53 +02:00
antirez 6e56f513b4 Modules: refactoring of RM_GetClientInfoById(). 2019-10-23 18:39:53 +02:00
antirez 21d8544128 Modules: fix RedisModule_GetClientInfoById() example. 2019-10-23 18:39:53 +02:00
antirez e9b5484ddd Modules: export GetClientInfoById(). 2019-10-23 18:39:53 +02:00
antirez 6ea8641ae0 Modules: add the client ID to the client info structure. 2019-10-23 18:39:53 +02:00
antirez d2d74ca0f3 Modules: RM_GetClientInfoById() draft. 2019-10-23 18:39:53 +02:00
antirez bebb2e1994 Modules hooks: a first version of events and some API. 2019-10-23 18:39:53 +02:00
antirez 3170f63330 Modules hooks: initial design of data structures. 2019-10-23 18:39:53 +02:00
antirez ed2ba31e4c Modules: fix moduleCreateArgvFromUserFormat() casting bug.
In 32 bit systems casting to "long" will cut the result to 32 bit.
2019-10-23 18:39:14 +02:00
antirez 673c9d7029 module: fix propagation API bug. 2019-10-17 18:28:34 +02:00
antirez 97f6e314c1 Modules: allow to check for AOF loading client. 2019-10-17 18:10:50 +02:00
antirez 8651e6a10d Modules: add new flags to context, replica state + more. 2019-10-17 17:49:33 +02:00
Yossi Gottlieb 0db3b0a0ff Merge remote-tracking branch 'upstream/unstable' into tls 2019-10-16 17:08:07 +03:00
Salvatore Sanfilippo b8e02f2b40
Merge pull request #5926 from JimB123/unstable
Addition of RedisModule_OnUnload hook
2019-10-16 11:13:12 +02:00
Yossi Gottlieb b087dd1db6 TLS: Connections refactoring and TLS support.
* Introduce a connection abstraction layer for all socket operations and
integrate it across the code base.
* Provide an optional TLS connections implementation based on OpenSSL.
* Pull a newer version of hiredis with TLS support.
* Tests, redis-cli updates for TLS support.
2019-10-07 21:06:13 +03:00
antirez 3eaff2941e Modules: RM_Call(): give pointer to documentation. 2019-10-04 11:46:53 +02:00
antirez 2a81e49dde Modules: RM_Call/Replicate() ability to exclude AOF/replicas. 2019-10-04 11:44:53 +02:00
antirez 1bca62c4b7 Modules: RM_Replicate() in thread safe contexts. 2019-10-03 11:03:46 +02:00
antirez e938bbc543 Modules: implement RM_Replicate() from async callbacks. 2019-10-03 10:56:37 +02:00
antirez c549513acd Modules: handle propagation when ctx is freed. Flag modules commands ctx. 2019-10-02 18:33:40 +02:00
Oran Agra 1b4f888109 Use sdscatfmt instead of sdscatprintf in module info
sdscatfmt is faster
2019-09-30 21:13:13 +03:00
Oran Agra d5c14c70b7 Merge remote-tracking branch 'antirez/unstable' into modules_info 2019-09-30 20:47:35 +03:00
antirez 23f5cb4233 Change a bit the style of #6385. 2019-09-30 10:58:15 +02:00
Salvatore Sanfilippo ad45d7e407
Merge pull request #6385 from filipecosta90/perf-reply-ss-error
Improve performance of RM_ReplyWithSimpleString and RM_ReplyWi…
2019-09-30 10:57:05 +02:00
antirez 916c4e5d86 moduleRDBLoadError(): io->ctx may be NULL.
The correct way to access the module about a given IO context is to
deference io->type->module, since io->ctx is only populated if the user
requests an explicit context from an IO object.
2019-09-27 18:42:38 +02:00
antirez 8b5848a4f5 Fix memory leak in moduleLoadFromQueue(). 2019-09-27 18:33:21 +02:00
antirez b394817754 Fix memory leak in RM_UnregisterCommandFilter(). 2019-09-27 18:33:05 +02:00
antirez 0a07f8ffee TerminateModuleForkChild(): fix function prototype. 2019-09-27 12:23:07 +02:00
antirez 721d3c9e0c TerminateModuleForkChild(): move safety checks there.
We don't want that the API could be used directly in an unsafe way,
without checking if there is an active child. Now the safety checks are
moved directly in the function performing the operations.
2019-09-27 12:17:47 +02:00
antirez de1f82aa33 Function renamed hasForkChild() -> hasActiveChildProcess(). 2019-09-27 12:03:09 +02:00
antirez 82845f8d04 TerminateModuleForkChild(): use wait4 for safety.
In theory currently there is only one active child, but the API may
change or for bugs in the implementation we may have several (it was
like that for years because of a bug). Better to wait for a specific
pid and avoid consuing other pending children information.
2019-09-27 11:59:58 +02:00
antirez ae3ef964c1 Modules fork: improve SIGUSR1 handling, fix include.
We can't expect SIGUSR1 to have any specific value range, so let's
define an exit code that we can handle in a special way.
This also fixes an #include <wait.h> that is not standard.
2019-09-27 11:39:45 +02:00
Salvatore Sanfilippo 6129758558
Merge branch 'unstable' into modules_fork 2019-09-27 11:24:06 +02:00
antirez b7b23bdfb8 INFO: more info about loaded modules.
Related to #6024.
2019-09-26 12:18:55 +02:00
Salvatore Sanfilippo c1ea6175c5
Merge pull request #6024 from itamarhaber/info_modules
Adds a "Modules" section to `INFO`
2019-09-26 11:58:52 +02:00
Salvatore Sanfilippo 959fb5cf68
Merge pull request #6235 from oranagra/module_rdb_load_errors
Allow modules to handle RDB loading errors.
2019-09-26 11:52:42 +02:00
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
antirez e1b34ecf98 Modules: ZSET API WIP #3. 2016-05-10 06:40:07 +02:00
antirez 4457e4acbe Modules: ZSET API WIP #2. 2016-05-10 06:40:07 +02:00
antirez f199504ac9 Modules: ZSET API WIP. 2016-05-10 06:40:07 +02:00
antirez 11b3df24cb Modules: expire API and documentation. 2016-05-10 06:40:07 +02:00
antirez f4e0129fa9 Modules: RedisModule_ReplyWithCallReply(). 2016-05-10 06:40:07 +02:00
Sun He 2e464bf0b1 modules/RM_StringTruncate: correct reallocate condition 2016-05-10 06:40:06 +02:00
Sun He 3a7b170205 modules/RM_OpenKey: avoid decrRefCount obj twice 2016-05-10 06:40:06 +02:00
Sun He 1868dee6f2 modules/RM_StringSet: set key->value 2016-05-10 06:40:06 +02:00
Sun He fded8aa4e5 modules: correct protolen 2016-05-10 06:40:06 +02:00
antirez 4efe9e19c1 Add the last break for consistency in moduleCreateCallReplyFromProto. 2016-05-10 06:40:06 +02:00
Dvir Volk e453d36e1e fixed case in moduleCreateCallReplyFromProto 2016-05-10 06:40:06 +02:00
Dvir Volk ae5cb3f7d5 renamed RedisModule_ReplyWithNull to RM_ReplyWithNull to fix compilation 2016-05-10 06:40:06 +02:00
antirez 2967c00c2c Modules: RedisModule_ReplyWithNull() implemented. 2016-05-10 06:40:06 +02:00
Yossi Gottlieb e443ad9c29 Log loadmodule dlopen() errors. 2016-05-10 06:40:06 +02:00
antirez 85919f80ed Modules: avoid conflict between modules func pointers and dynamic symbols.
In modules we fill a set of function pointers defined in redismodule.h,
populating a set of APIs that are callable from the module. We use this
manual process instead of resorting to dynamic linking so that we have
exact control on how we pass the API to the module, and we can even pass
different functions for the same name, depending on the API version
declared by the module.

However if the function pointers in redismodule.h and the functions
defined in module.c have the same name, they conflict since the core
exports the symbols to the module.

There is probably some compiler flags trick to avoid this, but in order
to be safer in the future and be more easily compatible with different
builidng systems, this commit changes the internal function prefix from
RedisModule_ to RM_, so for example:

    RM_StringSet() will be exported as RedisModule_StringSet()
2016-05-10 06:40:05 +02:00
antirez 6020469452 Modules: remove warnings due to void/function pointer conversion. 2016-05-10 06:40:05 +02:00
antirez 6dead2cff5 Modules: first preview 31 March 2016. 2016-05-10 06:40:05 +02:00