Skip to content

Commit b4f1389

Browse files
goffrieConvex, Inc.
authored andcommitted
Remove set_read_only from Persistence trait, and make it independent of the lease (#42108)
GitOrigin-RevId: 9e91aa25c3c38fba3f973aa820f6e1b64f685120
1 parent a00f444 commit b4f1389

File tree

11 files changed

+305
-381
lines changed

11 files changed

+305
-381
lines changed

crates/common/src/persistence.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ pub trait Persistence: Sync + Send + 'static {
214214
conflict_strategy: ConflictStrategy,
215215
) -> anyhow::Result<()>;
216216

217-
async fn set_read_only(&self, read_only: bool) -> anyhow::Result<()>;
218-
219217
/// Writes global key-value data for the whole persistence.
220218
/// This is expected to be small data that does not make sense in a
221219
/// versioned or transaction context. See `PersistenceGlobalKey`.

crates/common/src/testing/persistence_test_suite.rs

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use crate::{
7777

7878
#[macro_export]
7979
macro_rules! run_persistence_test_suite {
80-
($db:ident, $create_db:expr, $create_persistence:expr, $create_persistence_read_only:expr) => {
80+
($db:ident, $create_db:expr, $create_persistence:expr) => {
8181
#[tokio::test]
8282
async fn test_persistence_write_and_load() -> anyhow::Result<()> {
8383
let $db = $create_db;
@@ -192,16 +192,6 @@ macro_rules! run_persistence_test_suite {
192192
.await
193193
}
194194

195-
#[tokio::test]
196-
async fn test_persistence_set_read_only() -> anyhow::Result<()> {
197-
let $db = $create_db;
198-
persistence_test_suite::set_read_only(
199-
|| async { Ok($create_persistence) },
200-
|| async { Ok($create_persistence_read_only) },
201-
)
202-
.await
203-
}
204-
205195
#[tokio::test]
206196
async fn test_persistence_global() -> anyhow::Result<()> {
207197
let $db = $create_db;
@@ -1485,73 +1475,6 @@ where
14851475
Ok(())
14861476
}
14871477

1488-
pub async fn set_read_only<F, Fut, F1, Fut1, P: Persistence>(
1489-
mut make_p: F,
1490-
mut make_p_read_only: F1,
1491-
) -> anyhow::Result<()>
1492-
where
1493-
F: FnMut() -> Fut,
1494-
Fut: Future<Output = anyhow::Result<P>>,
1495-
F1: FnMut() -> Fut1,
1496-
Fut1: Future<Output = anyhow::Result<P>>,
1497-
{
1498-
// Initially not read-only.
1499-
let p_backend1 = make_p().await?;
1500-
let table: TableName = str::parse("table")?;
1501-
let mut id_generator = TestIdGenerator::new();
1502-
let doc_id = id_generator.user_generate(&table);
1503-
1504-
let doc = ResolvedDocument::new(doc_id, CreationTime::ONE, ConvexObject::empty())?;
1505-
1506-
p_backend1
1507-
.write(
1508-
&[DocumentLogEntry {
1509-
ts: Timestamp::must(0),
1510-
id: doc.id_with_table_id(),
1511-
value: Some(doc.clone()),
1512-
prev_ts: None,
1513-
}],
1514-
&[],
1515-
ConflictStrategy::Error,
1516-
)
1517-
.await?;
1518-
// Release the lease.
1519-
drop(p_backend1);
1520-
1521-
let p_migration = make_p().await?;
1522-
p_migration.set_read_only(true).await?;
1523-
1524-
let result = make_p().await;
1525-
assert!(result.is_err());
1526-
1527-
drop(p_migration);
1528-
1529-
// Try to acquire lease should fail because it's read-only.
1530-
let result = make_p().await;
1531-
assert!(result.is_err());
1532-
1533-
let p_cleanup = make_p_read_only().await?;
1534-
p_cleanup.set_read_only(false).await?;
1535-
drop(p_cleanup);
1536-
1537-
// Now it's no longer read-only.
1538-
let p_backend2 = make_p().await?;
1539-
p_backend2
1540-
.write(
1541-
&[(DocumentLogEntry {
1542-
ts: Timestamp::must(1),
1543-
id: doc.id_with_table_id(),
1544-
value: Some(doc.clone()),
1545-
prev_ts: None,
1546-
})],
1547-
&[],
1548-
ConflictStrategy::Error,
1549-
)
1550-
.await?;
1551-
1552-
Ok(())
1553-
}
1554-
15551478
pub async fn persistence_global<P: Persistence>(p: Arc<P>) -> anyhow::Result<()> {
15561479
let key = PersistenceGlobalKey::RetentionMinSnapshotTimestamp;
15571480
p.write_persistence_global(key, json!(5)).await?;

crates/common/src/testing/test_persistence.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,15 @@ impl TestPersistence {
6868
config_test();
6969
let inner = Inner {
7070
is_fresh: true,
71-
is_read_only: false,
7271
log: BTreeMap::new(),
7372
index: BTreeMap::new(),
7473
persistence_globals: BTreeMap::new(),
7574
};
76-
Self::new_inner(Arc::new(Mutex::new(inner)), false).unwrap()
75+
Self::new_inner(Arc::new(Mutex::new(inner))).unwrap()
7776
}
7877

7978
/// Pass in an Inner to store state across TestPersistence instances.
80-
fn new_inner(inner: Arc<Mutex<Inner>>, allow_read_only: bool) -> anyhow::Result<Self> {
81-
anyhow::ensure!(allow_read_only || !inner.lock().is_read_only);
79+
fn new_inner(inner: Arc<Mutex<Inner>>) -> anyhow::Result<Self> {
8280
Ok(Self { inner })
8381
}
8482
}
@@ -139,11 +137,6 @@ impl Persistence for TestPersistence {
139137
Ok(())
140138
}
141139

142-
async fn set_read_only(&self, read_only: bool) -> anyhow::Result<()> {
143-
self.inner.lock().is_read_only = read_only;
144-
Ok(())
145-
}
146-
147140
async fn write_persistence_global(
148141
&self,
149142
key: PersistenceGlobalKey,
@@ -421,7 +414,6 @@ impl PersistenceReader for TestPersistence {
421414

422415
struct Inner {
423416
is_fresh: bool,
424-
is_read_only: bool,
425417
log: BTreeMap<(Timestamp, InternalDocumentId), (Option<ResolvedDocument>, Option<Timestamp>)>,
426418
index: BTreeMap<IndexId, BTreeMap<(IndexKeyBytes, Timestamp), Option<InternalDocumentId>>>,
427419
persistence_globals: BTreeMap<PersistenceGlobalKey, JsonValue>,
@@ -450,11 +442,9 @@ run_persistence_test_suite!(
450442
db,
451443
Arc::new(Mutex::new(Inner {
452444
is_fresh: true,
453-
is_read_only: false,
454445
log: BTreeMap::new(),
455446
index: BTreeMap::new(),
456447
persistence_globals: BTreeMap::new(),
457448
})),
458-
TestPersistence::new_inner(db.clone(), false)?,
459-
TestPersistence::new_inner(db.clone(), true)?
449+
TestPersistence::new_inner(db.clone())?
460450
);

0 commit comments

Comments
 (0)