Skip to content

Commit 3da2a8b

Browse files
committed
libsql: Add max_write_replication_index field to Database
This field will store replication index of the latest write performed using any connection created with this Database object. This will allow a client to know what is a minimal replication index they have to use to see all the writes they performed so far. Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
1 parent 4023a3a commit 3da2a8b

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

libsql/src/database.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ pub use builder::Builder;
77
#[cfg(feature = "core")]
88
pub use libsql_sys::{Cipher, EncryptionConfig};
99

10-
use std::fmt;
11-
1210
use crate::{Connection, Result};
11+
use std::fmt;
12+
use std::sync::atomic::AtomicU64;
13+
use std::sync::Arc;
1314

1415
cfg_core! {
1516
bitflags::bitflags! {
@@ -76,6 +77,9 @@ impl fmt::Debug for DbType {
7677
/// not do much work until the [`Database::connect`] fn is called.
7778
pub struct Database {
7879
db_type: DbType,
80+
/// The maximum replication index returned from a write performed using any connection created using this Database object.
81+
#[allow(dead_code)]
82+
max_write_replication_index: Arc<AtomicU64>,
7983
}
8084

8185
cfg_core! {
@@ -87,6 +91,7 @@ cfg_core! {
8791

8892
Ok(Database {
8993
db_type: DbType::Memory { db },
94+
max_write_replication_index: Default::default(),
9095
})
9196
}
9297

@@ -105,6 +110,7 @@ cfg_core! {
105110
flags,
106111
encryption_config: None,
107112
},
113+
max_write_replication_index: Default::default(),
108114
})
109115
}
110116
}
@@ -130,6 +136,7 @@ cfg_replication! {
130136

131137
Ok(Database {
132138
db_type: DbType::Sync { db, encryption_config },
139+
max_write_replication_index: Default::default(),
133140
})
134141
}
135142

@@ -191,6 +198,7 @@ cfg_replication! {
191198

192199
Ok(Database {
193200
db_type: DbType::Sync { db, encryption_config },
201+
max_write_replication_index: Default::default(),
194202
})
195203
}
196204

@@ -317,6 +325,7 @@ cfg_replication! {
317325

318326
Ok(Database {
319327
db_type: DbType::Sync { db, encryption_config },
328+
max_write_replication_index: Default::default(),
320329
})
321330
}
322331

@@ -372,7 +381,8 @@ cfg_replication! {
372381
DbType::Sync { db, .. } => {
373382
let path = db.path().to_string();
374383
Ok(Database {
375-
db_type: DbType::File { path, flags: OpenFlags::default(), encryption_config: None}
384+
db_type: DbType::File { path, flags: OpenFlags::default(), encryption_config: None},
385+
max_write_replication_index: Default::default(),
376386
})
377387
}
378388
t => Err(Error::FreezeNotSupported(format!("{:?}", t)))
@@ -445,6 +455,7 @@ cfg_remote! {
445455
connector: crate::util::ConnectorService::new(svc),
446456
version,
447457
},
458+
max_write_replication_index: Default::default(),
448459
})
449460
}
450461
}

libsql/src/database/builder.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ cfg_core! {
135135
let db = crate::local::Database::open(":memory:", crate::OpenFlags::default())?;
136136
Database {
137137
db_type: DbType::Memory { db } ,
138+
max_write_replication_index: Default::default(),
138139
}
139140
} else {
140141
let path = self
@@ -150,6 +151,7 @@ cfg_core! {
150151
flags: self.inner.flags,
151152
encryption_config: self.inner.encryption_config,
152153
},
154+
max_write_replication_index: Default::default(),
153155
}
154156
};
155157

@@ -291,6 +293,7 @@ cfg_replication! {
291293

292294
Ok(Database {
293295
db_type: DbType::Sync { db, encryption_config },
296+
max_write_replication_index: Default::default(),
294297
})
295298
}
296299
}
@@ -360,6 +363,7 @@ cfg_replication! {
360363

361364
Ok(Database {
362365
db_type: DbType::Sync { db, encryption_config },
366+
max_write_replication_index: Default::default(),
363367
})
364368
}
365369
}
@@ -414,6 +418,7 @@ cfg_remote! {
414418
connector,
415419
version,
416420
},
421+
max_write_replication_index: Default::default(),
417422
})
418423
}
419424
}

0 commit comments

Comments
 (0)