Skip to content
Snippets Groups Projects
Commit 1cec5bd4 authored by Егор Ивков's avatar Егор Ивков
Browse files

feature: postjoin script

parent fe02558f
No related branches found
No related tags found
1 merge request!452feature: postjoin script
Pipeline #15200 failed
...@@ -116,6 +116,15 @@ pub struct Run { ...@@ -116,6 +116,15 @@ pub struct Run {
/// the cluster. It's only accounted upon the cluster initialization /// the cluster. It's only accounted upon the cluster initialization
/// (when the first instance bootstraps), and ignored aftwerwards. /// (when the first instance bootstraps), and ignored aftwerwards.
pub init_replication_factor: u8, pub init_replication_factor: u8,
#[clap(
long,
value_name = "path",
env = "PICODATA_SCRIPT",
parse(try_from_str = try_parse_path)
)]
/// A path to a lua script that will be executed at postjoin stage
pub script: Option<String>,
} }
// Copy enum because clap:ArgEnum can't be derived for the foreign SayLevel. // Copy enum because clap:ArgEnum can't be derived for the foreign SayLevel.
......
...@@ -992,6 +992,13 @@ fn start_join(args: &args::Run, leader_address: String) { ...@@ -992,6 +992,13 @@ fn start_join(args: &args::Run, leader_address: String) {
fn postjoin(args: &args::Run, storage: Clusterwide, raft_storage: RaftSpaceAccess) { fn postjoin(args: &args::Run, storage: Clusterwide, raft_storage: RaftSpaceAccess) {
tlog!(Info, ">>>>> postjoin()"); tlog!(Info, ">>>>> postjoin()");
// Execute postjoin script if present
if let Some(ref script) = args.script {
let l = ::tarantool::lua_state();
l.exec(&format!("dofile('{script}')"))
.unwrap_or_else(|err| panic!("failed to execute postjoin script: {err}"))
}
let mut box_cfg = tarantool::cfg().unwrap(); let mut box_cfg = tarantool::cfg().unwrap();
// Reset the quorum BEFORE initializing the raft node. // Reset the quorum BEFORE initializing the raft node.
......
from conftest import Cluster
def test_script_failure(cluster: Cluster):
instance = cluster.add_instance(wait_online=False)
script = f"{cluster.data_dir}/fail.lua"
with open(script, "w") as f:
f.write("assert(false)")
instance.env["PICODATA_SCRIPT"] = script
instance.fail_to_start()
instance.terminate()
def test_script(cluster: Cluster):
instance = cluster.add_instance(wait_online=False)
script = f"{cluster.data_dir}/ok.lua"
with open(script, "w") as f:
f.write("assert(type(box.cfg) == 'table')")
instance.env["PICODATA_SCRIPT"] = script
instance.start()
instance.wait_online()
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