mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-30 23:13:09 +08:00
fix snapshot creation
This commit is contained in:
parent
4847884165
commit
a85e7abb0c
@ -18,10 +18,12 @@ pub fn to_tar_gz(src: &Path, dest: &Path) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> Result<(), Error> {
|
pub fn from_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> Result<(), Error> {
|
||||||
|
println!("inflating from {:?} to {:?}", src.as_ref(), dest.as_ref());
|
||||||
let f = File::open(&src)?;
|
let f = File::open(&src)?;
|
||||||
let gz = GzDecoder::new(f);
|
let gz = GzDecoder::new(f);
|
||||||
let mut ar = Archive::new(gz);
|
let mut ar = Archive::new(gz);
|
||||||
create_dir_all(&dest)?;
|
create_dir_all(&dest)?;
|
||||||
ar.unpack(&dest)?;
|
ar.unpack(&dest)?;
|
||||||
|
println!("here");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,11 @@ impl<S: IndexStore + Sync + Send> IndexActor<S> {
|
|||||||
.map_err(|e| IndexError::Error(e.into()))?;
|
.map_err(|e| IndexError::Error(e.into()))?;
|
||||||
|
|
||||||
if let Some(index) = self.store.get(uuid).await? {
|
if let Some(index) = self.store.get(uuid).await? {
|
||||||
let index_path = path.join(format!("index-{}", uuid));
|
let mut index_path = path.join(format!("index-{}", uuid));
|
||||||
|
create_dir_all(&index_path)
|
||||||
|
.await
|
||||||
|
.map_err(|e| IndexError::Error(e.into()))?;
|
||||||
|
index_path.push("data.mdb");
|
||||||
spawn_blocking(move || -> anyhow::Result<()> {
|
spawn_blocking(move || -> anyhow::Result<()> {
|
||||||
// Get write txn to wait for ongoing write transaction before snapshot.
|
// Get write txn to wait for ongoing write transaction before snapshot.
|
||||||
let _txn = index.write_txn()?;
|
let _txn = index.write_txn()?;
|
||||||
|
@ -380,13 +380,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot(&self, txn: &mut heed::RwTxn, path: impl AsRef<Path>, uuid: Uuid) -> anyhow::Result<()> {
|
pub fn snapshot(&self, txn: &mut heed::RwTxn, path: impl AsRef<Path>, uuid: Uuid) -> anyhow::Result<()> {
|
||||||
println!("snapshoting updates in {:?}", path.as_ref());
|
|
||||||
let update_path = path.as_ref().join("updates");
|
let update_path = path.as_ref().join("updates");
|
||||||
create_dir_all(&update_path)?;
|
create_dir_all(&update_path)?;
|
||||||
|
|
||||||
let snapshot_path = update_path.join(format!("update-{}", uuid));
|
let mut snapshot_path = update_path.join(format!("update-{}", uuid));
|
||||||
// acquire write lock to prevent further writes during snapshot
|
// acquire write lock to prevent further writes during snapshot
|
||||||
println!("acquired lock");
|
create_dir_all(&snapshot_path)?;
|
||||||
|
snapshot_path.push("data.mdb");
|
||||||
|
|
||||||
// create db snapshot
|
// create db snapshot
|
||||||
self.env.copy_to_path(&snapshot_path, CompactionOption::Enabled)?;
|
self.env.copy_to_path(&snapshot_path, CompactionOption::Enabled)?;
|
||||||
|
@ -253,8 +253,9 @@ impl HeedUuidStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_snapshot(snapshot: impl AsRef<Path>, path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
fn from_snapshot(snapshot: impl AsRef<Path>, path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
||||||
let snapshot = snapshot.as_ref().join("uuids");
|
let src = snapshot.as_ref().join("uuids");
|
||||||
compression::from_tar_gz(snapshot, &path)?;
|
let dst = path.as_ref().join("uuids");
|
||||||
|
compression::from_tar_gz(src, dst)?;
|
||||||
Self::new(path)
|
Self::new(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,7 +348,9 @@ impl UuidStore for HeedUuidStore {
|
|||||||
let uuid = Uuid::from_slice(uuid)?;
|
let uuid = Uuid::from_slice(uuid)?;
|
||||||
entries.push(uuid)
|
entries.push(uuid)
|
||||||
}
|
}
|
||||||
path.push("uuids");
|
path.push("index_uuids");
|
||||||
|
create_dir_all(&path).unwrap();
|
||||||
|
path.push("data.mdb");
|
||||||
env.copy_to_path(path, CompactionOption::Enabled)?;
|
env.copy_to_path(path, CompactionOption::Enabled)?;
|
||||||
Ok(entries)
|
Ok(entries)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user