Skip to content
Snippets Groups Projects
Commit 9fb8856b authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

test: pico.raft_propose_mp function for arbitrary ops via msgpack

parent 63a89760
No related branches found
No related tags found
1 merge request!516OpDdl create space
......@@ -7,6 +7,7 @@ use ::tarantool::fiber::r#async::timeout;
use ::tarantool::fiber::r#async::timeout::IntoTimeout as _;
use ::tarantool::tlua;
use ::tarantool::transaction::start_transaction;
use ::tarantool::tuple::Decode;
use std::convert::TryFrom;
use std::time::{Duration, Instant};
use storage::Clusterwide;
......@@ -124,6 +125,26 @@ fn picolib_setup(args: &args::Run) {
traft::node::global()?.propose_and_wait(Op::Nop, Duration::from_secs(1))
}),
);
luamod.set(
"raft_propose",
tlua::function1(|lua: tlua::LuaState| -> traft::Result<()> {
use tlua::{AnyLuaString, AsLua, LuaError, LuaTable};
let lua = unsafe { tlua::Lua::from_static(lua) };
let t: LuaTable<_> = AsLua::read(&lua).map_err(|(_, e)| LuaError::from(e))?;
let mp: AnyLuaString = lua
.eval_with("return require 'msgpack'.encode(...)", &t)
.map_err(LuaError::from)?;
let op: Op = Decode::decode(mp.as_bytes())?;
traft::node::global()?.propose_and_wait(op, Duration::from_secs(1))
}),
);
luamod.set(
"raft_propose_mp",
tlua::function1(|op: tlua::AnyLuaString| -> traft::Result<()> {
let op: Op = Decode::decode(op.as_bytes())?;
traft::node::global()?.propose_and_wait(op, Duration::from_secs(1))
}),
);
luamod.set(
"raft_timeout_now",
tlua::function0(|| -> traft::Result<()> {
......@@ -154,6 +175,25 @@ fn picolib_setup(args: &args::Run) {
);
// TODO: remove this
if cfg!(debug_assertions) {
use ::tarantool::index::IteratorType;
use ::tarantool::space::Space;
use ::tarantool::tuple::Tuple;
luamod.set(
"prop",
tlua::Function::new(|property: Option<String>| -> traft::Result<Vec<Tuple>> {
if let Some(property) = property {
let _ = property;
todo!();
}
let space = Space::find("_picodata_property").expect("always defined");
let iter = space.select(IteratorType::All, &())?;
let mut res = vec![];
for t in iter {
res.push(t);
}
Ok(res)
}),
);
luamod.set(
"emit",
tlua::Function::new(|event: String| -> traft::Result<()> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment