|
10 | 10 |
|
11 | 11 | use std::path::PathBuf;
|
12 | 12 | use std::time::SystemTime;
|
13 |
| - |
14 | 13 | use tokio::sync::{oneshot, watch};
|
15 | 14 | use tracing::{debug, warn};
|
16 | 15 |
|
@@ -39,49 +38,80 @@ impl SnapshotPartitionTask {
|
39 | 38 | "Creating partition snapshot"
|
40 | 39 | );
|
41 | 40 |
|
42 |
| - let snapshot_id = SnapshotId::new(); |
43 |
| - let snapshot = self |
44 |
| - .partition_store_manager |
45 |
| - .export_partition_snapshot(self.partition_id, snapshot_id, self.snapshot_base_path) |
46 |
| - .await?; |
47 |
| - |
48 |
| - let metadata = write_snapshot_metadata_header( |
49 |
| - snapshot_id, |
| 41 | + let result = create_snapshot_inner( |
| 42 | + self.partition_store_manager, |
50 | 43 | self.cluster_name,
|
51 | 44 | self.node_name,
|
52 | 45 | self.partition_id,
|
53 |
| - snapshot, |
| 46 | + self.snapshot_base_path, |
| 47 | + self.archived_lsn_sender, |
54 | 48 | )
|
55 |
| - .await?; |
| 49 | + .await; |
56 | 50 |
|
57 |
| - // todo(pavel): SnapshotRepository integration will go in here in a future PR |
| 51 | + match result { |
| 52 | + Ok(metadata) => { |
| 53 | + let _ = self |
| 54 | + .result_sender |
| 55 | + .send(Ok(metadata.snapshot_id)) |
| 56 | + .inspect_err(|err| { |
| 57 | + warn!( |
| 58 | + "Failed to send snapshot acknowledgement after snapshot {} was successfully created: {:?}", |
| 59 | + metadata.snapshot_id, |
| 60 | + err |
| 61 | + ) |
| 62 | + }); |
58 | 63 |
|
59 |
| - self.archived_lsn_sender |
60 |
| - .send(Some(metadata.min_applied_lsn))?; |
61 |
| - |
62 |
| - let _ = self |
63 |
| - .result_sender |
64 |
| - .send(Ok(metadata.snapshot_id)) |
65 |
| - .inspect_err(|err| { |
| 64 | + debug!( |
| 65 | + partition_id = %self.partition_id, |
| 66 | + snapshot_id = %metadata.snapshot_id, |
| 67 | + archived_lsn = %metadata.min_applied_lsn, |
| 68 | + "Partition snapshot created" |
| 69 | + ); |
| 70 | + Ok(metadata.snapshot_id) |
| 71 | + } |
| 72 | + Err(err) => { |
66 | 73 | warn!(
|
67 |
| - "Failed to send snapshot acknowledgement after snapshot {} was successfully created: {:?}", |
68 |
| - metadata.snapshot_id, |
| 74 | + partition_id = %self.partition_id, |
| 75 | + "Failed to create partition snapshot: {}", |
69 | 76 | err
|
70 |
| - ) |
71 |
| - }); |
72 |
| - |
73 |
| - debug!( |
74 |
| - partition_id = %self.partition_id, |
75 |
| - snapshot_id = %metadata.snapshot_id, |
76 |
| - archived_lsn = %metadata.min_applied_lsn, |
77 |
| - "Partition snapshot created" |
78 |
| - ); |
| 77 | + ); |
79 | 78 |
|
80 |
| - Ok(metadata.snapshot_id) |
| 79 | + Err(err) |
| 80 | + } |
| 81 | + } |
81 | 82 | }
|
82 | 83 | }
|
83 | 84 |
|
84 |
| -pub async fn write_snapshot_metadata_header( |
| 85 | +async fn create_snapshot_inner( |
| 86 | + partition_store_manager: PartitionStoreManager, |
| 87 | + cluster_name: String, |
| 88 | + node_name: String, |
| 89 | + partition_id: PartitionId, |
| 90 | + snapshot_base_path: PathBuf, |
| 91 | + archived_lsn_sender: watch::Sender<Option<Lsn>>, |
| 92 | +) -> anyhow::Result<PartitionSnapshotMetadata> { |
| 93 | + let snapshot_id = SnapshotId::new(); |
| 94 | + let snapshot = partition_store_manager |
| 95 | + .export_partition_snapshot(partition_id, snapshot_id, snapshot_base_path.clone()) |
| 96 | + .await?; |
| 97 | + |
| 98 | + let metadata = write_snapshot_metadata_header( |
| 99 | + snapshot_id, |
| 100 | + cluster_name, |
| 101 | + node_name, |
| 102 | + partition_id, |
| 103 | + snapshot, |
| 104 | + ) |
| 105 | + .await?; |
| 106 | + |
| 107 | + // todo(pavel): SnapshotRepository integration will go in here in a future PR |
| 108 | + |
| 109 | + archived_lsn_sender.send(Some(metadata.min_applied_lsn))?; |
| 110 | + |
| 111 | + Ok(metadata) |
| 112 | +} |
| 113 | + |
| 114 | +async fn write_snapshot_metadata_header( |
85 | 115 | snapshot_id: SnapshotId,
|
86 | 116 | cluster_name: String,
|
87 | 117 | node_name: String,
|
|
0 commit comments