Commit Graph

467 Commits

Author SHA1 Message Date
Oran Agra
46216b0e83 add no-slowlog option to RM_CreateCommand 2020-02-06 15:06:33 +02:00
Oran Agra
28ef18a894 RM_Scan disable dict rehashing
The callback approach we took is very efficient, the module can do any
filtering of keys without building any list and cloning strings, it can
also read data from the key's value. but if the user tries to re-open
the key, or any other key, this can cause dict re-hashing (dictFind does
that), and that's very bad to do from inside dictScan.

this commit protects the dict from doing any rehashing during scan, but
also warns the user not to attempt any writes or command calls from
within the callback, for fear of unexpected side effects and crashes.
2020-02-06 11:48:12 +02:00
Salvatore Sanfilippo
5bfba06a3b
Merge pull request #6821 from guybe7/key_miss_notify
Exclude "keymiss" notification from NOTIFY_ALL
2020-02-06 10:43:05 +01:00
Salvatore Sanfilippo
2e1dd00c80
Merge pull request #6837 from oranagra/signal_modified_key_doc
update RM_SignalModifiedKey doc comment
2020-02-06 10:38:36 +01:00
Salvatore Sanfilippo
13741fb99d
Merge pull request #6846 from oranagra/module_client_flags
Fix client flags to be int64 in module.c
2020-02-06 10:32:35 +01:00
Oran Agra
85cc696f50 moduleRDBLoadError, add key name, and use panic rather than exit
using panic rather than exit means you get s stack trace of the code
path that experianced the error, and possibly other info.
2020-02-06 09:37:04 +02:00
Oran Agra
d454d5a4f5 Fix client flags to be int64 in module.c
currently there's no bug since the flags these functions handle are
always lower than 32bit, but still better fix the type to prevent future
bugs.
2020-02-06 09:33:20 +02:00
Oran Agra
3795aaf42a update RM_SignalModifiedKey doc comment 2020-02-05 18:15:38 +02:00
Guy Benoish
1c7a2269d6 Add RM_CreateStringFromDouble 2020-02-04 19:28:09 +05:30
Oran Agra
138ed120dd fix uninitialized info_cb var in module.c 2020-02-03 16:35:39 +02:00
Guy Benoish
2fda5f5c98 Exclude "keymiss" notification from NOTIFY_ALL
Because "keymiss" is "special" compared to the rest of
the notifications (Trying not to break existing apps
using the 'A' format for notifications)

Also updated redis.conf and module.c docs
2020-02-03 15:43:44 +05:30
Salvatore Sanfilippo
53ac8c7df2
Merge pull request #6812 from guybe7/str_convert_fix
ld2string should fail if string contains \0 in the middle
2020-01-30 17:51:04 +01:00
Guy Benoish
2deb55512f ld2string should fail if string contains \0 in the middle
This bug affected RM_StringToLongDouble and HINCRBYFLOAT.
I added tests for both cases.

Main changes:
1. Fixed string2ld to fail if string contains \0 in the middle
2. Use string2ld in getLongDoubleFromObject - No point of
   having duplicated code here

The two changes above broke RM_SaveLongDouble/RM_LoadLongDouble
because the long double string was saved with length+1 (An innocent
mistake, but it's actually a bug - The length passed to
RM_SaveLongDouble should not include the last \0).
2020-01-30 18:15:17 +05:30
antirez
17ff3173d6 Add more info in the unblockClientFromModule() function. 2020-01-29 12:47:50 +01:00
Salvatore Sanfilippo
bf53f9280a
Merge pull request #6699 from guybe7/module_blocked_on_key_timeout_memleak
Modules: Fix blocked-client-related memory leak
2020-01-29 12:06:14 +01:00
Guy Benoish
d7d13721d3 Modules: Fix blocked-client-related memory leak
If a blocked module client times-out (or disconnects, unblocked
by CLIENT command, etc.) we need to call moduleUnblockClient
in order to free memory allocated by the module sub-system
and blocked-client private data

Other changes:
Made blockedonkeys.tcl tests a bit more aggressive in order
to smoke-out potential memory leaks
2019-12-30 10:10:59 +05:30
Yossi Gottlieb
0c898bdb07 Add REDISMODULE_CTX_FLAGS_MULTI_DIRTY. 2019-12-23 19:43:51 +02:00
Oran Agra
660645c742 modules don't signalModifiedKey in setKey() since that's done (optionally) in RM_CloseKey 2019-12-23 10:15:52 +02:00
antirez
324e22accf Fix ip and missing mode in RM_GetClusterNodeInfo(). 2019-12-20 12:29:02 +01:00
Salvatore Sanfilippo
d3a9dff6b9
Merge pull request #6615 from soloestoy/wrap-also-propagate-as-multi
Wrap also propagate as multi
2019-12-19 09:24:52 +01:00
antirez
c5bc1c14c0 Modules: rewrite top function doc of AvoidReplicaTraffic(). 2019-12-18 17:11:03 +01:00
Salvatore Sanfilippo
ef0b45ece8
Merge pull request #6497 from oranagra/avoid_replica_traffic
Add config and module API for AvoidReplicaTraffic
2019-12-18 17:06:05 +01:00
antirez
5b9d3ac6c6 Avoid changing setKey() API after #6679 fix. 2019-12-18 11:58:02 +01:00
zhaozhao.zz
24044f3356 add a new SET option KEEPTTL that doesn't remove expire time 2019-12-18 15:20:36 +08:00
Salvatore Sanfilippo
b7c78b7651
Merge pull request #5916 from madolson/dev-unstable-acl-module-pr
Add module APIs for custom authentication
2019-12-17 09:58:26 +01:00
Madelyn Olson
576a08908b Split error message so dependandent callers give a useful result 2019-12-16 23:34:37 -08:00
Madelyn Olson
44aa22c635 Added better exception handling around scripting and module 2019-12-16 23:33:53 -08:00
Madelyn Olson
f891b64a83 Tweaking the documentation 2019-12-17 07:28:55 +00:00
Madelyn Olson
034dcf185c Add module APIs for custom authentication 2019-12-17 06:59:59 +00:00
antirez
aa3f13761f Merge branch 'unstable' of github.com:/antirez/redis into unstable 2019-12-16 11:18:20 +01:00
antirez
096592506e Modules: allow to execute RM_Call() from the module init function. 2019-12-13 17:34:37 +01:00
Yossi Gottlieb
0283db5883 Improve RM_ModuleTypeReplaceValue() API.
With the previous API, a NULL return value was ambiguous and could
represent either an old value of NULL or an error condition. The new API
returns a status code and allows the old value to be returned
by-reference.

This commit also includes test coverage based on
tests/modules/datatype.c which did not exist at the time of the original
commit.
2019-12-12 18:50:11 +02:00
antirez
476333d192 Remove useless space from moduleLoad(). 2019-12-12 09:29:10 +01:00
Salvatore Sanfilippo
2968d8e3cb
Merge branch 'unstable' into ModuleSecurity 2019-12-12 09:27:14 +01:00
Oran Agra
b5f3247ca5 Add module API for AvoidReplicaTraffic
This is useful to tell redis and modules to try to avoid doing things that may
increment the replication offset, and should be used when draining a master
and waiting for replicas to be in perfect sync before a failover.
2019-12-12 08:38:09 +02:00
Salvatore Sanfilippo
c6fb9d0963
Merge pull request #6656 from oranagra/leak_rm_load_from_str
fix leak in RM_LoadDataTypeFromString, and save
2019-12-11 11:39:27 +01:00
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