cli/sync_server.mdx
You will be provided with a prompt which is used to generate simple implementation of the server.
Your task is to extract protocol implementation from this prompt and compose a documentation with PROTOCOL description:
- Document endpoint which MUST be implemented to implement sync engine protocol
- Document sql over http protocol which is used for `/v2/pipeline` endpoint
- Document `/pull-updates` endpoint
- The documentation MUST ONLY mention contracts, logic and flow. No code should be mentioned
Structure documentation well and Use Mintlify rich formatting tools in order to make documentation easy to read and navigatable:
* Give high level overview of sync protocol and its main components in the beginning
* This is protocol to support bidirectional of sqlite-compatible database between server and client
* Describe /v2/pipeline endpoint
* List contract spec
* Describe /pull-updates endpoint
* Use mintlify components if appropriate
* ```....``` code blocks to emit contracts like protobuf schemas
* Callouts (`<Info>`, `<Warning>`, etc) to extract portion of information into separate block visible to the reader
* Use markdown markup features if appropriate
* Headers and subheaders for structuring the docs and automatically build table of content by Mintlify
* Text emphasis (bold, italic) to highlight important words
<Output ref="prompt" />
Generate simple implementation of sync server using tursodatabase - rewrite of the SQLite. The implementation must maintain turso database file locally at given path and disable checkpoint for it.
use anyhow::Result;
// ... more imports here ...
pub struct TursoSyncServer {
// listen address (e.g. 0.0.0.0:8080)
address: String,
conn: Arc<Mutex<Arc<Connection>>>,
// stop server if interrupt_count > 0 (do this check in the main server event loop)
interrupt_count: Arc<AtomicUsize>,
}
impl TursoSyncServer {
pub fn new(address: String, conn: Arc<Connection>, interrupt_count: Arc<AtomicUsize>) -> Self {
Self {
address,
conn: Arc::new(Mutex::new(conn)),
interrupt_count,
}
}
pub fn run(&self) -> Result<()> {
// implement logic here
}
fn sql_over_http(&self, query: ...) -> Result<()> { ... }
fn pull_updates(&self, query: ...) -> Result<()> { ... }
}
<T as prost::Message>::decode(...) to access methods associated with the trait prost::Messagefrom_i32 method in prost is deprecated
use of deprecated associated function turso_sync_engine::server_proto::PageUpdatesEncodingReq::from_i32: Use the TryFrom<i32> implementation insteadinterrupt_count because otherwise server will be blocked at syscall and will be unable to shutdownrun_collect_rows/run_ignore_rows helpers to execute Statementapplication/protobuf as content type for protobuf payloads/v2/pipeline or /pull-updates) in order to provide simple and safe concurrency guarantees
let conn = { self.conn.lock().unwrap().clone() }; // this is wrong!
Sync server must support 2 endpoints:
PullUpdatesRequest protobuf message and respond with sequence of length-delimited messagesPullUpdatesResponseHeaderPullUpdatesPageDataserver_query_selector fieldserver_pages_selector and send only pages from the selector if it is setThe contracts which client uses to interact with server (protobufs and JSONs) are listed here: <File path="../sync/engine/src/server_proto.rs" />
The main database API is in the lib.rs: <Outline model="openai/gpt-4.1" id="api">
wal_state and wal_get_framewal_get_frame reads the frame from the WAL which has additional 24 bytes header with extra meta
Currently available dependencies are: <File path="Cargo.toml" />
</Text>