Skip to content

Commit ce2d378

Browse files
Athos CoutoMarinPostma
authored andcommitted
Add UUID to stats
This should allow any stats consumer to know when the file has been lost and the counters should be restarted.
1 parent b32d62f commit ce2d378

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

libsql-server/src/http/admin/stats.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use serde::Serialize;
44

55
use axum::extract::{Path, State};
66
use axum::Json;
7+
use uuid::Uuid;
78

89
use crate::namespace::{MakeNamespace, NamespaceName};
910
use crate::replication::FrameNo;
@@ -13,6 +14,7 @@ use super::AppState;
1314

1415
#[derive(Serialize)]
1516
pub struct StatsResponse {
17+
pub id: Option<Uuid>,
1618
pub rows_read_count: u64,
1719
pub rows_written_count: u64,
1820
pub storage_bytes_used: u64,
@@ -25,6 +27,7 @@ pub struct StatsResponse {
2527
impl From<&Stats> for StatsResponse {
2628
fn from(stats: &Stats) -> Self {
2729
Self {
30+
id: stats.id(),
2831
rows_read_count: stats.rows_read(),
2932
rows_written_count: stats.rows_written(),
3033
storage_bytes_used: stats.storage_bytes_used(),

libsql-server/src/stats.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::collections::BTreeSet;
88
use tokio::io::AsyncWriteExt;
99
use tokio::task::JoinSet;
1010
use tokio::time::Duration;
11+
use uuid::Uuid;
1112

1213
use crate::namespace::NamespaceName;
1314
use crate::replication::FrameNo;
@@ -56,6 +57,8 @@ pub struct Stats {
5657
#[serde(skip)]
5758
namespace: NamespaceName,
5859

60+
#[serde(default)]
61+
id: Option<Uuid>,
5962
#[serde(default)]
6063
rows_written: AtomicU64,
6164
#[serde(default)]
@@ -93,6 +96,10 @@ impl Stats {
9396
Stats::default()
9497
};
9598

99+
if this.id.is_none() {
100+
this.id = Some(Uuid::new_v4());
101+
}
102+
96103
this.namespace = namespace;
97104
let this = Arc::new(this);
98105

@@ -226,6 +233,10 @@ impl Stats {
226233
counter!("libsql_server_query_rows_written", rows_written);
227234
counter!("libsql_server_query_mem_used", mem_used);
228235
}
236+
237+
pub fn id(&self) -> Option<Uuid> {
238+
self.id.clone()
239+
}
229240
}
230241

231242
async fn spawn_stats_persist_thread(stats: Weak<Stats>, path: PathBuf) -> anyhow::Result<()> {

0 commit comments

Comments
 (0)