Fix context cancellation issue (#2212)

This commit is contained in:
Emmanuel Keller 2023-07-05 14:30:44 +01:00 committed by GitHub
parent 2b9fe88342
commit 67687496c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 20 deletions

View file

@ -79,16 +79,16 @@ impl Iterator {
// Log the statement // Log the statement
trace!("Iterating: {}", stm); trace!("Iterating: {}", stm);
// Enable context override // Enable context override
let mut run = Context::new(ctx); let mut cancel_ctx = Context::new(ctx);
self.run = run.add_cancel(); self.run = cancel_ctx.add_cancel();
// Process the query LIMIT clause // Process the query LIMIT clause
self.setup_limit(ctx, opt, stm).await?; self.setup_limit(&cancel_ctx, opt, stm).await?;
// Process the query START clause // Process the query START clause
self.setup_start(ctx, opt, stm).await?; self.setup_start(&cancel_ctx, opt, stm).await?;
// Process any EXPLAIN clause // Process any EXPLAIN clause
let explanation = self.output_explain(ctx, opt, stm)?; let explanation = self.output_explain(&cancel_ctx, opt, stm)?;
// Process prepared values // Process prepared values
self.iterate(ctx, opt, stm).await?; self.iterate(&cancel_ctx, opt, stm).await?;
// Return any document errors // Return any document errors
if let Some(e) = self.error.take() { if let Some(e) = self.error.take() {
return Err(e); return Err(e);

View file

@ -15,7 +15,6 @@ struct Prefix<'a> {
pub tb: &'a str, pub tb: &'a str,
_d: u8, _d: u8,
pub ix: &'a str, pub ix: &'a str,
_e: u8,
} }
impl<'a> Prefix<'a> { impl<'a> Prefix<'a> {
@ -30,7 +29,6 @@ impl<'a> Prefix<'a> {
tb, tb,
_d: CHAR_INDEX, _d: CHAR_INDEX,
ix, ix,
_e: b'*',
} }
} }
} }
@ -46,9 +44,7 @@ struct PrefixIds<'a> {
pub tb: &'a str, pub tb: &'a str,
_d: u8, _d: u8,
pub ix: &'a str, pub ix: &'a str,
_e: u8,
pub fd: Array, pub fd: Array,
_f: u8,
} }
impl<'a> PrefixIds<'a> { impl<'a> PrefixIds<'a> {
@ -63,9 +59,7 @@ impl<'a> PrefixIds<'a> {
tb, tb,
_d: CHAR_INDEX, _d: CHAR_INDEX,
ix, ix,
_e: b'*',
fd: fd.to_owned(), fd: fd.to_owned(),
_f: b'*',
} }
} }
} }
@ -81,9 +75,7 @@ pub struct Index<'a> {
pub tb: &'a str, pub tb: &'a str,
_d: u8, _d: u8,
pub ix: &'a str, pub ix: &'a str,
_e: u8,
pub fd: Array, pub fd: Array,
_f: u8,
pub id: Option<Id>, pub id: Option<Id>,
} }
@ -141,9 +133,7 @@ impl<'a> Index<'a> {
tb, tb,
_d: CHAR_INDEX, _d: CHAR_INDEX,
ix, ix,
_e: 0x2a, // *
fd, fd,
_f: 0x2a, // *
id, id,
} }
} }

View file

@ -898,18 +898,17 @@ async fn define_statement_index_multiple_unique_existing() -> Result<(), Error>
} }
// //
let tmp = res.remove(0).result; let tmp = res.remove(0).result;
println!("{:?}", tmp);
assert!(matches!( assert!(matches!(
tmp.err(), tmp.err(),
Some(e) if e.to_string() == r#"Database index `test` already contains ['tesla', 'test@surrealdb.com'], with record `user:4`"# Some(e) if e.to_string() == r#"Database index `test` already contains ['apple', 'test@surrealdb.com'], with record `user:3`"#
)); ));
// //
let tmp = res.remove(0).result; let tmp = res.remove(0).result;
assert!(matches!( assert!(matches!(
tmp.err(), tmp.err(),
Some(e) if e.to_string() == r#"Database index `test` already contains ['tesla', 'test@surrealdb.com'], with record `user:4`"# Some(e) if e.to_string() == r#"Database index `test` already contains ['apple', 'test@surrealdb.com'], with record `user:3`"#
)); ));
//
let tmp = res.remove(0).result?; let tmp = res.remove(0).result?;
let val = Value::parse( let val = Value::parse(
"{ "{