Skip to content

Commit 097ab2e

Browse files
authored
Replace full key with S3Location in file handles (#1539)
Internal change to directly propagate `S3Location` in file handles rather than the derived `full_key` string. The value is used for logging and error report, so we can postpone formatting the string until it is needed. ### Does this change impact existing behavior? Minor change in string formatting in logs. ### Does this change need a changelog entry? Does it require a version change? No. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). Signed-off-by: Alessandro Passaro <[email protected]>
1 parent 15fe956 commit 097ab2e

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

mountpoint-s3-fs/src/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,14 @@ where
689689
};
690690

691691
let complete_result = write_state
692-
.complete_if_in_progress(self, file_handle.ino, &file_handle.location.full_key())
692+
.complete_if_in_progress(self, file_handle.ino, &file_handle.location)
693693
.await;
694694
metrics::gauge!("fs.current_handles", "type" => "write").decrement(1.0);
695695

696696
match complete_result {
697697
Ok(upload_completed_async) => {
698698
if upload_completed_async {
699-
debug!(key = ?&file_handle.location.full_key(), "upload completed async after file was closed");
699+
debug!(key = %file_handle.location, "upload completed async after file was closed");
700700
}
701701
Ok(())
702702
}

mountpoint-s3-fs/src/fs/handles.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,10 @@ where
154154
Err(e) => Err(e.into()),
155155
},
156156
UploadState::Completed => {
157-
return Err(err!(
158-
libc::EIO,
159-
"upload already completed for key {:?}",
160-
handle.location.full_key()
161-
));
157+
return Err(err!(libc::EIO, "upload already completed for key {}", handle.location));
162158
}
163159
UploadState::Failed(e) => {
164-
return Err(err!(
165-
*e,
166-
"upload already aborted for key {:?}",
167-
handle.location.full_key()
168-
));
160+
return Err(err!(*e, "upload already aborted for key {}", handle.location));
169161
}
170162
};
171163

@@ -194,11 +186,7 @@ where
194186
match &self {
195187
UploadState::Completed => return Ok(()),
196188
UploadState::Failed(e) => {
197-
return Err(err!(
198-
*e,
199-
"upload already aborted for key {:?}",
200-
handle.location.full_key()
201-
));
189+
return Err(err!(*e, "upload already aborted for key {}", handle.location));
202190
}
203191
_ => {}
204192
};
@@ -210,7 +198,7 @@ where
210198
written_bytes,
211199
} => {
212200
let current_offset = request.current_offset();
213-
match Self::commit_append(request, &handle.location.full_key()).await {
201+
match Self::commit_append(request, &handle.location).await {
214202
Ok(etag) => {
215203
// Restart append request.
216204
let initial_etag = etag.or(initial_etag);
@@ -234,7 +222,7 @@ where
234222
}
235223
}
236224
UploadState::MPUInProgress { request, .. } => {
237-
let result = Self::complete_upload(fs, handle.ino, handle.location.full_key().as_ref(), request).await;
225+
let result = Self::complete_upload(fs, handle.ino, &handle.location, request).await;
238226
if let Err(e) = &result {
239227
*self = UploadState::Failed(e.to_errno());
240228
}
@@ -260,12 +248,12 @@ where
260248
}
261249
UploadState::MPUInProgress { request, .. } => {
262250
if request.size() == 0 {
263-
debug!(key=?handle.location.full_key(), "not completing upload because nothing was written yet");
251+
debug!(key=%handle.location, "not completing upload because nothing was written yet");
264252
return Ok(());
265253
}
266254
if !are_from_same_process(open_pid, pid) {
267255
debug!(
268-
key=?handle.location.full_key(),
256+
key=%handle.location,
269257
pid, open_pid, "not completing upload because current PID differs from PID at open",
270258
);
271259
return Ok(());
@@ -284,9 +272,9 @@ where
284272
let result = match std::mem::replace(self, UploadState::Completed) {
285273
UploadState::AppendInProgress {
286274
request, initial_etag, ..
287-
} => Self::complete_append(fs, handle.ino, &handle.location.full_key(), request, initial_etag).await,
275+
} => Self::complete_append(fs, handle.ino, &handle.location, request, initial_etag).await,
288276
UploadState::MPUInProgress { request, .. } => {
289-
Self::complete_upload(fs, handle.ino, &handle.location.full_key(), request).await
277+
Self::complete_upload(fs, handle.ino, &handle.location, request).await
290278
}
291279
UploadState::Failed(_) | UploadState::Completed => unreachable!("checked above"),
292280
};
@@ -304,7 +292,7 @@ where
304292
self,
305293
fs: &S3Filesystem<Client>,
306294
ino: InodeNo,
307-
key: &str,
295+
key: &S3Location,
308296
) -> Result<bool, Error> {
309297
match self {
310298
UploadState::AppendInProgress {
@@ -324,28 +312,28 @@ where
324312
async fn complete_upload(
325313
fs: &S3Filesystem<Client>,
326314
ino: InodeNo,
327-
key: &str,
315+
key: &S3Location,
328316
upload: UploadRequest<Client>,
329317
) -> Result<(), Error> {
330318
let size = upload.size();
331319
let (put_result, etag) = match upload.complete().await {
332320
Ok(result) => {
333-
debug!(etag=?result.etag.as_str(), ?key, size, "put succeeded");
321+
debug!(etag=?result.etag.as_str(), %key, size, "put succeeded");
334322
(Ok(()), Some(result.etag))
335323
}
336324
Err(e) => (Err(err!(libc::EIO, source:e, "put failed")), None),
337325
};
338326
if let Err(err) = fs.metablock.finish_writing(ino, etag).await {
339327
// Log the issue but still return put_result.
340-
error!(?err, ?key, "error updating the inode status");
328+
error!(?err, %key, "error updating the inode status");
341329
}
342330
put_result
343331
}
344332

345333
async fn complete_append(
346334
fs: &S3Filesystem<Client>,
347335
ino: InodeNo,
348-
key: &str,
336+
key: &S3Location,
349337
upload: AppendUploadRequest<Client>,
350338
initial_etag: Option<ETag>,
351339
) -> Result<(), Error> {
@@ -361,14 +349,14 @@ where
361349
}
362350
}
363351

364-
async fn commit_append(upload: AppendUploadRequest<Client>, key: &str) -> Result<Option<ETag>, Error> {
352+
async fn commit_append(upload: AppendUploadRequest<Client>, key: &S3Location) -> Result<Option<ETag>, Error> {
365353
match upload.complete().await {
366354
Ok(Some(result)) => {
367-
debug!(key, "put succeeded");
355+
debug!(%key, "put succeeded");
368356
Ok(Some(result.etag))
369357
}
370358
Ok(None) => {
371-
debug!(key, "no put required");
359+
debug!(%key, "no put required");
372360
Ok(None)
373361
}
374362
Err(e) => Err(err!(libc::EIO, source:e, "put failed")),

mountpoint-s3-fs/src/metablock/path.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ impl S3Location {
183183
}
184184
}
185185

186+
impl Display for S3Location {
187+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
188+
write!(
189+
f,
190+
"{}{} (bucket: {})",
191+
self.path.prefix, self.partial_key, self.path.bucket
192+
)
193+
}
194+
}
195+
186196
/// A valid name for an [Inode](super::Inode).
187197
#[derive(Debug, Clone, Copy)]
188198
pub struct ValidName<'a>(&'a str);

0 commit comments

Comments
 (0)