Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3f9bdaf
WIP Add Support for RDB Short Read
oshadmi Jun 13, 2021
ae48442
WIP Add Support for RDB Short Read (not using macros yet)
oshadmi Jun 17, 2021
e2126e1
Merge remote-tracking branch 'origin/master' into omer-short-read
oshadmi Jul 25, 2021
495d8fd
WIP allow rdb_load to short read
oshadmi Jul 26, 2021
1256511
Add minimal version check for short read
oshadmi Jul 28, 2021
f6b0f5f
Merge branch 'master' into omer-short-read
gkorland Jul 28, 2021
b9161e4
Fixes per Guy's code review
oshadmi Aug 1, 2021
13897a8
Merge remote-tracking branch 'origin/master' into omer-short-read
oshadmi Aug 1, 2021
5dab8e2
Update .lock to use the last commit of redismodule-rs branch
oshadmi Aug 4, 2021
9861a39
Module should perform check_minimal_version_for_short_read on its own
oshadmi Aug 6, 2021
4238180
Merge remote-tracking branch 'origin/master' into omer-short-read
oshadmi Aug 6, 2021
f1db324
Avoid check_minimal_version_for_short_read (there's no aux data)
oshadmi Aug 10, 2021
4f28679
Merge remote-tracking branch 'origin/master' into omer-short-read
oshadmi Aug 10, 2021
8014012
WIP Add short read test
oshadmi Aug 11, 2021
f63a1f5
WIP move to latest redismodule-rs in omer-short-read branch
oshadmi Aug 11, 2021
d2efb29
Handle decoding/encoding in redis connection and mock
oshadmi Aug 12, 2021
54617d2
Fixes per code review by Gavrie
oshadmi Aug 16, 2021
3c3448a
Deploy ReJSON to S3
oshadmi Aug 17, 2021
2d06152
Update readies submodule
oshadmi Aug 17, 2021
cf7c9a1
Debug: push branch artifacts to S3
rafie Aug 17, 2021
8f554a4
Debug: build platforms
rafie Aug 17, 2021
a426d68
Debug: build platforms (2)
rafie Aug 17, 2021
ee3bef9
Debug: build platforms (3)
rafie Aug 17, 2021
2d812bf
Use latest redismodule-rs in corresponding branch
oshadmi Aug 17, 2021
204b455
Fixed per code review by Meir
oshadmi Aug 18, 2021
ae36e4a
Minor update to test
oshadmi Aug 19, 2021
33d24a8
Remove aux_load
oshadmi Aug 22, 2021
cc53cb9
Update .lock to last commit of corresponding redismodule-rs branch
oshadmi Aug 22, 2021
8a05824
Bump version of dep redismodule to 0.23.0 and rollback temp CI changes
oshadmi Aug 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,3 @@ workflows:
jobs:
- performance-automation:
context: common

34 changes: 18 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ bson = "0.14"
serde_json = "1.0"
serde = "1.0"
libc = "0.2"
jsonpath_lib = { git="https://github.com/RedisJSON/jsonpath.git", branch="generic_json_path" }
redis-module = { version="0.22", features = ["experimental-api"]}
jsonpath_lib = { git = "https://github.com/RedisJSON/jsonpath.git", branch = "generic_json_path" }
redis-module = { version="0.23", features = ["experimental-api"]}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also bump it on hdt...

[features]
# Workaround to allow cfg(feature = "test") in redismodue-rs dependencies:
# https://github.com/RedisLabsModules/redismodule-rs/pull/68
Expand Down
55 changes: 34 additions & 21 deletions src/backward.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::vec::Vec;

use redis_module::raw;
use serde_json::map::Map;
use serde_json::Number;
use serde_json::Value;
use std::vec::Vec;

use crate::error::Error;

#[derive(Debug, PartialEq)]
enum NodeType {
Null, // used in masks and consistent type checking
Null,
// used in masks and consistent type checking
String,
Number,
Integer,
Expand Down Expand Up @@ -34,41 +38,50 @@ impl From<u64> for NodeType {
}
}

pub fn json_rdb_load(rdb: *mut raw::RedisModuleIO) -> Value {
let node_type = raw::load_unsigned(rdb).into();
pub fn json_rdb_load(rdb: *mut raw::RedisModuleIO) -> Result<Value, Error> {
let node_type = raw::load_unsigned(rdb)?.into();
match node_type {
NodeType::Null => Value::Null,
NodeType::Null => Ok(Value::Null),
NodeType::Boolean => {
let buffer = raw::load_string_buffer(rdb);
Value::Bool(buffer.as_ref()[0] == b'1')
let buffer = raw::load_string_buffer(rdb)?;
Ok(Value::Bool(buffer.as_ref()[0] == b'1'))
}
NodeType::Integer => {
let n = raw::load_signed(rdb)?;
Ok(Value::Number(n.into()))
}
NodeType::Number => {
let n = raw::load_double(rdb)?;
Ok(Value::Number(
Number::from_f64(n).ok_or_else(|| Error::from("Can't load as float"))?,
))
}
NodeType::Integer => Value::Number(raw::load_signed(rdb).into()),
NodeType::Number => Value::Number(Number::from_f64(raw::load_double(rdb)).unwrap()),
NodeType::String => {
let buffer = raw::load_string_buffer(rdb);
Value::String(buffer.to_string().unwrap())
let buffer = raw::load_string_buffer(rdb)?;
Ok(Value::String(buffer.to_string()?))
}
NodeType::Dict => {
let len = raw::load_unsigned(rdb);
let len = raw::load_unsigned(rdb)?;
let mut m = Map::with_capacity(len as usize);
for _ in 0..len {
let t: NodeType = raw::load_unsigned(rdb).into();
let t: NodeType = raw::load_unsigned(rdb)?.into();
if t != NodeType::KeyVal {
panic!("Can't load old RedisJSON RDB");
return Err(Error::from("Can't load old RedisJSON RDB"));
Comment thread
oshadmi marked this conversation as resolved.
Resolved
}
let buffer = raw::load_string_buffer(rdb);
m.insert(buffer.to_string().unwrap(), json_rdb_load(rdb));
let buffer = raw::load_string_buffer(rdb)?;
m.insert(buffer.to_string()?, json_rdb_load(rdb)?);
}
Value::Object(m)
Ok(Value::Object(m))
}
NodeType::Array => {
let len = raw::load_unsigned(rdb);
let len = raw::load_unsigned(rdb)?;
let mut v = Vec::with_capacity(len as usize);
for _ in 0..len {
v.push(json_rdb_load(rdb))
let nested = json_rdb_load(rdb)?;
v.push(nested);
}
Value::Array(v)
Ok(Value::Array(v))
}
NodeType::KeyVal => panic!("Can't load old RedisJSON RDB"),
NodeType::KeyVal => Err(Error::from("Can't load old RedisJSON RDB")),
Comment thread
oshadmi marked this conversation as resolved.
Resolved
}
}
8 changes: 8 additions & 0 deletions src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct ResultsIterator<'a, V: SelectValue> {

pub static mut LLAPI_CTX: Option<*mut rawmod::RedisModuleCtx> = None;

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn create_rmstring(
ctx: *mut rawmod::RedisModuleCtx,
from_str: &str,
Expand Down Expand Up @@ -83,6 +84,7 @@ pub fn json_api_get_at<M: Manager>(_: M, json: *const c_void, index: size_t) ->
}
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn json_api_get_len<M: Manager>(_: M, json: *const c_void, count: *mut libc::size_t) -> c_int {
let json = unsafe { &*(json as *const M::V) };
let len = match json.get_type() {
Expand Down Expand Up @@ -132,6 +134,7 @@ pub fn json_api_get_json<M: Manager>(
create_rmstring(ctx, &res, str)
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn json_api_get_int<M: Manager>(_: M, json: *const c_void, val: *mut c_long) -> c_int {
let json = unsafe { &*(json as *const M::V) };
match json.get_type() {
Expand All @@ -143,6 +146,7 @@ pub fn json_api_get_int<M: Manager>(_: M, json: *const c_void, val: *mut c_long)
}
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn json_api_get_double<M: Manager>(_: M, json: *const c_void, val: *mut c_double) -> c_int {
let json = unsafe { &*(json as *const M::V) };
match json.get_type() {
Expand All @@ -154,6 +158,7 @@ pub fn json_api_get_double<M: Manager>(_: M, json: *const c_void, val: *mut c_do
}
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn json_api_get_boolean<M: Manager>(_: M, json: *const c_void, val: *mut c_int) -> c_int {
let json = unsafe { &*(json as *const M::V) };
match json.get_type() {
Expand Down Expand Up @@ -191,6 +196,7 @@ pub fn get_type_and_size(value: &Value) -> (JSONType, size_t) {
RedisJSON::get_type_and_size(value)
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_string(from_str: &str, str: *mut *const c_char, len: *mut size_t) -> c_int {
if !str.is_null() {
unsafe {
Expand Down Expand Up @@ -236,6 +242,7 @@ pub fn json_api_free_iter<M: Manager>(_: M, iter: *mut c_void) {
}
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn json_api_get<M: Manager>(_: M, val: *const c_void, path: *const c_char) -> *const c_void {
let v = unsafe { &*(val as *const M::V) };
let mut selector = Selector::new();
Expand Down Expand Up @@ -289,6 +296,7 @@ macro_rules! redis_json_module_export_shared_api {
}

#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn JSONAPI_openKeyFromStr(
ctx: *mut rawmod::RedisModuleCtx,
path: *const c_char,
Expand Down
36 changes: 36 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use jsonpath_lib::select::JsonPathError;
use redis_module::RedisError;
use std::num::ParseIntError;

#[derive(Debug)]
pub struct Error {
Expand All @@ -11,6 +13,40 @@ impl From<String> for Error {
}
}

impl From<redis_module::error::GenericError> for Error {
fn from(err: redis_module::error::GenericError) -> Error {
err.to_string().into()
}
}

impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8Error) -> Error {
err.to_string().into()
}
}

impl From<ParseIntError> for Error {
fn from(err: ParseIntError) -> Error {
err.to_string().into()
}
}

impl From<redis_module::error::Error> for Error {
fn from(e: redis_module::error::Error) -> Self {
match e {
redis_module::error::Error::Generic(err) => err.into(),
redis_module::error::Error::FromUtf8(err) => err.into(),
redis_module::error::Error::ParseInt(err) => err.into(),
}
}
}

impl From<RedisError> for Error {
fn from(e: RedisError) -> Self {
Self::from(format!("ERR {}", e))
}
}

impl From<&str> for Error {
fn from(e: &str) -> Self {
Error { msg: e.to_string() }
Expand Down
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
extern crate redis_module;

use redis_module::native_types::RedisType;
use redis_module::raw::RedisModuleTypeMethods;

#[cfg(not(feature = "as-library"))]
use redis_module::Status;
#[cfg(not(feature = "as-library"))]
use redis_module::{Context, RedisResult};

#[cfg(not(feature = "as-library"))]
use crate::c_api::{
get_llapi_ctx, json_api_free_iter, json_api_get, json_api_get_at, json_api_get_boolean,
json_api_get_double, json_api_get_int, json_api_get_json, json_api_get_len,
json_api_get_string, json_api_get_type, json_api_is_json, json_api_len, json_api_next,
json_api_open_key_internal, LLAPI_CTX,
};

#[cfg(not(feature = "as-library"))]
use redis_module::Status;

#[cfg(not(feature = "as-library"))]
use redis_module::{Context, RedisResult};
use crate::redisjson::Format;

mod array_index;
mod backward;
Expand All @@ -25,7 +27,6 @@ pub mod manager;
mod nodevisitor;
pub mod redisjson;

use crate::redisjson::Format;
pub const REDIS_JSON_TYPE_VERSION: i32 = 3;

pub static REDIS_JSON_TYPE: RedisType = RedisType::new(
Expand All @@ -44,7 +45,7 @@ pub static REDIS_JSON_TYPE: RedisType = RedisType::new(
digest: None,

// Auxiliary data (v2)
aux_load: Some(redisjson::type_methods::aux_load),
aux_load: None,
aux_save: None,
aux_save_triggers: 0,

Expand All @@ -71,6 +72,7 @@ macro_rules! redis_json_module_create {(
use std::marker::PhantomData;
use std::os::raw::{c_double, c_int, c_long};
use redis_module::{raw as rawmod};
use rawmod::ModuleOptions;
use std::{
ffi::CStr,
os::raw::{c_char, c_void},
Expand Down Expand Up @@ -399,6 +401,8 @@ macro_rules! redis_json_module_create {(

fn intialize(ctx: &Context, args: &Vec<RedisString>) -> Status {
export_shared_api(ctx);
ctx.set_module_options(ModuleOptions::HANDLE_IO_ERRORS);
ctx.log_notice("Enabled diskless replication");
$init_func(ctx, args)
}

Expand Down
Loading