Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI on 1.1 #2923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions benchmarks/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
Expand Down
6 changes: 5 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ unsound = "deny"
# output a note when they are encountered.
ignore = [
# Unmaintained dependency error that needs more attention due to nested dependencies
"RUSTSEC-2024-0370"
"RUSTSEC-2024-0370",
"RUSTSEC-2024-0384",
"RUSTSEC-2024-0388",
"RUSTSEC-2024-0421",
]
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
# lower than the range specified will be ignored. Note that ignored advisories
Expand Down Expand Up @@ -84,6 +87,7 @@ allow = [
"BSD-2-Clause",
"BSD-3-Clause",
"Unicode-DFS-2016",
"Unicode-3.0",
"ISC",
"OpenSSL"
]
Expand Down
4 changes: 1 addition & 3 deletions glide-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

#[cfg(feature = "socket-layer")]
fn build_protobuf() {
Expand Down
6 changes: 5 additions & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ name = "glide"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "^0.20", features = ["extension-module", "num-bigint"] }
pyo3 = { version = "^0.22", features = [
"extension-module",
"num-bigint",
"gil-refs",
] }
bytes = { version = "1.6.0" }
redis = { path = "../submodules/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager","tokio-rustls-comp"] }
glide-core = { path = "../glide-core", features = ["socket-layer"] }
Expand Down
4 changes: 2 additions & 2 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9691,7 +9691,7 @@ async def cluster_route_custom_command_slot_route(
route_class = SlotKeyRoute if is_slot_key else SlotIdRoute
route_second_arg = "foo" if is_slot_key else 4000
primary_res = await glide_client.custom_command(
["CLUSTER", "NODES"], route_class(SlotType.PRIMARY, route_second_arg)
["CLUSTER", "NODES"], route_class(SlotType.PRIMARY, route_second_arg) # type: ignore
)
assert isinstance(primary_res, bytes)
primary_res = primary_res.decode()
Expand All @@ -9704,7 +9704,7 @@ async def cluster_route_custom_command_slot_route(
expected_primary_node_id = node_line.split(" ")[0]

replica_res = await glide_client.custom_command(
["CLUSTER", "NODES"], route_class(SlotType.REPLICA, route_second_arg)
["CLUSTER", "NODES"], route_class(SlotType.REPLICA, route_second_arg) # type: ignore
)
assert isinstance(replica_res, bytes)
replica_res = replica_res.decode()
Expand Down
88 changes: 50 additions & 38 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

use bytes::Bytes;
use glide_core::client::FINISHED_SCAN_CURSOR;
/**
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/
use glide_core::start_socket_listener;
use glide_core::MAX_REQUEST_ARGS_LENGTH;
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::types::{PyAny, PyBool, PyBytes, PyDict, PyFloat, PyList, PySet};
use pyo3::Python;
use redis::Value;
use std::sync::Arc;

pub const DEFAULT_TIMEOUT_IN_MILLISECONDS: u32 =
glide_core::client::DEFAULT_RESPONSE_TIMEOUT.as_millis() as u32;
pub const MAX_REQUEST_ARGS_LEN: u32 = MAX_REQUEST_ARGS_LENGTH as u32;

#[pyclass]
#[pyclass(eq, eq_int)]
#[derive(PartialEq, Eq, PartialOrd, Clone)]
pub enum Level {
Error = 0,
Expand Down Expand Up @@ -47,6 +47,7 @@ pub struct ClusterScanCursor {
#[pymethods]
impl ClusterScanCursor {
#[new]
#[pyo3(signature = (new_cursor=None))]
fn new(new_cursor: Option<String>) -> Self {
match new_cursor {
Some(cursor) => ClusterScanCursor { cursor },
Expand Down Expand Up @@ -77,10 +78,10 @@ pub struct Script {
#[pymethods]
impl Script {
#[new]
fn new(code: &PyAny) -> PyResult<Self> {
fn new(code: &Bound<PyAny>) -> PyResult<Self> {
let hash = if let Ok(code_str) = code.extract::<String>() {
glide_core::scripts_container::add_script(code_str.as_bytes())
} else if let Ok(code_bytes) = code.extract::<&PyBytes>() {
} else if let Ok(code_bytes) = code.extract::<Bound<PyBytes>>() {
glide_core::scripts_container::add_script(code_bytes.as_bytes())
} else {
return Err(PyTypeError::new_err(
Expand All @@ -102,7 +103,7 @@ impl Script {

/// A Python module implemented in Rust.
#[pymodule]
fn glide(_py: Python, m: &PyModule) -> PyResult<()> {
fn glide(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<Level>()?;
m.add_class::<Script>()?;
m.add_class::<ClusterScanCursor>()?;
Expand All @@ -111,30 +112,41 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> {
DEFAULT_TIMEOUT_IN_MILLISECONDS,
)?;
m.add("MAX_REQUEST_ARGS_LEN", MAX_REQUEST_ARGS_LEN)?;
m.add_function(wrap_pyfunction!(py_log, m)?)?;
m.add_function(wrap_pyfunction!(py_init, m)?)?;
m.add_function(wrap_pyfunction!(start_socket_listener_external, m)?)?;
m.add_function(wrap_pyfunction!(value_from_pointer, m)?)?;
m.add_function(wrap_pyfunction!(create_leaked_value, m)?)?;
m.add_function(wrap_pyfunction!(create_leaked_bytes_vec, m)?)?;

#[pyfn(m)]
#[pyfunction]
fn py_log(log_level: Level, log_identifier: String, message: String) {
log(log_level, log_identifier, message);
}

#[pyfn(m)]
#[pyfunction]
#[pyo3(signature = (level=None, file_name=None))]
fn py_init(level: Option<Level>, file_name: Option<&str>) -> Level {
init(level, file_name)
}

#[pyfn(m)]
#[pyfunction]
fn start_socket_listener_external(init_callback: PyObject) -> PyResult<PyObject> {
start_socket_listener(move |socket_path| {
Python::with_gil(|py| {
match socket_path {
Ok(path) => {
let _ = init_callback.call(py, (path, py.None()), None);
}
Err(error_message) => {
let _ = init_callback.call(py, (py.None(), error_message), None);
}
};
});
let init_callback = Arc::new(init_callback);
start_socket_listener({
let init_callback = Arc::clone(&init_callback);
move |socket_path| {
let init_callback = Arc::clone(&init_callback);
Python::with_gil(|py| {
match socket_path {
Ok(path) => {
let _ = init_callback.call_bound(py, (path, py.None()), None);
}
Err(error_message) => {
let _ = init_callback.call_bound(py, (py.None(), error_message), None);
}
};
});
}
});
Ok(Python::with_gil(|py| "OK".into_py(py)))
}
Expand All @@ -159,28 +171,28 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> {
match val {
Value::Nil => Ok(py.None()),
Value::SimpleString(str) => {
let data_bytes = PyBytes::new(py, str.as_bytes());
let data_bytes = PyBytes::new_bound(py, str.as_bytes());
Ok(data_bytes.into_py(py))
}
Value::Okay => Ok("OK".into_py(py)),
Value::Int(num) => Ok(num.into_py(py)),
Value::BulkString(data) => {
let data_bytes = PyBytes::new(py, &data);
let data_bytes = PyBytes::new_bound(py, &data);
Ok(data_bytes.into_py(py))
}
Value::Array(bulk) => {
let elements: &PyList = PyList::new(py, iter_to_value(py, bulk)?);
let elements: Bound<PyList> = PyList::new_bound(py, iter_to_value(py, bulk)?);
Ok(elements.into_py(py))
}
Value::Map(map) => {
let dict = PyDict::new(py);
let dict = PyDict::new_bound(py);
for (key, value) in map {
dict.set_item(resp_value_to_py(py, key)?, resp_value_to_py(py, value)?)?;
}
Ok(dict.into_py(py))
}
Value::Attribute { data, attributes } => {
let dict = PyDict::new(py);
let dict = PyDict::new_bound(py);
let value = resp_value_to_py(py, *data)?;
let attributes = resp_value_to_py(py, Value::Map(attributes))?;
dict.set_item("value", value)?;
Expand All @@ -189,43 +201,43 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> {
}
Value::Set(set) => {
let set = iter_to_value(py, set)?;
let set = PySet::new(py, set.iter())?;
let set = PySet::new_bound(py, set.iter())?;
Ok(set.into_py(py))
}
Value::Double(double) => Ok(PyFloat::new(py, double).into_py(py)),
Value::Boolean(boolean) => Ok(PyBool::new(py, boolean).into_py(py)),
Value::Double(double) => Ok(PyFloat::new_bound(py, double).into_py(py)),
Value::Boolean(boolean) => Ok(PyBool::new_bound(py, boolean).into_py(py)),
Value::VerbatimString { format: _, text } => {
// TODO create MATCH on the format
let data_bytes = PyBytes::new(py, text.as_bytes());
let data_bytes = PyBytes::new_bound(py, text.as_bytes());
Ok(data_bytes.into_py(py))
}
Value::BigNumber(bigint) => Ok(bigint.into_py(py)),
Value::Push { kind, data } => {
let dict = PyDict::new(py);
let dict = PyDict::new_bound(py);
dict.set_item("kind", format!("{kind:?}"))?;
let values: &PyList = PyList::new(py, iter_to_value(py, data)?);
let values: Bound<PyList> = PyList::new_bound(py, iter_to_value(py, data)?);
dict.set_item("values", values)?;
Ok(dict.into_py(py))
}
}
}

#[pyfn(m)]
#[pyfunction]
pub fn value_from_pointer(py: Python, pointer: u64) -> PyResult<PyObject> {
let value = unsafe { Box::from_raw(pointer as *mut Value) };
resp_value_to_py(py, *value)
}

#[pyfn(m)]
#[pyfunction]
/// This function is for tests that require a value allocated on the heap.
/// Should NOT be used in production.
pub fn create_leaked_value(message: String) -> usize {
let value = Value::SimpleString(message);
Box::leak(Box::new(value)) as *mut Value as usize
}

#[pyfn(m)]
pub fn create_leaked_bytes_vec(args_vec: Vec<&PyBytes>) -> usize {
#[pyfunction]
pub fn create_leaked_bytes_vec(args_vec: Vec<Bound<PyBytes>>) -> usize {
// Convert the bytes vec -> Bytes vector
let bytes_vec: Vec<Bytes> = args_vec
.iter()
Expand All @@ -238,7 +250,6 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> {
}
Ok(())
}

impl From<logger_core::Level> for Level {
fn from(level: logger_core::Level) -> Self {
match level {
Expand Down Expand Up @@ -269,6 +280,7 @@ pub fn log(log_level: Level, log_identifier: String, message: String) {
}

#[pyfunction]
#[pyo3(signature = (level=None, file_name=None))]
pub fn init(level: Option<Level>, file_name: Option<&str>) -> Level {
let logger_level = logger_core::init(level.map(|level| level.into()), file_name);
logger_level.into()
Expand Down
Loading