Skip to content
Snippets Groups Projects
Verified Commit 1befa37f authored by Denis Smirnov's avatar Denis Smirnov
Browse files

fix: trasaction already started error

Remove redundant transaction start from the open telemetry's spans
in the code. There is no sense in it at the moment (seems like it
was added while prototyping tarantool space as a storage for the
per-fiber traces... but we gave this idea up and switched to the
custom Rust implementation). But if we start a transaction manually
and call sbroad execute() method, we end up with transaction already
started error. So, remove the transaction start wrappers and make
nested transactions work.
parent c2770b9a
No related branches found
No related tags found
1 merge request!1414sbroad import
...@@ -35,7 +35,6 @@ mod prod_imports { ...@@ -35,7 +35,6 @@ mod prod_imports {
pub use crate::otm::fiber::fiber_id; pub use crate::otm::fiber::fiber_id;
pub use crate::warn; pub use crate::warn;
pub use tarantool::error::Error as TntError; pub use tarantool::error::Error as TntError;
pub use tarantool::transaction::start_transaction;
} }
#[cfg(not(feature = "mock"))] #[cfg(not(feature = "mock"))]
...@@ -168,14 +167,11 @@ where ...@@ -168,14 +167,11 @@ where
{ {
let fid = fiber_id(); let fid = fiber_id();
let id = current_id(); let id = current_id();
let old_ti = start_transaction(|| -> Result<TraceInfo, TntError> { let old_ti = TRACE_MANAGER.with(|tm| {
Ok(TRACE_MANAGER.with(|tm| { tm.borrow_mut()
tm.borrow_mut() .remove(fid)
.remove(fid) .map_or(TraceInfo::empty(), |ti| ti)
.map_or(TraceInfo::empty(), |ti| ti) });
}))
})
.unwrap();
let ctx = build_ctx( let ctx = build_ctx(
old_ti.tracer(), old_ti.tracer(),
SpanBuilder::from_name(name) SpanBuilder::from_name(name)
...@@ -184,53 +180,46 @@ where ...@@ -184,53 +180,46 @@ where
old_ti.context(), old_ti.context(),
); );
let ti = TraceInfo::new(old_ti.tracer().clone(), ctx, id); let ti = TraceInfo::new(old_ti.tracer().clone(), ctx, id);
start_transaction(|| -> Result<(), TntError> { TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() {
TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() { Ok(mut mut_tm) => {
Ok(mut mut_tm) => { debug!(
debug!( Option::from("child span"),
Option::from("child span"), &format!(
&format!( "fiber {}, child span {}: insert trace info {:?}",
"fiber {}, child span {}: insert trace info {:?}", fid, name, ti
fid, name, ti ),
), );
); mut_tm.insert(fid, ti);
mut_tm.insert(fid, ti); }
} Err(_e) => {
Err(_e) => { warn!(
warn!( Option::from("query span"),
Option::from("query span"), &format!(
&format!(
"fiber {}, child span {}: failed to insert trace info {:?}, error: {:?}", "fiber {}, child span {}: failed to insert trace info {:?}, error: {:?}",
fid, name, ti, _e fid, name, ti, _e
), ),
); );
} }
}); });
Ok(())
})
.unwrap();
let result = f(); let result = f();
start_transaction(|| -> Result<(), TntError> { TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() {
TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() { Ok(mut mut_tm) => {
Ok(mut mut_tm) => { debug!(
debug!( Option::from("child span"),
Option::from("child span"), &format!("fiber {}, child span {}: restore old trace info {:?}", fid, name, old_ti),
&format!("fiber {}, child span {}: restore old trace info {:?}", fid, name, old_ti), );
); mut_tm.insert(fid, old_ti);
mut_tm.insert(fid, old_ti); }
} Err(_e) => {
Err(_e) => { warn!(
warn!( Option::from("query span"),
Option::from("query span"), &format!(
&format!( "fiber {}, child span {}: failed to restore old trace info {:?}, error: {:?}",
"fiber {}, child span {}: failed to restore old trace info {:?}, error: {:?}", fid, name, old_ti, _e
fid, name, old_ti, _e ),
), );
); }
} });
});
Ok(())
}).unwrap();
return result; return result;
} }
f() f()
...@@ -273,53 +262,46 @@ where ...@@ -273,53 +262,46 @@ where
); );
let ti = TraceInfo::new(tracer.clone(), ctx, id.to_string()); let ti = TraceInfo::new(tracer.clone(), ctx, id.to_string());
start_transaction(|| -> Result<(), TntError> { TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() {
TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() { Ok(mut mut_tm) => {
Ok(mut mut_tm) => { debug!(
debug!( Option::from("query span"),
Option::from("query span"), &format!(
&format!( "fiber {}, query span {}: insert trace info {:?}",
"fiber {}, query span {}: insert trace info {:?}", fid, name, ti
fid, name, ti ),
), );
); mut_tm.insert(fid, ti);
mut_tm.insert(fid, ti); }
} Err(_e) => {
Err(_e) => { warn!(
warn!( Option::from("query span"),
Option::from("query span"), &format!(
&format!( "fiber {}, query span {}: failed to insert trace info {:?}, error: {:?}",
"fiber {}, query span {}: failed to insert trace info {:?}, error: {:?}", fid, name, ti, _e
fid, name, ti, _e ),
), );
); }
} });
});
Ok(())
}).unwrap();
let result = f(); let result = f();
start_transaction(|| -> Result<(), TntError> { TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() {
TRACE_MANAGER.with(|tm| match tm.try_borrow_mut() { Ok(mut mut_tm) => {
Ok(mut mut_tm) => { debug!(
debug!( Option::from("query span"),
Option::from("query span"), &format!("fiber {}, query span {}: remove trace info", fid, name),
&format!("fiber {}, query span {}: remove trace info", fid, name), );
); mut_tm.remove(fid);
mut_tm.remove(fid); }
} Err(_e) => {
Err(_e) => { warn!(
warn!( Option::from("query span"),
Option::from("query span"), &format!(
&format!( "fiber {}, query span {}: failed to remove trace info, error: {:?}",
"fiber {}, query span {}: failed to remove trace info, error: {:?}", fid, name, _e
fid, name, _e ),
), );
); }
} });
});
Ok(())
})
.unwrap();
return result; return result;
} }
f() f()
......
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