Conversation
| ) -> CollectionResult<()> { | ||
| let local_read = self.local.read().await; | ||
|
|
||
| ) -> impl Future<Output = CollectionResult<()>> + use<> { |
| shard_id: ShardId, | ||
| temp_dir: &Path, | ||
| ) -> CollectionResult<SnapshotDescription> { | ||
| ) -> CollectionResult<impl Future<Output = CollectionResult<SnapshotDescription>> + use<>> { |
There was a problem hiding this comment.
this is the second main change
| manifest: Option<SnapshotManifest>, | ||
| save_wal: bool, | ||
| ) -> CollectionResult<()> { | ||
| ) -> CollectionResult<impl Future<Output = CollectionResult<()>> + use<>> { |
| manifest: Option<SnapshotManifest>, | ||
| save_wal: bool, | ||
| ) -> CollectionResult<()> { | ||
| ) -> CollectionResult<impl Future<Output = CollectionResult<()>> + use<>> { |
There was a problem hiding this comment.
Would + 'static work here? IMO, it's less weird/niche than + use<>, I'd prefer to use 'static if it works.
| ) -> CollectionResult<impl Future<Output = CollectionResult<()>> + use<>> { | |
| ) -> CollectionResult<impl Future<Output = CollectionResult<()>> + 'static> { |
There was a problem hiding this comment.
I would argue that use<> is more precise compare to 'static. We declare that future doesn't capture any lifetimes.
There was a problem hiding this comment.
Maybe. Though, I think in this case both are equivalent. But also, why do we care? If we accidentally capture non-static lifetime or smth, we would get a compilation error anyway. IMO, rule of thumb is "use strictly necessary, least restrictive bound".
And also 'static is better recognized than use<>. I'd prefer 'static as long as it works.
| let local_read = self.local.read().await; | ||
|
|
||
| let shard_config = ShardConfig::new_replica_set(); | ||
| shard_config.save_to_tar(tar).await?; | ||
| Ok(()) | ||
| let maybe_local_snapshot_future = if let Some(local) = &*local_read { | ||
| Some( | ||
| local | ||
| .get_snapshot_creator(&temp_path, &tar, format, manifest, save_wal) | ||
| .await?, | ||
| ) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| drop(local_read); |
There was a problem hiding this comment.
🙅♀️ no explicit drops 🚫
I'd also just call it create_snapshot instead of maybe_local_snapshot_future
| let local_read = self.local.read().await; | |
| let shard_config = ShardConfig::new_replica_set(); | |
| shard_config.save_to_tar(tar).await?; | |
| Ok(()) | |
| let maybe_local_snapshot_future = if let Some(local) = &*local_read { | |
| Some( | |
| local | |
| .get_snapshot_creator(&temp_path, &tar, format, manifest, save_wal) | |
| .await?, | |
| ) | |
| } else { | |
| None | |
| }; | |
| drop(local_read); | |
| let maybe_local_snapshot_future = if let Some(local) = &*self.local.read().await { | |
| let create_snapshot = local | |
| .get_snapshot_creator(&temp_path, &tar, format, manifest, save_wal) | |
| .await?; | |
| Some(create_snapshot) | |
| } else { | |
| None | |
| }; |
There was a problem hiding this comment.
this one is actually not necessary, and it will work the same way without drop. But I prefer to keep the drop to make it explicit.
There was a problem hiding this comment.
if let Some(_) = local.read() { ... } is still simpler. 🤷♀️
| pub async fn create_snapshot( | ||
| &self, | ||
| _temp_path: &Path, | ||
| _tar: &tar_ext::BuilderExt, | ||
| _format: SnapshotFormat, | ||
| _manifest: Option<SnapshotManifest>, | ||
| _save_wal: bool, | ||
| ) -> CollectionResult<()> { | ||
| self.dummy() | ||
| ) -> CollectionError { | ||
| self.dummy_error() | ||
| } |
There was a problem hiding this comment.
Ah, yeah, I see. Then, maybe, remove create_snapshot at all and just do dummy.dummy_error() in that match? This does not make any sense at all.
ffuugoo
left a comment
There was a problem hiding this comment.
Overall, LGTM, I don't see any major issues. Mostly just code style/structuring.
| Shard::Dummy(dummy_shard) => { | ||
| dummy_shard | ||
| return Err(dummy_shard | ||
| .create_snapshot(temp_path, tar, format, manifest, save_wal) | ||
| .await | ||
| .await); | ||
| } |
There was a problem hiding this comment.
Just do return Err(dummy_shard.dummy_error()) and remove DummyShard::create_snapshot method entirely?
* refactor shard.create_snapshot to own everything necessary in the future for snapshotting * do not lock shards_holder and replica_set during snapshot * separate locks and snapshot creation all the way down * separate locks and snapshot creation even further on the local shard level * final touches * minor review fixes
Fixes: #7489
Unblocks: #7510
[AI-free]