Skip to content

Commit 2497f0e

Browse files
committed
chore(stores): switch from pause/resume semantics to close and reopen ones
1 parent e72841a commit 2497f0e

24 files changed

Lines changed: 372 additions & 368 deletions

File tree

crates/matrix-sdk-base/src/client.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,28 +1150,28 @@ impl BaseClient {
11501150
Ok(result)
11511151
}
11521152

1153-
/// Pause all stores, releasing database connections and file locks.
1153+
/// Close all stores, releasing database connections and file locks.
11541154
///
11551155
/// In-flight operations will complete before this returns.
1156-
pub async fn pause_stores(&self) -> Result<()> {
1157-
self.state_store.pause().await?;
1158-
self.event_cache_store.pause().await.map_err(Error::EventCacheStore)?;
1159-
self.media_store.pause().await.map_err(Error::MediaStore)?;
1156+
pub async fn close_stores(&self) -> Result<()> {
1157+
self.state_store.close().await?;
1158+
self.event_cache_store.close().await.map_err(Error::EventCacheStore)?;
1159+
self.media_store.close().await.map_err(Error::MediaStore)?;
11601160

11611161
#[cfg(feature = "e2e-encryption")]
1162-
self.crypto_store.pause().await.map_err(Error::CryptoStore)?;
1162+
self.crypto_store.close().await.map_err(Error::CryptoStore)?;
11631163

11641164
Ok(())
11651165
}
11661166

1167-
/// Resume all stores after a pause, re-opening database connections.
1168-
pub async fn resume_stores(&self) -> Result<()> {
1167+
/// Reopen all stores after a close, re-opening database connections.
1168+
pub async fn reopen_stores(&self) -> Result<()> {
11691169
#[cfg(feature = "e2e-encryption")]
1170-
self.crypto_store.resume().await.map_err(Error::CryptoStore)?;
1170+
self.crypto_store.reopen().await.map_err(Error::CryptoStore)?;
11711171

1172-
self.media_store.resume().await.map_err(Error::MediaStore)?;
1173-
self.event_cache_store.resume().await.map_err(Error::EventCacheStore)?;
1174-
self.state_store.resume().await?;
1172+
self.media_store.reopen().await.map_err(Error::MediaStore)?;
1173+
self.event_cache_store.reopen().await.map_err(Error::EventCacheStore)?;
1174+
self.state_store.reopen().await?;
11751175

11761176
Ok(())
11771177
}

crates/matrix-sdk-base/src/event_cache/store/memory_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ impl MemoryStore {
7777
impl EventCacheStore for MemoryStore {
7878
type Error = EventCacheStoreError;
7979

80-
async fn pause(&self) -> Result<(), Self::Error> {
80+
async fn close(&self) -> Result<(), Self::Error> {
8181
Ok(())
8282
}
8383

84-
async fn resume(&self) -> Result<(), Self::Error> {
84+
async fn reopen(&self) -> Result<(), Self::Error> {
8585
Ok(())
8686
}
8787

crates/matrix-sdk-base/src/event_cache/store/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ impl EventCacheStoreLock {
8080
Self { cross_process_lock, store }
8181
}
8282

83-
/// Pause the store, releasing database connections and file locks.
84-
pub async fn pause(&self) -> Result<(), EventCacheStoreError> {
85-
self.store.pause().await
83+
/// Close the store, releasing database connections and file locks.
84+
pub async fn close(&self) -> Result<(), EventCacheStoreError> {
85+
self.store.close().await
8686
}
8787

88-
/// Resume the store after a pause.
89-
pub async fn resume(&self) -> Result<(), EventCacheStoreError> {
90-
self.store.resume().await
88+
/// Reopen the store after a close.
89+
pub async fn reopen(&self) -> Result<(), EventCacheStoreError> {
90+
self.store.reopen().await
9191
}
9292

9393
/// Acquire a spin lock (see [`CrossProcessLock::spin_lock`]).

crates/matrix-sdk-base/src/event_cache/store/traits.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,16 @@ pub trait EventCacheStore: AsyncTraitDeps {
176176
/// without causing an error.
177177
async fn save_event(&self, room_id: &RoomId, event: Event) -> Result<(), Self::Error>;
178178

179-
/// Pause the store, releasing all held resources (database connections,
179+
/// Close the store, releasing all held resources (database connections,
180180
/// file descriptors, file locks).
181181
///
182182
/// In-flight operations complete before this method returns. After it
183-
/// returns, operations will fail until [`Self::resume()`] is called.
184-
async fn pause(&self) -> Result<(), Self::Error>;
183+
/// returns, operations will fail until [`Self::reopen()`] is called.
184+
async fn close(&self) -> Result<(), Self::Error>;
185185

186-
/// Resume the store after a [`Self::pause()`], re-acquiring database
186+
/// Reopen the store after a [`Self::close()`], re-acquiring database
187187
/// connections.
188-
async fn resume(&self) -> Result<(), Self::Error>;
188+
async fn reopen(&self) -> Result<(), Self::Error>;
189189

190190
/// Perform database optimizations if any are available, i.e. vacuuming in
191191
/// SQLite.
@@ -305,12 +305,12 @@ impl<T: EventCacheStore> EventCacheStore for EraseEventCacheStoreError<T> {
305305
self.0.save_event(room_id, event).await.map_err(Into::into)
306306
}
307307

308-
async fn pause(&self) -> Result<(), Self::Error> {
309-
self.0.pause().await.map_err(Into::into)
308+
async fn close(&self) -> Result<(), Self::Error> {
309+
self.0.close().await.map_err(Into::into)
310310
}
311311

312-
async fn resume(&self) -> Result<(), Self::Error> {
313-
self.0.resume().await.map_err(Into::into)
312+
async fn reopen(&self) -> Result<(), Self::Error> {
313+
self.0.reopen().await.map_err(Into::into)
314314
}
315315

316316
async fn optimize(&self) -> Result<(), Self::Error> {

crates/matrix-sdk-base/src/media/store/memory_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ impl MediaStore for MemoryMediaStore {
227227
Ok(None)
228228
}
229229

230-
async fn pause(&self) -> Result<(), Self::Error> {
230+
async fn close(&self) -> Result<(), Self::Error> {
231231
Ok(())
232232
}
233233

234-
async fn resume(&self) -> Result<(), Self::Error> {
234+
async fn reopen(&self) -> Result<(), Self::Error> {
235235
Ok(())
236236
}
237237
}

crates/matrix-sdk-base/src/media/store/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ impl MediaStoreLock {
129129
Self { cross_process_lock, store }
130130
}
131131

132-
/// Pause the store, releasing database connections and file locks.
133-
pub async fn pause(&self) -> Result<(), MediaStoreError> {
134-
self.store.pause().await
132+
/// Close the store, releasing database connections and file locks.
133+
pub async fn close(&self) -> Result<(), MediaStoreError> {
134+
self.store.close().await
135135
}
136136

137-
/// Resume the store after a pause.
138-
pub async fn resume(&self) -> Result<(), MediaStoreError> {
139-
self.store.resume().await
137+
/// Reopen the store after a close.
138+
pub async fn reopen(&self) -> Result<(), MediaStoreError> {
139+
self.store.reopen().await
140140
}
141141

142142
/// Acquire a spin lock (see [`CrossProcessLock::spin_lock`]).

crates/matrix-sdk-base/src/media/store/traits.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ pub trait MediaStore: AsyncTraitDeps {
166166
/// If there is already an ongoing cleanup, this is a noop.
167167
async fn clean(&self) -> Result<(), Self::Error>;
168168

169-
/// Pause the store, releasing all held resources (database connections,
169+
/// Close the store, releasing all held resources (database connections,
170170
/// file descriptors, file locks).
171171
///
172172
/// In-flight operations complete before this method returns. After it
173-
/// returns, operations will fail until [`Self::resume()`] is called.
174-
async fn pause(&self) -> Result<(), Self::Error>;
173+
/// returns, operations will fail until [`Self::reopen()`] is called.
174+
async fn close(&self) -> Result<(), Self::Error>;
175175

176-
/// Resume the store after a [`Self::pause()`], re-acquiring database
176+
/// Reopen the store after a [`Self::close()`], re-acquiring database
177177
/// connections.
178-
async fn resume(&self) -> Result<(), Self::Error>;
178+
async fn reopen(&self) -> Result<(), Self::Error>;
179179

180180
/// Perform database optimizations if any are available, i.e. vacuuming in
181181
/// SQLite.
@@ -404,12 +404,12 @@ impl<T: MediaStore> MediaStore for EraseMediaStoreError<T> {
404404
self.0.clean().await.map_err(Into::into)
405405
}
406406

407-
async fn pause(&self) -> Result<(), Self::Error> {
408-
self.0.pause().await.map_err(Into::into)
407+
async fn close(&self) -> Result<(), Self::Error> {
408+
self.0.close().await.map_err(Into::into)
409409
}
410410

411-
async fn resume(&self) -> Result<(), Self::Error> {
412-
self.0.resume().await.map_err(Into::into)
411+
async fn reopen(&self) -> Result<(), Self::Error> {
412+
self.0.reopen().await.map_err(Into::into)
413413
}
414414

415415
async fn optimize(&self) -> Result<(), Self::Error> {

crates/matrix-sdk-base/src/store/memory_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ impl MemoryStore {
154154
impl StateStore for MemoryStore {
155155
type Error = StoreError;
156156

157-
async fn pause(&self) -> Result<(), Self::Error> {
157+
async fn close(&self) -> Result<(), Self::Error> {
158158
Ok(())
159159
}
160160

161-
async fn resume(&self) -> Result<(), Self::Error> {
161+
async fn reopen(&self) -> Result<(), Self::Error> {
162162
Ok(())
163163
}
164164

crates/matrix-sdk-base/src/store/traits.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,16 @@ pub trait StateStore: AsyncTraitDeps {
517517
thread_id: &EventId,
518518
) -> Result<Option<StoredThreadSubscription>, Self::Error>;
519519

520-
/// Pause the store, releasing all held resources (database connections,
520+
/// Close the store, releasing all held resources (database connections,
521521
/// file descriptors, file locks).
522522
///
523523
/// In-flight operations complete before this method returns. After it
524-
/// returns, operations will fail until [`Self::resume()`] is called.
525-
async fn pause(&self) -> Result<(), Self::Error>;
524+
/// returns, operations will fail until [`Self::reopen()`] is called.
525+
async fn close(&self) -> Result<(), Self::Error>;
526526

527-
/// Resume the store after a [`Self::pause()`], re-acquiring database
527+
/// Reopen the store after a [`Self::close()`], re-acquiring database
528528
/// connections.
529-
async fn resume(&self) -> Result<(), Self::Error>;
529+
async fn reopen(&self) -> Result<(), Self::Error>;
530530

531531
/// Perform database optimizations if any are available, i.e. vacuuming in
532532
/// SQLite.
@@ -831,12 +831,12 @@ impl<T: StateStore> StateStore for &T {
831831
(*self).load_thread_subscription(room, thread_id).await
832832
}
833833

834-
async fn pause(&self) -> Result<(), Self::Error> {
835-
(*self).pause().await
834+
async fn close(&self) -> Result<(), Self::Error> {
835+
(*self).close().await
836836
}
837837

838-
async fn resume(&self) -> Result<(), Self::Error> {
839-
(*self).resume().await
838+
async fn reopen(&self) -> Result<(), Self::Error> {
839+
(*self).reopen().await
840840
}
841841

842842
async fn optimize(&self) -> Result<(), Self::Error> {
@@ -1139,12 +1139,12 @@ impl<T: StateStore + ?Sized> StateStore for Arc<T> {
11391139
self.deref().load_thread_subscription(room, thread_id).await
11401140
}
11411141

1142-
async fn pause(&self) -> Result<(), Self::Error> {
1143-
self.deref().pause().await
1142+
async fn close(&self) -> Result<(), Self::Error> {
1143+
self.deref().close().await
11441144
}
11451145

1146-
async fn resume(&self) -> Result<(), Self::Error> {
1147-
self.deref().resume().await
1146+
async fn reopen(&self) -> Result<(), Self::Error> {
1147+
self.deref().reopen().await
11481148
}
11491149

11501150
async fn optimize(&self) -> Result<(), Self::Error> {
@@ -1472,12 +1472,12 @@ impl<T: StateStore> StateStore for EraseStateStoreError<T> {
14721472
self.0.remove_thread_subscription(room, thread_id).await.map_err(Into::into)
14731473
}
14741474

1475-
async fn pause(&self) -> Result<(), Self::Error> {
1476-
self.0.pause().await.map_err(Into::into)
1475+
async fn close(&self) -> Result<(), Self::Error> {
1476+
self.0.close().await.map_err(Into::into)
14771477
}
14781478

1479-
async fn resume(&self) -> Result<(), Self::Error> {
1480-
self.0.resume().await.map_err(Into::into)
1479+
async fn reopen(&self) -> Result<(), Self::Error> {
1480+
self.0.reopen().await.map_err(Into::into)
14811481
}
14821482

14831483
async fn optimize(&self) -> Result<(), Self::Error> {
@@ -1833,12 +1833,12 @@ impl<T: StateStore> StateStore for SaveLockedStateStore<T> {
18331833
self.store.remove_thread_subscription(room, thread_id).await
18341834
}
18351835

1836-
async fn pause(&self) -> Result<(), Self::Error> {
1837-
self.store.pause().await
1836+
async fn close(&self) -> Result<(), Self::Error> {
1837+
self.store.close().await
18381838
}
18391839

1840-
async fn resume(&self) -> Result<(), Self::Error> {
1841-
self.store.resume().await
1840+
async fn reopen(&self) -> Result<(), Self::Error> {
1841+
self.store.reopen().await
18421842
}
18431843

18441844
async fn optimize(&self) -> Result<(), Self::Error> {

crates/matrix-sdk-crypto/src/store/memorystore.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ type Result<T> = std::result::Result<T, Infallible>;
197197
impl CryptoStore for MemoryStore {
198198
type Error = Infallible;
199199

200-
async fn pause(&self) -> Result<()> {
200+
async fn close(&self) -> Result<()> {
201201
Ok(())
202202
}
203203

204-
async fn resume(&self) -> Result<()> {
204+
async fn reopen(&self) -> Result<()> {
205205
Ok(())
206206
}
207207

@@ -1400,12 +1400,12 @@ mod integration_tests {
14001400
impl CryptoStore for PersistentMemoryStore {
14011401
type Error = <MemoryStore as CryptoStore>::Error;
14021402

1403-
async fn pause(&self) -> Result<(), Self::Error> {
1404-
self.0.pause().await
1403+
async fn close(&self) -> Result<(), Self::Error> {
1404+
self.0.close().await
14051405
}
14061406

1407-
async fn resume(&self) -> Result<(), Self::Error> {
1408-
self.0.resume().await
1407+
async fn reopen(&self) -> Result<(), Self::Error> {
1408+
self.0.reopen().await
14091409
}
14101410

14111411
async fn load_account(&self) -> Result<Option<Account>, Self::Error> {

0 commit comments

Comments
 (0)