Re-open the database, after ensuring that all data has been flushed to disk (if the database was created via [`Self::durable`]).
(self)
| 2023 | /// Re-open the database, after ensuring that all data has been flushed |
| 2024 | /// to disk (if the database was created via [`Self::durable`]). |
| 2025 | pub fn reopen(self) -> Result<Self, DBError> { |
| 2026 | if let Some(rt) = self.runtime() { |
| 2027 | rt.block_on(self.db.shutdown()); |
| 2028 | } |
| 2029 | drop(self.db); |
| 2030 | |
| 2031 | if let Some(DurableState { |
| 2032 | durability, |
| 2033 | rt, |
| 2034 | replica_dir, |
| 2035 | }) = self.durable |
| 2036 | { |
| 2037 | rt.block_on(durability.close()); |
| 2038 | drop(durability); |
| 2039 | // Enter the runtime so that `Self::durable_internal` can spawn a `SnapshotWorker`. |
| 2040 | let _rt = rt.enter(); |
| 2041 | let (db, handle) = Self::durable_internal(&replica_dir, rt.handle().clone(), self.want_snapshot_repo)?; |
| 2042 | let durable = DurableState { |
| 2043 | durability: handle, |
| 2044 | rt, |
| 2045 | replica_dir, |
| 2046 | }; |
| 2047 | |
| 2048 | Ok(Self { |
| 2049 | db: Arc::new(db), |
| 2050 | durable: Some(durable), |
| 2051 | ..self |
| 2052 | }) |
| 2053 | } else { |
| 2054 | let db = Self::in_memory_internal().map(Arc::new)?; |
| 2055 | Ok(Self { db, ..self }) |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | pub fn with_row_count(self, row_count: RowCountFn) -> Self { |
| 2060 | let db = Arc::into_inner(self.db).expect("TestDB::db should be unique"); |