Skip to content

Commit aa67655

Browse files
committed
[experimental] Restate-lite library
This introduces `restate-lite` a crate that provides restate core functionality as a library. The library is intended to be used in developement or testing use cases. Therefore, it uses defaults tuned for for that purpose.
1 parent c29a614 commit aa67655

File tree

10 files changed

+686
-2
lines changed

10 files changed

+686
-2
lines changed

Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crates/encoding/derive",
77
"crates/codederror/derive",
88
"server",
9+
"lite",
910
"benchmarks",
1011
"tools/bifrost-benchpress",
1112
"tools/mock-service-endpoint",
@@ -69,6 +70,7 @@ restate-queue = { path = "crates/queue" }
6970
restate-rocksdb = { path = "crates/rocksdb" }
7071
restate-serde-util = { path = "crates/serde-util" }
7172
restate-server = { path = "server" }
73+
restate-lite = { path = "lite" }
7274
restate-service-client = { path = "crates/service-client" }
7375
restate-service-protocol = { path = "crates/service-protocol" }
7476
restate-service-protocol-v4 = { path = "crates/service-protocol-v4" }

crates/core/src/task_center/handle.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ impl OwnedHandle {
301301
}
302302
}
303303

304+
pub fn address_book(&self) -> Option<&AddressBook> {
305+
self.inner.address_book()
306+
}
307+
308+
pub fn try_set_address_book(&self, address_book: AddressBook) -> bool {
309+
self.inner.try_set_address_book(address_book)
310+
}
311+
304312
pub fn to_handle(&self) -> Handle {
305313
Handle::new(&self.inner)
306314
}

crates/node/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ publish = false
99

1010
[features]
1111
default = []
12+
all-metadata-providers = [
13+
"restate-metadata-providers/replicated",
14+
"restate-metadata-providers/etcd",
15+
"restate-metadata-providers/objstore",
16+
]
17+
1218
memory-loglet = ["restate-bifrost/memory-loglet"]
1319
options_schema = [
1420
"dep:schemars",
@@ -25,7 +31,7 @@ restate-core = { workspace = true }
2531
restate-futures-util = { workspace = true }
2632
restate-ingress-http = { workspace = true }
2733
restate-log-server = { workspace = true }
28-
restate-metadata-providers = { workspace = true, features = ["replicated", "objstore", "etcd"] }
34+
restate-metadata-providers = { workspace = true }
2935
restate-metadata-server = { workspace = true }
3036
restate-metadata-server-grpc = { workspace = true, features = ["grpc-client"] }
3137
restate-metadata-store = { workspace = true, features = ["grpc-server"] }

lite/Cargo.toml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[package]
2+
name = "restate-lite"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
repository.workspace = true
7+
homepage.workspace = true
8+
rust-version.workspace = true
9+
license.workspace = true
10+
publish = false
11+
description = "Restate Lite"
12+
build = "build.rs"
13+
14+
[package.metadata.dist]
15+
dist = true
16+
17+
[features]
18+
default = ["no-trace-logging"]
19+
no-trace-logging = ["tracing/max_level_trace", "tracing/release_max_level_debug"]
20+
21+
[dependencies]
22+
restate-workspace-hack = { workspace = true }
23+
24+
restate-bifrost = { workspace = true }
25+
restate-core = { workspace = true }
26+
restate-errors = { workspace = true }
27+
restate-metadata-server = { workspace = true }
28+
restate-node = { workspace = true }
29+
restate-rocksdb = { workspace = true }
30+
restate-service-client = { workspace = true }
31+
restate-types = { workspace = true }
32+
restate-admin = { workspace = true }
33+
34+
anyhow = { workspace = true }
35+
http = { workspace = true }
36+
parking_lot = { workspace = true }
37+
reqwest = { workspace = true }
38+
rlimit = { workspace = true }
39+
serde_json = { workspace = true }
40+
tokio = { workspace = true }
41+
tracing = { workspace = true }
42+
43+
[dev-dependencies]
44+
tracing-subscriber = { workspace = true }
45+
tempfile = { workspace = true }
46+
47+
[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
48+
tikv-jemallocator = { workspace = true }
49+
50+
[build-dependencies]
51+
vergen = { version = "8.0.0", default-features = false, features = [
52+
"build",
53+
"git",
54+
"gitcl",
55+
"cargo",
56+
] }

lite/build.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2023 - 2025 Restate Software, Inc., Restate GmbH.
2+
// All rights reserved.
3+
//
4+
// Use of this software is governed by the Business Source License
5+
// included in the LICENSE file.
6+
//
7+
// As of the Change Date specified in that file, in accordance with
8+
// the Business Source License, use of this software will be governed
9+
// by the Apache License, Version 2.0.
10+
11+
use std::error::Error;
12+
use vergen::EmitBuilder;
13+
14+
fn main() -> Result<(), Box<dyn Error>> {
15+
// Emit the instructions
16+
EmitBuilder::builder()
17+
.build_date()
18+
.build_timestamp()
19+
.cargo_features()
20+
.cargo_opt_level()
21+
.cargo_target_triple()
22+
.cargo_debug()
23+
.git_branch()
24+
.git_commit_date()
25+
.git_commit_timestamp()
26+
.git_sha(true)
27+
.emit()?;
28+
Ok(())
29+
}

lite/examples/restate-lite.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) 2023 - 2025 Restate Software, Inc., Restate GmbH.
2+
// All rights reserved.
3+
//
4+
// Use of this software is governed by the Business Source License
5+
// included in the LICENSE file.
6+
//
7+
// As of the Change Date specified in that file, in accordance with
8+
// the Business Source License, use of this software will be governed
9+
// by the Apache License, Version 2.0.
10+
11+
use std::io::IsTerminal;
12+
use std::io::Write as _;
13+
14+
use restate_lite::Options;
15+
use tokio::signal::unix::SignalKind;
16+
use tokio::signal::unix::signal;
17+
18+
use restate_lite::AddressMeta;
19+
use restate_lite::Restate;
20+
21+
#[cfg(not(target_env = "msvc"))]
22+
use tikv_jemallocator::Jemalloc;
23+
24+
#[cfg(not(target_env = "msvc"))]
25+
#[global_allocator]
26+
static GLOBAL: Jemalloc = Jemalloc;
27+
28+
#[tokio::main(flavor = "multi_thread")]
29+
async fn main() -> anyhow::Result<()> {
30+
tracing_subscriber::fmt::init();
31+
32+
let temp_dir = tempfile::tempdir()?;
33+
let options = Options {
34+
data_dir: Some(temp_dir.path().to_path_buf()),
35+
..Default::default()
36+
};
37+
38+
println!(
39+
"Using data dir: {}",
40+
options.data_dir.as_ref().unwrap().display()
41+
);
42+
43+
let restate = Restate::create(options).await?;
44+
println!("** Bound addresses **");
45+
print_addresses(&restate.get_bound_addresses());
46+
47+
println!("** Advertised addresses **");
48+
print_addresses(&restate.get_advertised_addresses());
49+
50+
shutdown(restate).await?;
51+
eprintln!("Bye!");
52+
53+
Ok(())
54+
}
55+
56+
fn print_addresses(addresses: &[AddressMeta]) {
57+
if !std::io::stdout().is_terminal() {
58+
return;
59+
}
60+
61+
let mut stdout = std::io::stdout().lock();
62+
for address in addresses {
63+
let _ = writeln!(&mut stdout, "[{}]: {}", address.name, address.address);
64+
}
65+
66+
let _ = writeln!(&mut stdout);
67+
}
68+
69+
async fn shutdown(restate: Restate) -> anyhow::Result<()> {
70+
let signal = tokio::select! {
71+
() = await_signal(SignalKind::interrupt()) => "SIGINT",
72+
() = await_signal(SignalKind::terminate()) => "SIGTERM",
73+
};
74+
eprintln!("Received {signal}, starting shutdown.");
75+
76+
restate.stop().await
77+
}
78+
79+
async fn await_signal(kind: SignalKind) {
80+
signal(kind)
81+
.expect("failed to register signal handler")
82+
.recv()
83+
.await;
84+
}

lite/src/build_info.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2023 - 2025 Restate Software, Inc., Restate GmbH.
2+
// All rights reserved.
3+
//
4+
// Use of this software is governed by the Business Source License
5+
// included in the LICENSE file.
6+
//
7+
// As of the Change Date specified in that file, in accordance with
8+
// the Business Source License, use of this software will be governed
9+
// by the Apache License, Version 2.0.
10+
11+
//! Build information
12+
#![allow(dead_code)]
13+
14+
/// The version of restate server.
15+
pub const RESTATE_SERVER_VERSION: &str = env!("CARGO_PKG_VERSION");
16+
pub const RESTATE_SERVER_VERSION_MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR");
17+
pub const RESTATE_SERVER_VERSION_MINOR: &str = env!("CARGO_PKG_VERSION_MINOR");
18+
pub const RESTATE_SERVER_VERSION_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
19+
/// Pre-release version of restate.
20+
pub const RESTATE_SERVER_VERSION_PRE: &str = env!("CARGO_PKG_VERSION_PRE");
21+
22+
pub const RESTATE_SERVER_BUILD_DATE: &str = env!("VERGEN_BUILD_DATE");
23+
pub const RESTATE_SERVER_BUILD_TIME: &str = env!("VERGEN_BUILD_TIMESTAMP");
24+
pub const RESTATE_SERVER_COMMIT_SHA: &str = env!("VERGEN_GIT_SHA");
25+
pub const RESTATE_SERVER_COMMIT_DATE: &str = env!("VERGEN_GIT_COMMIT_DATE");
26+
pub const RESTATE_SERVER_BRANCH: &str = env!("VERGEN_GIT_BRANCH");
27+
// The target triple.
28+
pub const RESTATE_SERVER_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
29+
30+
/// Returns build information, e.g: 0.5.0-dev (debug) (2ba1491 aarch64-apple-darwin 2023-11-21)
31+
pub fn build_info() -> String {
32+
format!(
33+
"{RESTATE_SERVER_VERSION}{} ({RESTATE_SERVER_COMMIT_SHA} {RESTATE_SERVER_TARGET_TRIPLE} {RESTATE_SERVER_BUILD_DATE})",
34+
if is_debug() { " (debug)" } else { "" }
35+
)
36+
}
37+
38+
const RESTATE_SERVER_DEBUG_STRIPPED: Option<&str> = option_env!("DEBUG_STRIPPED");
39+
const RESTATE_SERVER_DEBUG: &str = env!("VERGEN_CARGO_DEBUG");
40+
/// Was the binary compiled with debug symbols
41+
pub fn is_debug() -> bool {
42+
RESTATE_SERVER_DEBUG == "true" && RESTATE_SERVER_DEBUG_STRIPPED != Some("true")
43+
}

0 commit comments

Comments
 (0)