Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

rename sqld to libsql-server #694

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-images.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create and publish sqld binaried and Docker image
name: Create and publish libsql-server binaried and Docker image

on:
pull_request:
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create and publish sqld binaried and Docker image
name: Create and publish libsql-server binaried and Docker image

on:
push:
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -159,7 +159,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
repository: "libsql/homebrew-sqld"
repository: "libsql/homebrew-libsql"
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
# So we have access to the formula
- name: Fetch local artifacts
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ jobs:
submodules: recursive
- name: Test openssl
shell: bash {0}
run: cargo tree -p sqld -i openssl; [ $? = 101 ]
run: cargo tree -p libsql-server -i openssl; [ $? = 101 ]

docker:
runs-on: ubuntu-latest
@@ -126,4 +126,4 @@ jobs:
uses: docker/build-push-action@v3
with:
context: .
tags: sqld:unstable
tags: libsql-server:unstable
180 changes: 90 additions & 90 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
members = [
"bottomless",
"bottomless-cli",
"sqld",
"sqld-libsql-bindings",
"libsql-server",
"libsql-bindings",
"testing/end-to-end",
]

18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# build sqld
# build libsql-server
FROM rust:slim-bullseye AS chef
RUN apt update \
&& apt install -y libclang-dev clang \
@@ -23,18 +23,18 @@ FROM chef AS builder
COPY --from=planner /recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build -p sqld --release
RUN cargo build -p libsql-server --release

# runtime
FROM debian:bullseye-slim
COPY --from=builder /target/release/sqld /bin/sqld
RUN groupadd --system --gid 666 sqld
RUN adduser --system --home /var/lib/sqld --uid 666 --gid 666 sqld
COPY --from=builder /target/release/libsql-server /bin/libsql-server
RUN groupadd --system --gid 666 libsql-server
RUN adduser --system --home /var/lib/libsql-server --uid 666 --gid 666 libsql-server
RUN apt-get update && apt-get install -y ca-certificates
COPY docker-entrypoint.sh /usr/local/bin
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
VOLUME [ "/var/lib/sqld" ]
WORKDIR /var/lib/sqld
USER sqld
VOLUME [ "/var/lib/libsql-server" ]
WORKDIR /var/lib/libsql-server
USER libsql-server
EXPOSE 5001 8080
CMD ["/bin/sqld"]
CMD ["/bin/libsql-server"]
24 changes: 12 additions & 12 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# build sqld
# build libsql-server
FROM rust:slim-bullseye as builder
RUN apt update

@@ -9,31 +9,31 @@ RUN apt install -y libclang-dev clang \
RUN apt clean
RUN update-ca-certificates

WORKDIR /sqld
WORKDIR /libsql-server
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/sqld/target \
cargo build -p sqld --release && \
cp target/release/sqld /sqld/bin
--mount=type=cache,target=/libsql-server/target \
cargo build -p libsql-server --release && \
cp target/release/libsql-server /libsql-server/bin


# runtime
FROM debian:bullseye-slim
RUN apt update

COPY --from=builder /sqld/bin /bin/sqld
COPY --from=builder /libsql-server/bin /bin/libsql-server
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY docker-entrypoint.sh /usr/local/bin

VOLUME [ "/var/lib/sqld" ]
VOLUME [ "/var/lib/libsql-server" ]

RUN groupadd --system --gid 666 sqld
RUN adduser --system --home /var/lib/sqld --uid 666 --gid 666 sqld
USER sqld
WORKDIR /var/lib/sqld
RUN groupadd --system --gid 666 libsql-server
RUN adduser --system --home /var/lib/libsql-server --uid 666 --gid 666 libsql-server
USER libsql-server
WORKDIR /var/lib/libsql-server

EXPOSE 5001 8080

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["/bin/sqld"]
CMD ["/bin/libsql-server"]
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright 2023 the sqld authors
Copyright 2023 the libsql-server authors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# `sqld` - a server mode for libSQL
# `Libsql-server` - a server mode for libSQL

The `sqld` ("SQL daemon") project is a server mode for
The `libsql-server` project is a server mode for
[libSQL](https://github.com/libsql/libsql/).

Embedded SQL databases such as libSQL and SQLite are great for a lot of use
cases, but sometimes you really do want to consume your database as a server.
For example, with apps running on serverless infrastructure, fitting a database
engine might be difficult given the limited size of the hardware. And even when
it's _possible_, it might be really inconvenient. We created `sqld` for this use
it's _possible_, it might be really inconvenient. We created `libsql-server` for this use
case.

## Features
@@ -21,12 +21,12 @@ case.

## Build and run

Follow the [instructions](./docs/BUILD-RUN.md) to build and run `sqld`
Follow the [instructions](./docs/BUILD-RUN.md) to build and run `libsql-server`
using Homebrew, Docker, or your own Rust toolchain.

## Client libraries

The following client libraries enable your app to query `sqld` programmatically:
The following client libraries enable your app to query `libsql-server` programmatically:

* [TypeScript and JavaScript](https://github.com/libsql/libsql-client-ts)
* [Rust](https://github.com/libsql/libsql-client-rs)
@@ -60,16 +60,16 @@ extension directory

## Integration with S3 bottomless replication

`sqld` is integrated with [bottomless replication subproject]. With bottomless
`libsql-server` is integrated with [bottomless replication subproject]. With bottomless
replication, the database state is continuously backed up to S3-compatible
storage. Each backup session is called a "generation" and consists of the main
database file snapshot and replicates [SQLite WAL] pages.

In order to enable automatic replication to S3 storage, compile `sqld` with `-F bottomless` flag
and run `sqld` with `--enable-bottomless-replication` parameter:
In order to enable automatic replication to S3 storage, compile `libsql-server` with `-F bottomless` flag
and run `libsql-server` with `--enable-bottomless-replication` parameter:

```bash
sqld --http-listen-addr=127.0.0.1:8000 --enable-bottomless-replication
libsql-server --http-listen-addr=127.0.0.1:8000 --enable-bottomless-replication
```

[bottomless replication subproject]: ./bottomless
@@ -110,4 +110,4 @@ This project is licensed under the MIT license.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `sqld` by you, shall be licensed as MIT, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `libsql-server` by you, shall be licensed as MIT, without any additional terms or conditions.
2 changes: 1 addition & 1 deletion bottomless/Cargo.toml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ aws-sdk-s3 = { version = "0.28" }
bytes = "1"
crc = "3.0.0"
futures = { version = "0.3.25" }
sqld-libsql-bindings = { version = "0", path = "../sqld-libsql-bindings" }
libsql-bindings = { version = "0", path = "../libsql-bindings" }
tokio = { version = "1.22.2", features = ["rt-multi-thread", "net", "io-std", "io-util", "time", "macros", "sync", "fs"] }
tokio-util = "0.7"
tracing = "0.1.37"
2 changes: 1 addition & 1 deletion bottomless/src/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use sqld_libsql_bindings::ffi::{
pub use libsql_bindings::ffi::{
libsql_wal_methods, sqlite3, sqlite3_file, sqlite3_vfs, PageHdrIter, PgHdr, Wal, WalIndexHdr,
SQLITE_CANTOPEN, SQLITE_CHECKPOINT_TRUNCATE, SQLITE_IOERR_WRITE, SQLITE_OK,
};
110 changes: 54 additions & 56 deletions docs/BUILD-RUN.md
Original file line number Diff line number Diff line change
@@ -1,158 +1,158 @@
# Build and run sqld
# Build and run libsql-server

There are four ways to build and run sqld:
There are four ways to build and run libsql-server:

- [Download a prebuilt binary](#download-a-prebuilt-binary)
- [Using Homebrew](#build-and-install-with-homebrew)
- [Using a prebuilt Docker image](#using-a-prebuilt-docker-image)
- [From source using Docker/Podman](#build-from-source-using-docker--podman)
- [From source using Rust](#build-from-source-using-rust)

## Running sqld
## Running libsql-server

You can simply run launch the executable with no command line arguments to run
an instance of sqld. By default, sqld listens on 127.0.0.1 port 8080 and
an instance of libsql-server. By default, libsql-server listens on 127.0.0.1 port 8080 and
persists database data in a directory `./data.sqld`.

Use the `--help` flag to discover how to change its runtime behavior.

## Query sqld
## Query libsql-server

You can query sqld using one of the provided [client
You can query libsql-server using one of the provided [client
libraries](../#client-libraries).

You can also use the sqlite3 CLI to query the SQLite 3 compatible database file
managed by sqld.
managed by libsql-server.

```bash
sqlite3 ./data.sqld/data
```

Be sure to stop sqld before using `sqlite3` like this.
Be sure to stop libsql-server before using `sqlite3` like this.

## Download a prebuilt binary

The [sqld releases page] for this repository lists released versions of sqld
The [libsql-server releases page] for this repository lists released versions of libsql-server
along with downloads for macOS and Linux.

## Build and install with Homebrew

The sqld formulae for Homebrew works with macOS, Linux (including WSL).
The libsql-server formulae for Homebrew works with macOS, Linux (including WSL).

### 1. Add the tap `libsql/sqld` to Homebrew
### 1. Add the tap `libsql/libsql-server` to Homebrew

```bash
brew tap libsql/sqld
brew tap libsql/libsql-server
```

### 2. Install the formulae `sqld`
### 2. Install the formulae `libsql-server`

```bash
brew install sqld
brew install libsql-server
```

This builds and installs the binary `sqld` into `$HOMEBREW_PREFIX/bin/sqld`,
This builds and installs the binary `libsql-server` into `$HOMEBREW_PREFIX/bin/libsql-server`,
which should be in your PATH.

### 3. Verify that `sqld` works
### 3. Verify that `libsql-server` works

```bash
sqld --help
libsql-server --help
```

## Using a prebuilt Docker image

The sqld release process publishes a Docker image to the GitHub Container
Registry. The URL is https://ghcr.io/libsql/sqld. You can run the latest image locally
The libsql-server release process publishes a Docker image to the GitHub Container
Registry. The URL is https://ghcr.io/libsql/libsql-server. You can run the latest image locally
on port 8080 with the following:

```bash
docker run -p 8080:8080 -d ghcr.io/libsql/sqld:latest
docker run -p 8080:8080 -d ghcr.io/libsql/libsql-server:latest
```

Or you can run a specific version using one of the [sqld container release
Or you can run a specific version using one of the [libsql-server container release
tags] in the following form for version X.Y.Z:

```bash
docker run -p 8080:8080 -d ghcr.io/libsql/sqld:vX.Y.Z
docker run -p 8080:8080 -d ghcr.io/libsql/libsql-server:vX.Y.Z
```

## Build from source using Docker / Podman

To build sqld with Docker, you must have a Docker [installed] and running on
To build libsql-server with Docker, you must have a Docker [installed] and running on
your machine with its CLI in your shell PATH.

[installed]: https://docs.docker.com/get-docker/

### 1. Clone this repo

Clone this repo using your preferred mechanism. You may want to use one of the
[sqld release tags].
[libsql-server release tags].

Change to the `sqld` directory.
Change to the `libsql-server` directory.

### 2. Build with Docker

Run the following to build a Docker image named "libsql/sqld" tagged with
Run the following to build a Docker image named "libsql/libsql-server" tagged with
version "latest".

```bash
docker build -t libsql/sqld:latest .
docker build -t libsql/libsql-server:latest .
```

### 3. Verify the build

Check that sqld built successfully using its --help flag:
Check that libsql-server built successfully using its --help flag:

```bash
docker container run \
--rm \
-i \
libsql/sqld \
/bin/sqld --help
libsql/libsql-server \
/bin/libsql-server --help
```

### 4. Create a data volume

The following will create a volume named `sqld-data` that sqld uses to persist
The following will create a volume named `libsql-data` that libsql-server uses to persist
database files.

```bash
docker volume create sqld-data
docker volume create libsql-data
```

### 5. Run sqld in a container
### 5. Run libsql-server in a container

The following uses the built image to create and run a new container named
`sqld`, attaching the `sqld-data` volume to it, and exposing its port 8080
`libsql-server`, attaching the `libsql-data` volume to it, and exposing its port 8080
locally:

```bash
docker container run \
-d \
--name sqld \
-v sqld-data:/var/lib/sqld \
--name libsql-server \
-v libsql-data:/var/lib/libsql-server\
-p 127.0.0.1:8080:8080 \
libsql/sqld:latest
libsql/libsql-server:latest
```

8080 is the default port for the sqld HTTP service that handles client queries.
8080 is the default port for the libsql-server HTTP service that handles client queries.
With this container running, you can use the URL `http://127.0.0.1:8080` or
`ws://127.0.0.1:8080` to configure one of the libSQL client SDKs for local
development.

### 6. Configure sqld with environment variables
### 6. Configure libsql-server with environment variables

In the sqld output using `--help` from step 3, you saw the names of command line
In the libsql-server output using `--help` from step 3, you saw the names of command line
flags along with the names of environment variables (look for "env:") used to
configure the way sqld works.
configure the way libsql-server works.

## Build from source using Rust

To build from source, you must have a Rust development environment installed and
available in your PATH.

Currently we only support building sqld on macOS and Linux (including WSL). We
Currently we only support building libsql-server on macOS and Linux (including WSL). We
are working native Windows build instructions.

### 1. Setup
@@ -166,9 +166,9 @@ Install dependencies:
### 2. Clone this repo

Clone this repo using your preferred mechanism. You may want to use one of the
[sqld release tags].
[libsql-server release tags].

Change to the `sqld` directory.
Change to the `libsql-server` directory.

Install git submodules:

@@ -182,28 +182,28 @@ git submodule update --init --force --recursive --depth 1
cargo build
```

The sqld binary will be in `./target/debug/sqld`.
The libsql-server binary will be in `./target/debug/libsql-server`.

### 4. Verify the build

Check that sqld built successfully using its --help flag:
Check that libsql-server built successfully using its --help flag:

```bash
./target/debug/sqld --help
./target/debug/libsql-server --help
```

### 5. Run sqld with all defaults
### 5. Run libsql-server with all defaults

The following starts sqld, taking the following defaults:
The following starts libsql-server, taking the following defaults:

- Local files stored in the directory `./data.sqld`
- Client HTTP requests on 127.0.0.1:8080

```bash
./target/debug/sqld
./target/debug/libsql-server
```

8080 is the default port for the sqld HTTP service that handles client queries.
8080 is the default port for the libsql-server HTTP service that handles client queries.
With this container running, you can use the URL `http://127.0.0.1:8080` or
`ws://127.0.0.1:8080` to configure one of the libSQL client SDKs for local
development.
@@ -213,8 +213,6 @@ development.
```console
make test
```


[sqld releases page]: https://github.com/libsql/sqld/releases
[sqld container release tags]: https://github.com/libsql/sqld/pkgs/container/sqld
[sqld release tags]: https://github.com/libsql/sqld/releases
[libsql-server releases page]: https://github.com/libsql/libsql-server/releases
[libsql-server container release tags]: https://github.com/libsql/libsql-server/pkgs/container/libsql-server
[libsql-server release tags]: https://github.com/libsql/libsql-server/releases
10 changes: 5 additions & 5 deletions docs/CONSISTENCY_MODEL.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Sqld consistency model
# Libsql-server consistency model

## Building on top of sqlite

sqlite offers a strictly serializable consistency model. Since sqld is built on top of it, it inherits some of its properties.
sqlite offers a strictly serializable consistency model. Since libsql-server is built on top of it, it inherits some of its properties.

## Transactional consistency

Any transaction in sqld is equivalent to sqlite transaction. When a transaction is opened, on the primary or replicas alike, the view that the transaction get is "frozen" is time. any write performed by a transaction is at the same time immediately visible to itself, as well as completely isolated from any other ongoing transactions. Therefore, sqld offers serializable transactions
Any transaction in libsql-server is equivalent to sqlite transaction. When a transaction is opened, on the primary or replicas alike, the view that the transaction get is "frozen" is time. any write performed by a transaction is at the same time immediately visible to itself, as well as completely isolated from any other ongoing transactions. Therefore, libsql-server offers serializable transactions

## Real-time guarantees

All operations occurring on the primary are linearizable. However, there is no guarantee that changes made to the primary are immediately visible to all replicas. Sqld guarantees that a process (connection) will always see its write. Given that the primary is linearizable, it means that a process is guaranteed to see all writes that happened on the primary up until (at least) the last write performed by the process. This is not true for two distinct processes on the same replica, however, that can potentially read two different points in time. For example, a read for process A on the replica might return immediately returning some state, while a read on process B issued at the same time would need to wait to sync with the primary.
All operations occurring on the primary are linearizable. However, there is no guarantee that changes made to the primary are immediately visible to all replicas. libsql-server guarantees that a process (connection) will always see its write. Given that the primary is linearizable, it means that a process is guaranteed to see all writes that happened on the primary up until (at least) the last write performed by the process. This is not true for two distinct processes on the same replica, however, that can potentially read two different points in time. For example, a read for process A on the replica might return immediately returning some state, while a read on process B issued at the same time would need to wait to sync with the primary.

Note that reads on a replica are monotonical: once a value has been witnessed, only a value at least as recent can be witnessed on any subsequent read.

There are no global ordering guarantees provided by sqld: any two instances needn't be in sync at any time.
There are no global ordering guarantees provided by libsql-server: any two instances needn't be in sync at any time.
2 changes: 1 addition & 1 deletion docs/HTTP_V1_SPEC.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The sqld HTTP API v1 specification ("Hrana over HTTP")
# The libsql-server HTTP API v1 specification ("Hrana over HTTP")

Version 1 of the HTTP API ("Hrana over HTTP") is designed to complement the
WebSocket-based Hrana protocol for use cases that don't require stateful
2 changes: 1 addition & 1 deletion docs/HTTP_V2_SPEC.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The sqld HTTP API v2 specification ("Hrana over HTTP")
# The libsql-server HTTP API v2 specification ("Hrana over HTTP")

Version 2 of the HTTP API ("Hrana over HTTP") exposes stateful streams from
Hrana over HTTP. It provides functionality equivalent to Hrana and it is useful
10 changes: 5 additions & 5 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ The script generates the following files:
To start a `sqld` server in primary mode, run:

```console
sqld \
libsql-server \
--http-listen-addr 127.0.0.1:8081 \
--grpc-listen-addr 127.0.0.1:5001 \
--grpc-tls \
@@ -72,14 +72,14 @@ sqld \
--grpc-key-file server_key.pem
```

You now have a `sqld` primary server listening to SQL over HTTP at `127.0.0.1:8081` and gRPC with TLS at `127.0.0.1:5001`.
You now have a `libsql-server` primary server listening to SQL over HTTP at `127.0.0.1:8081` and gRPC with TLS at `127.0.0.1:5001`.

### Launching a replica server

To start a a `sqld` server in replica mode, run:
To start a a `libsql-server` server in replica mode, run:

```console
sqld \
libsql-server \
--http-listen-addr 127.0.0.1:8082 \
--primary-grpc-url https://127.0.0.1:5001 \
--primary-grpc-tls \
@@ -171,7 +171,7 @@ sqld --snapshot-exec ./snapshot.sh --max-log-duration 5
When you write to the `sqld` database, you will eventually see log line such as:

```console
2023-08-11T08:21:04.183564Z INFO sqld::replication::snapshot: snapshot `e126f594-90f4-45be-9350-bc8a01160de9-0-2.snap` successfully created
2023-08-11T08:21:04.183564Z INFO libsql-server::replication::snapshot: snapshot `e126f594-90f4-45be-9350-bc8a01160de9-0-2.snap` successfully created
Generated incremental snapshot data.sqld/dbs/default/snapshots/e126f594-90f4-45be-9350-bc8a01160de9-0-2.snap
```

4 changes: 2 additions & 2 deletions docs/http_api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SQLD HTTP API
# Libsql-server HTTP API

This is the documentation for the sqld HTTP API.
This is the documentation for the libsql-server HTTP API.

## Usage

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "sqld-libsql-bindings"
name = "libsql-bindings"
version = "0.1.0"
edition = "2021"

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions sqld/Cargo.toml → libsql-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "sqld"
name = "libsql-server"
version = "0.20.3"
edition = "2021"
default-run = "sqld"
default-run = "libsql-server"

[dependencies]
anyhow = "1.0.66"
@@ -47,7 +47,7 @@ serde = { version = "1.0.149", features = ["derive", "rc"] }
serde_json = { version = "1.0.91", features = ["preserve_order"] }
sha2 = "0.10"
sha256 = "1.1.3"
sqld-libsql-bindings = { version = "0", path = "../sqld-libsql-bindings" }
libsql-bindings = { version = "0", path = "../libsql-bindings" }
sqlite3-parser = { version = "0.11.0", default-features = false, features = [ "YYNOERRORRECOVERY" ] }
tempfile = "3.3.0"
thiserror = "1.0.38"
@@ -89,7 +89,7 @@ tonic-build = "0.10"
vergen = { version = "8", features = ["build", "git", "gitcl"] }

[features]
unix-excl-vfs = ["sqld-libsql-bindings/unix-excl-vfs"]
unix-excl-vfs = ["libsql-bindings/unix-excl-vfs"]
debug-tools = ["console-subscriber", "rusqlite/trace", "tokio/tracing"]


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ use std::sync::Arc;
use std::time::{Duration, Instant};

use crossbeam::channel::RecvTimeoutError;
use libsql_bindings::wal_hook::WalMethodsHook;
use rusqlite::{ErrorCode, OpenFlags, StatementStatus};
use sqld_libsql_bindings::wal_hook::WalMethodsHook;
use tokio::sync::{oneshot, watch};
use tracing::warn;

@@ -154,7 +154,7 @@ pub fn open_db<'a, W>(
hook_ctx: &'a mut W::Context,
flags: Option<OpenFlags>,
auto_checkpoint: u32,
) -> Result<sqld_libsql_bindings::Connection<'a>, rusqlite::Error>
) -> Result<libsql_bindings::Connection<'a>, rusqlite::Error>
where
W: WalHook,
{
@@ -164,7 +164,7 @@ where
| OpenFlags::SQLITE_OPEN_URI
| OpenFlags::SQLITE_OPEN_NO_MUTEX,
);
sqld_libsql_bindings::Connection::open(path, flags, wal_methods, hook_ctx, auto_checkpoint)
libsql_bindings::Connection::open(path, flags, wal_methods, hook_ctx, auto_checkpoint)
}

impl LibSqlConnection {
@@ -247,7 +247,7 @@ impl LibSqlConnection {

struct Connection<'a> {
timeout_deadline: Option<Instant>,
conn: sqld_libsql_bindings::Connection<'a>,
conn: libsql_bindings::Connection<'a>,
timed_out: bool,
stats: Arc<Stats>,
config_store: Arc<DatabaseConfigStore>,
@@ -626,7 +626,7 @@ mod test {
fn setup_test_conn(ctx: &mut ()) -> Connection {
let mut conn = Connection {
timeout_deadline: None,
conn: sqld_libsql_bindings::Connection::test(ctx),
conn: libsql_bindings::Connection::test(ctx),
timed_out: false,
stats: Arc::new(Stats::default()),
config_store: Arc::new(DatabaseConfigStore::new_test()),
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::path::PathBuf;
use std::sync::Arc;

use libsql_bindings::wal_hook::TRANSPARENT_METHODS;
use parking_lot::Mutex as PMutex;
use rusqlite::types::ValueRef;
use sqld_libsql_bindings::wal_hook::TRANSPARENT_METHODS;
use tokio::sync::{watch, Mutex};
use tonic::metadata::BinaryMetadataValue;
use tonic::transport::Channel;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions sqld/src/hrana/batch.rs → libsql-server/src/hrana/batch.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
use crate::auth::Authenticated;
use crate::connection::program::{Cond, Program, Step};
use crate::connection::Connection;
use crate::error::Error as SqldError;
use crate::error::Error;
use crate::hrana::stmt::StmtError;
use crate::query::{Params, Query};
use crate::query_analysis::Statement;
@@ -165,21 +165,21 @@ pub async fn execute_sequence(
})
}

fn catch_batch_error(sqld_error: SqldError) -> anyhow::Error {
fn catch_batch_error(sqld_error: Error) -> anyhow::Error {
match batch_error_from_sqld_error(sqld_error) {
Ok(batch_error) => anyhow!(batch_error),
Err(sqld_error) => anyhow!(sqld_error),
}
}

pub fn batch_error_from_sqld_error(sqld_error: SqldError) -> Result<BatchError, SqldError> {
Ok(match sqld_error {
SqldError::LibSqlTxTimeout => BatchError::TransactionTimeout,
SqldError::LibSqlTxBusy => BatchError::TransactionBusy,
SqldError::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => {
pub fn batch_error_from_sqld_error(error: Error) -> crate::Result<BatchError> {
Ok(match error {
Error::LibSqlTxTimeout => BatchError::TransactionTimeout,
Error::LibSqlTxBusy => BatchError::TransactionBusy,
Error::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => {
BatchError::ResponseTooLarge
}
sqld_error => return Err(sqld_error),
error => return Err(error),
})
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions sqld/src/hrana/stmt.rs → libsql-server/src/hrana/stmt.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use super::{proto, ProtocolError, Version};
use crate::auth::Authenticated;
use crate::connection::program::DescribeResponse;
use crate::connection::Connection;
use crate::error::Error as SqldError;
use crate::error::Error;
use crate::hrana;
use crate::query::{Params, Query, Value};
use crate::query_analysis::Statement;
@@ -196,24 +196,24 @@ fn proto_describe_result_from_describe_response(
}
}

fn catch_stmt_error(sqld_error: SqldError) -> anyhow::Error {
fn catch_stmt_error(sqld_error: Error) -> anyhow::Error {
match stmt_error_from_sqld_error(sqld_error) {
Ok(stmt_error) => anyhow!(stmt_error),
Err(sqld_error) => anyhow!(sqld_error),
}
}

pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result<StmtError, SqldError> {
Ok(match sqld_error {
SqldError::LibSqlInvalidQueryParams(source) => StmtError::ArgsInvalid { source },
SqldError::LibSqlTxTimeout => StmtError::TransactionTimeout,
SqldError::LibSqlTxBusy => StmtError::TransactionBusy,
SqldError::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => {
pub fn stmt_error_from_sqld_error(error: Error) -> crate::Result<StmtError> {
Ok(match error {
Error::LibSqlInvalidQueryParams(source) => StmtError::ArgsInvalid { source },
Error::LibSqlTxTimeout => StmtError::TransactionTimeout,
Error::LibSqlTxBusy => StmtError::TransactionBusy,
Error::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => {
StmtError::ResponseTooLarge
}
SqldError::Blocked(reason) => StmtError::Blocked { reason },
SqldError::RpcQueryError(e) => StmtError::Proxy(e.message),
SqldError::RusqliteError(rusqlite_error) => match rusqlite_error {
Error::Blocked(reason) => StmtError::Blocked { reason },
Error::RpcQueryError(e) => StmtError::Proxy(e.message),
Error::RusqliteError(rusqlite_error) => match rusqlite_error {
rusqlite::Error::SqliteFailure(sqlite_error, Some(message)) => StmtError::SqliteError {
source: sqlite_error,
message,
@@ -232,9 +232,9 @@ pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result<StmtError, Sq
message,
offset,
},
rusqlite_error => return Err(SqldError::RusqliteError(rusqlite_error)),
rusqlite_error => return Err(Error::RusqliteError(rusqlite_error)),
},
sqld_error => return Err(sqld_error),
e => return Err(e),
})
}

Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ async fn handle_ws<F: MakeNamespace>(
close(
&mut conn,
CloseCode::Normal,
"Thank you for using sqld".into(),
"Thank you for using libsql-server".into(),
)
.await;
Ok(())
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ where
}

async fn handle_get_index() -> &'static str {
"Welcome to the sqld admin API"
"Welcome to the libsql-server admin API"
}

async fn handle_get_config<M: MakeNamespace>(
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: libsql-server/src/http/user/types.rs
expression: found
---
{
"statements": [
{
"q": "select * from test",
"params": {
"Positional": []
}
},
{
"q": "select ?",
"params": {
"Positional": [
{
"Integer": 12
},
{
"Integer": 1
}
]
}
},
{
"q": "select ?",
"params": {
"Named": {
":foo": {
"Text": "bar"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: libsql-server/src/http/user/types.rs
expression: found
---
{
"Named": {
"$real": {
"Real": 1.23
},
":blob": {
"Blob": [
104,
101,
108,
108,
111,
10
]
},
":bool": {
"Integer": 0
},
":int": {
"Integer": 1
},
":null": "Null",
":str": {
"Text": "hello"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: libsql-server/src/http/user/types.rs
expression: found
---
{
"Positional": [
{
"Integer": 1
},
{
"Text": "hello"
},
{
"Real": 12.1
},
{
"Blob": [
104,
101,
108,
108,
111,
10
]
},
"Null"
]
}
File renamed without changes.
10 changes: 3 additions & 7 deletions sqld/src/lib.rs → libsql-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ use crate::migration::maybe_migrate;
use crate::net::Accept;
use crate::net::AddrIncoming;
use crate::stats::Stats;
pub use sqld_libsql_bindings as libsql;
pub use libsql_bindings as libsql;

pub mod config;
pub mod connection;
@@ -228,17 +228,13 @@ where
if let Some(soft_limit_mb) = self.db_config.soft_heap_limit_mb {
tracing::warn!("Setting soft heap limit to {soft_limit_mb}MiB");
unsafe {
sqld_libsql_bindings::ffi::sqlite3_soft_heap_limit64(
soft_limit_mb as i64 * 1024 * 1024,
)
libsql_bindings::ffi::sqlite3_soft_heap_limit64(soft_limit_mb as i64 * 1024 * 1024)
};
}
if let Some(hard_limit_mb) = self.db_config.hard_heap_limit_mb {
tracing::warn!("Setting hard heap limit to {hard_limit_mb}MiB");
unsafe {
sqld_libsql_bindings::ffi::sqlite3_hard_heap_limit64(
hard_limit_mb as i64 * 1024 * 1024,
)
libsql_bindings::ffi::sqlite3_hard_heap_limit64(hard_limit_mb as i64 * 1024 * 1024)
};
}
}
27 changes: 15 additions & 12 deletions sqld/src/main.rs → libsql-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -16,18 +16,18 @@ use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;

use sqld::config::{
use libsql_server::config::{
AdminApiConfig, DbConfig, HeartbeatConfig, RpcClientConfig, RpcServerConfig, TlsConfig,
UserApiConfig,
};
use sqld::net::AddrIncoming;
use sqld::Server;
use sqld::{connection::dump::exporter::export_dump, version::Version};
use libsql_server::net::AddrIncoming;
use libsql_server::Server;
use libsql_server::{connection::dump::exporter::export_dump, version::Version};

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

/// SQL daemon
/// Libsql-server
#[derive(Debug, Parser)]
#[command(name = "sqld")]
#[command(about = "SQL daemon", version = Version::default(), long_about = None)]
@@ -210,15 +210,18 @@ impl Cli {
// no welcome :'(
if self.no_welcome { return }

eprintln!(r#" _ _ "#);
eprintln!(r#" ___ __ _| | __| |"#);
eprintln!(r#"/ __|/ _` | |/ _` |"#);
eprintln!(r#"\__ \ (_| | | (_| |"#);
eprintln!(r#"|___/\__, |_|\__,_|"#);
eprintln!(r#" |_| "#);

eprintln!(r#" _ _ _ _ "#);
eprintln!(r#"| (_) | | | "#);
eprintln!(r#"| |_| |__ ___ __ _| |______ ___ ___ _ ____ _____ _ __ "#);
eprintln!(r#"| | | '_ \/ __|/ _` | |______/ __|/ _ \ '__\ \ / / _ \ '__|"#);
eprintln!(r#"| | | |_) \__ \ (_| | | \__ \ __/ | \ V / __/ | "#);
eprintln!(r#"|_|_|_.__/|___/\__, |_| |___/\___|_| \_/ \___|_| "#);
eprintln!(r#" | | "#);
eprintln!(r#" |_| "#);

eprintln!();
eprintln!("Welcome to sqld!");
eprintln!("Welcome to libsql-server!");
eprintln!();
eprintln!("version: {}", env!("CARGO_PKG_VERSION"));
if env!("VERGEN_GIT_SHA") != "VERGEN_IDEMPOTENT_OUTPUT" {
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ use chrono::NaiveDateTime;
use enclose::enclose;
use futures_core::Stream;
use hyper::Uri;
use libsql_bindings::wal_hook::TRANSPARENT_METHODS;
use rusqlite::ErrorCode;
use sqld_libsql_bindings::wal_hook::TRANSPARENT_METHODS;
use tokio::io::AsyncBufReadExt;
use tokio::sync::watch;
use tokio::task::{block_in_place, JoinSet};
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ impl StmtKind {
Cmd::Stmt(Stmt::Select { .. }) => Some(Self::Read),
Cmd::Stmt(Stmt::Pragma(name, body)) => Self::pragma_kind(name, body.as_ref()),
// Creating regular views is OK, temporary views are bound to a connection
// and thus disallowed in sqld.
// and thus disallowed in libsql-server.
Cmd::Stmt(Stmt::CreateView {
temporary: false, ..
}) => Some(Self::Write),
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ use std::sync::Arc;
use anyhow::{bail, ensure};
use bytemuck::{bytes_of, pod_read_unaligned, Pod, Zeroable};
use bytes::{Bytes, BytesMut};
use libsql_bindings::init_static_wal_method;
use parking_lot::RwLock;
use rusqlite::ffi::SQLITE_BUSY;
use sqld_libsql_bindings::init_static_wal_method;
use tokio::sync::watch;
use tokio::time::{Duration, Instant};
use uuid::Uuid;
@@ -375,7 +375,7 @@ impl LogFile {
start_checksum: 0,
db_id: db_id.as_u128(),
frame_count: 0,
sqld_version: Version::current().0,
libsql_server_version: Version::current().0,
}
} else {
Self::read_header(&file)?
@@ -692,8 +692,8 @@ pub struct LogFileHeader {
pub version: u32,
/// page size: 4096
pub page_size: i32,
/// sqld version when creating this log
pub sqld_version: [u16; 4],
/// libsql-server version when creating this log
pub libsql_server_version: [u16; 4],
}

impl LogFileHeader {
@@ -707,7 +707,7 @@ impl LogFileHeader {
}

fn sqld_version(&self) -> Version {
Version(self.sqld_version)
Version(self.libsql_server_version)
}
}

@@ -765,7 +765,7 @@ impl ReplicationLogger {
tracing::info!("Replication log is dirty, recovering from database file.");
true
} else if header.version < 2 || header.sqld_version() != Version::current() {
tracing::info!("replication log version not compatible with current sqld version, recovering from database file.");
tracing::info!("replication log version not compatible with current libsql-server version, recovering from database file.");
true
} else if fresh && data_path.exists() {
tracing::info!("replication log not found, recovering from database file.");
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::ffi::{c_int, CStr};
use std::marker::PhantomData;

use libsql_bindings::ffi::Wal;
use libsql_bindings::init_static_wal_method;
use libsql_bindings::{ffi::types::XWalFrameFn, wal_hook::WalHook};
use rusqlite::ffi::{PgHdr, SQLITE_ERROR};
use sqld_libsql_bindings::ffi::Wal;
use sqld_libsql_bindings::init_static_wal_method;
use sqld_libsql_bindings::{ffi::types::XWalFrameFn, wal_hook::WalHook};

use crate::replication::frame::{Frame, FrameBorrowed};
use crate::replication::{FrameNo, WAL_PAGE_SIZE};
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@ use crate::replication::replica::hook::{SQLITE_CONTINUE_REPLICATION, SQLITE_EXIT
use super::hook::{InjectorHookCtx, INJECTOR_METHODS};

pub struct FrameInjector<'a> {
conn: sqld_libsql_bindings::Connection<'a>,
conn: libsql_bindings::Connection<'a>,
}

impl<'a> FrameInjector<'a> {
pub fn new(db_path: &Path, hook_ctx: &'a mut InjectorHookCtx) -> anyhow::Result<Self> {
let conn = sqld_libsql_bindings::Connection::open(
let conn = libsql_bindings::Connection::open(
db_path,
OpenFlags::SQLITE_OPEN_READ_WRITE
| OpenFlags::SQLITE_OPEN_CREATE
File renamed without changes.
26 changes: 13 additions & 13 deletions sqld/src/rpc/proxy.rs → libsql-server/src/rpc/proxy.rs
Original file line number Diff line number Diff line change
@@ -28,26 +28,26 @@ pub mod rpc {
use anyhow::Context;

use crate::query_analysis::Statement;
use crate::{connection, error::Error as SqldError};
use crate::{connection, error::Error as CrateError};

use self::{error::ErrorCode, execute_results::State};
tonic::include_proto!("proxy");

impl From<SqldError> for Error {
fn from(other: SqldError) -> Self {
impl From<CrateError> for Error {
fn from(other: CrateError) -> Self {
Error {
message: other.to_string(),
code: ErrorCode::from(other).into(),
}
}
}

impl From<SqldError> for ErrorCode {
fn from(other: SqldError) -> Self {
impl From<CrateError> for ErrorCode {
fn from(other: CrateError) -> Self {
match other {
SqldError::LibSqlInvalidQueryParams(_) => ErrorCode::SqlError,
SqldError::LibSqlTxTimeout => ErrorCode::TxTimeout,
SqldError::LibSqlTxBusy => ErrorCode::TxBusy,
CrateError::LibSqlInvalidQueryParams(_) => ErrorCode::SqlError,
CrateError::LibSqlTxTimeout => ErrorCode::TxTimeout,
CrateError::LibSqlTxBusy => ErrorCode::TxBusy,
_ => ErrorCode::Internal,
}
}
@@ -74,11 +74,11 @@ pub mod rpc {
}

impl TryFrom<crate::query::Params> for query::Params {
type Error = SqldError;
type Error = CrateError;
fn try_from(value: crate::query::Params) -> Result<Self, Self::Error> {
match value {
crate::query::Params::Named(params) => {
let iter = params.into_iter().map(|(k, v)| -> Result<_, SqldError> {
let iter = params.into_iter().map(|(k, v)| -> Result<_, CrateError> {
let v = Value {
data: bincode::serialize(&v)?,
};
@@ -95,15 +95,15 @@ pub mod rpc {
data: bincode::serialize(&v)?,
})
})
.collect::<Result<Vec<_>, SqldError>>()?;
.collect::<Result<Vec<_>, CrateError>>()?;
Ok(Self::Positional(Positional { values }))
}
}
}
}

impl TryFrom<query::Params> for crate::query::Params {
type Error = SqldError;
type Error = CrateError;

fn try_from(value: query::Params) -> Result<Self, Self::Error> {
match value {
@@ -112,7 +112,7 @@ pub mod rpc {
.values
.into_iter()
.map(|v| bincode::deserialize(&v.data).map_err(|e| e.into()))
.collect::<Result<Vec<_>, SqldError>>()?;
.collect::<Result<Vec<_>, CrateError>>()?;
Ok(Self::Positional(params))
}
query::Params::Named(named) => {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.