1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Stopped long queries, Read is_open() through TLS, Simplified answers and paging

- [server] query_time_limit (20 s by default) stops a client's query
  through SQLite's progress handler: refused with QueryTimedOut (11). A
  client closing while its query runs stops it too.
- The answer timeout in the DLL (BakaShrot_SetAnswerTimeout /
  GetAnswerTimeout, kept across connections), Python (answer_timeout)
  and C# (AnswerTimeoutMs); QueryTimedOut in every binding.
- is_open() reads what's waiting through TLS: a close_notify says
  closed, TLS's own records keep it open, unasked data or a broken
  stream close it.
- The Rust client checks an answer's type in one place (TryFrom per
  packet); Client::wait() pings while waiting (the tool's --follow).
- Pair::from(&Head), heads_after taking a Pair; simpler SyncState
  paging on both ends; the writer's redundant rollback check dropped.
- codes.rs: the bindings' error codes and copied values match Rust's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 12:17:28 +01:00
parent a6ade535d0
commit 1bae8ee182
37 changed files with 1064 additions and 264 deletions
+61 -4
View File
@@ -3,10 +3,11 @@
use bakashrot_config::Synchronous;
use bakashrot_proto::limits::{ATTACHMENT_PART_SIZE, MAX_MESSAGE_ID};
use bakashrot_proto::packets::{Attachment as Sent, ReplicatedMessage};
use bakashrot_storage::{AttachmentState, Database, Error, MAX_QUERY_ROWS, MAX_STREAMS};
use bakashrot_proto::packets::{Attachment as Sent, Pair, ReplicatedMessage};
use bakashrot_storage::{AttachmentState, Database, Error, MAX_QUERY_ROWS, MAX_STREAMS, Stop};
use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Duration, Instant};
const PART: usize = ATTACHMENT_PART_SIZE as usize;
@@ -174,9 +175,13 @@ fn pushing_and_reading() {
]
);
// In pages: after a pair (its names without case), so many at most.
let page = |after, limit| -> Vec<_> {
let page = |after: Option<(&str, &str)>, limit| -> Vec<_> {
let after = after.map(|(topic, node)| Pair {
topic: topic.into(),
node: node.into(),
});
reader
.heads_after(after, limit)
.heads_after(after.as_ref(), limit)
.unwrap()
.into_iter()
.map(|h| (h.topic, h.node))
@@ -754,6 +759,58 @@ fn queries() {
);
}
#[test]
fn queries_are_stopped() {
let (database, _) = open("stopped-queries");
let _writer = database.writer().unwrap();
let runner = database.query_runner().unwrap();
let forever =
"WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n) SELECT count(*) FROM n";
let refused = |result: bakashrot_storage::Result<String>| match result {
Err(Error::Query(why)) => why,
other => panic!("{other:?}"),
};
// Past its time limit.
let started = Instant::now();
let why = match runner.run_limited(forever, Duration::from_millis(200), &Stop::new()) {
Err(Error::QueryTimedOut(why)) => why,
other => panic!("{other:?}"),
};
let took = started.elapsed();
assert!(why.contains("200ms, the server's time limit"), "{why}");
assert!(
took >= Duration::from_millis(200) && took < Duration::from_secs(5),
"{took:?}"
);
// From another thread, long before its time limit.
let stop = Stop::new();
let stopping = stop.clone();
let started = Instant::now();
let thread = std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(100));
stopping.stop();
});
let why = refused(runner.run_limited(forever, Duration::from_secs(3600), &stop));
thread.join().unwrap();
assert_eq!(why, "stopped while it ran");
assert!(started.elapsed() < Duration::from_secs(5));
// Stopped before it starts: at its first look.
refused(runner.run_limited(forever, Duration::from_secs(3600), &stop));
// The next queries aren't: the connection is as before.
let short = "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 100000) SELECT count(*) FROM n";
let counted = r#"{"columns":["count(*)"],"rows":[["100000"]]}"#;
assert_eq!(
runner
.run_limited(short, Duration::from_secs(60), &Stop::new())
.unwrap(),
counted
);
assert_eq!(runner.run(short).unwrap(), counted);
}
#[test]
fn the_view_reads_by_key_range() {
let (database, path) = open("plans");