mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-06-17 06:49:51 +00:00
Add UUID to stats
This should allow any stats consumer to know when the file has been lost and the counters should be restarted.
This commit is contained in:
@ -4,6 +4,7 @@ use serde::Serialize;
|
||||
|
||||
use axum::extract::{Path, State};
|
||||
use axum::Json;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::namespace::{MakeNamespace, NamespaceName};
|
||||
use crate::replication::FrameNo;
|
||||
@ -13,6 +14,7 @@ use super::AppState;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct StatsResponse {
|
||||
pub id: Option<Uuid>,
|
||||
pub rows_read_count: u64,
|
||||
pub rows_written_count: u64,
|
||||
pub storage_bytes_used: u64,
|
||||
@ -25,6 +27,7 @@ pub struct StatsResponse {
|
||||
impl From<&Stats> for StatsResponse {
|
||||
fn from(stats: &Stats) -> Self {
|
||||
Self {
|
||||
id: stats.id(),
|
||||
rows_read_count: stats.rows_read(),
|
||||
rows_written_count: stats.rows_written(),
|
||||
storage_bytes_used: stats.storage_bytes_used(),
|
||||
|
@ -8,6 +8,7 @@ use std::collections::BTreeSet;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::task::JoinSet;
|
||||
use tokio::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::namespace::NamespaceName;
|
||||
use crate::replication::FrameNo;
|
||||
@ -56,6 +57,8 @@ pub struct Stats {
|
||||
#[serde(skip)]
|
||||
namespace: NamespaceName,
|
||||
|
||||
#[serde(default)]
|
||||
id: Option<Uuid>,
|
||||
#[serde(default)]
|
||||
rows_written: AtomicU64,
|
||||
#[serde(default)]
|
||||
@ -93,6 +96,10 @@ impl Stats {
|
||||
Stats::default()
|
||||
};
|
||||
|
||||
if this.id.is_none() {
|
||||
this.id = Some(Uuid::new_v4());
|
||||
}
|
||||
|
||||
this.namespace = namespace;
|
||||
let this = Arc::new(this);
|
||||
|
||||
@ -226,6 +233,10 @@ impl Stats {
|
||||
counter!("libsql_server_query_rows_written", rows_written);
|
||||
counter!("libsql_server_query_mem_used", mem_used);
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<Uuid> {
|
||||
self.id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
async fn spawn_stats_persist_thread(stats: Weak<Stats>, path: PathBuf) -> anyhow::Result<()> {
|
||||
|
Reference in New Issue
Block a user