mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
lance worker: drop guard aborts on a failed probe, keeps another's manifest
An upload whose check before completing failed returned the error without aborting, leaving its parts behind on S3. A manifest write found dropped or replaced was deleted at its path even when a table created again had since written its own manifest there. complete now aborts on a failed probe too. The rollback deletes the manifest only while its e-tag is the one this write got. Object stores offer no conditional delete, so a table created again between that HEAD and the delete is still not covered. a_failed_probe_aborts_an_upload and a_rollback_keeps_the_manifest_of_a_table_created_again failed before this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK
This commit is contained in:
1 parent
ea7307f69c
commit
d2e66d3a52
2 files changed
+124
-26
No files matched your search
@@ -179,13 +179,13 @@ impl MultipartUpload for GuardedUpload {
|
||||
}
|
||||
|
||||
async fn complete(&mut self) -> Result<PutResult> {
|
||||
if let Found::Dropped(error) | Found::Replaced(error) =
|
||||
self.guard.find(&self.location).await?
|
||||
{
|
||||
let _ = self.inner.abort().await;
|
||||
return Err(error);
|
||||
}
|
||||
self.inner.complete().await
|
||||
// A failed probe aborts too: the parts would outlive the upload.
|
||||
let error = match self.guard.find(&self.location).await {
|
||||
Ok(Found::Table) => return self.inner.complete().await,
|
||||
Ok(Found::Dropped(error) | Found::Replaced(error)) | Err(error) => error,
|
||||
};
|
||||
let _ = self.inner.abort().await;
|
||||
Err(error)
|
||||
}
|
||||
|
||||
async fn abort(&mut self) -> Result<()> {
|
||||
@@ -211,11 +211,20 @@ impl ObjectStore for Guarded {
|
||||
let put = self.inner.put_opts(location, payload, opts).await?;
|
||||
// A drop can land between the check and the write. A manifest is
|
||||
// what makes the table readable again, so look once more and take
|
||||
// it back if the table is gone; a failed probe leaves it.
|
||||
// it back if the table is gone; a failed probe leaves it. A table
|
||||
// created again since may have written its own manifest there:
|
||||
// only this write's is taken back.
|
||||
if is_manifest(location)
|
||||
&& let Ok(Found::Dropped(error) | Found::Replaced(error)) = self.find(location).await
|
||||
{
|
||||
let _ = self.inner.delete(location).await;
|
||||
let ours = match (&put.e_tag, self.inner.head(location).await) {
|
||||
(Some(wrote), Ok(meta)) => meta.e_tag.as_ref() == Some(wrote),
|
||||
(_, Err(object_store::Error::NotFound { .. })) => false,
|
||||
_ => true,
|
||||
};
|
||||
if ours {
|
||||
let _ = self.inner.delete(location).await;
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
self.committed(location, put.e_tag.clone());
|
||||
|
||||
@@ -382,9 +382,7 @@ fn table_root(dataset: &Dataset) -> Path {
|
||||
async fn a_multipart_upload_does_not_complete_into_a_dropped_table() {
|
||||
let dir = tempfile::TempDir::new().unwrap();
|
||||
table(&dir, 1).await;
|
||||
let s3_like: Arc<dyn WrappingObjectStore> = Arc::new(FailHeadAfterManifest {
|
||||
armed: Arc::new(AtomicBool::new(false)),
|
||||
});
|
||||
let s3_like: Arc<dyn WrappingObjectStore> = Arc::new(S3Like::default());
|
||||
let job = crate::dataset::open_guarded(&guarded_description(&dir), Some(s3_like))
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -404,6 +402,56 @@ async fn a_multipart_upload_does_not_complete_into_a_dropped_table() {
|
||||
assert!(files(dir.path()).is_empty(), "{:?}", files(dir.path()));
|
||||
}
|
||||
|
||||
/// An upload whose last probe fails is aborted, not left with its parts.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn a_failed_probe_aborts_an_upload() {
|
||||
let dir = tempfile::TempDir::new().unwrap();
|
||||
table(&dir, 1).await;
|
||||
let s3_like = S3Like::default();
|
||||
let (armed, aborted) = (s3_like.armed.clone(), s3_like.aborted.clone());
|
||||
let s3_like: Arc<dyn WrappingObjectStore> = Arc::new(s3_like);
|
||||
let job = crate::dataset::open_guarded(&guarded_description(&dir), Some(s3_like))
|
||||
.await
|
||||
.unwrap();
|
||||
let store = job.object_store(None).await.unwrap().inner.clone();
|
||||
let path = table_root(&job).child("data").child("late.lance");
|
||||
let mut upload = store.put_multipart(&path).await.unwrap();
|
||||
upload
|
||||
.put_part(PutPayload::from(vec![0u8; 16]))
|
||||
.await
|
||||
.unwrap();
|
||||
armed.store(true, Ordering::SeqCst);
|
||||
assert!(upload.complete().await.is_err());
|
||||
assert!(aborted.load(Ordering::SeqCst), "the upload was left open");
|
||||
}
|
||||
|
||||
/// A table created again, through the version a job just wrote, between
|
||||
/// that write and its check keeps its own manifest at that path.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn a_rollback_keeps_the_manifest_of_a_table_created_again() {
|
||||
let dir = tempfile::TempDir::new().unwrap();
|
||||
table(&dir, 1).await;
|
||||
let s3_like: Arc<dyn WrappingObjectStore> = Arc::new(S3Like {
|
||||
recreate: Some((dir.path().to_path_buf(), Arc::new(AtomicBool::new(false)))),
|
||||
..Default::default()
|
||||
});
|
||||
let mut job = crate::dataset::open_guarded(&guarded_description(&dir), Some(s3_like))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(job.version().version, 1);
|
||||
assert!(
|
||||
job.update_config([("seaweedfs.test", "job")])
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let again = Dataset::open(dir.path().to_str().unwrap()).await.unwrap();
|
||||
assert_eq!(again.version().version, 2);
|
||||
assert_eq!(
|
||||
again.config().get("seaweedfs.test").map(String::as_str),
|
||||
Some("again")
|
||||
);
|
||||
}
|
||||
|
||||
/// A cleanup that picked its paths before the drop does not delete the files
|
||||
/// of the table created again there.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
@@ -439,8 +487,9 @@ async fn a_cleanup_does_not_delete_a_table_created_again() {
|
||||
async fn a_failed_probe_does_not_take_back_a_commit() {
|
||||
let dir = tempfile::TempDir::new().unwrap();
|
||||
table(&dir, 1).await;
|
||||
let flaky: Arc<dyn WrappingObjectStore> = Arc::new(FailHeadAfterManifest {
|
||||
armed: Arc::new(AtomicBool::new(false)),
|
||||
let flaky: Arc<dyn WrappingObjectStore> = Arc::new(S3Like {
|
||||
fail_head_after_manifest: true,
|
||||
..Default::default()
|
||||
});
|
||||
let mut job = crate::dataset::open_guarded(&guarded_description(&dir), Some(flaky))
|
||||
.await
|
||||
@@ -452,36 +501,47 @@ async fn a_failed_probe_does_not_take_back_a_commit() {
|
||||
}
|
||||
|
||||
/// Behaves as an object store, not a file system: a multipart upload holds
|
||||
/// its parts until it completes. Fails one HEAD after a manifest is written,
|
||||
/// as a timeout would.
|
||||
#[derive(Debug)]
|
||||
struct FailHeadAfterManifest {
|
||||
/// its parts until it completes, and records an abort. Optionally fails one
|
||||
/// HEAD after a manifest is written, as a timeout would, or creates the table
|
||||
/// again, through two versions, right after the first manifest is written.
|
||||
#[derive(Debug, Default)]
|
||||
struct S3Like {
|
||||
fail_head_after_manifest: bool,
|
||||
/// The next HEAD fails.
|
||||
armed: Arc<AtomicBool>,
|
||||
aborted: Arc<AtomicBool>,
|
||||
recreate: Option<(PathBuf, Arc<AtomicBool>)>,
|
||||
}
|
||||
|
||||
impl WrappingObjectStore for FailHeadAfterManifest {
|
||||
impl WrappingObjectStore for S3Like {
|
||||
fn wrap(&self, _prefix: &str, original: Arc<dyn ObjectStore>) -> Arc<dyn ObjectStore> {
|
||||
Arc::new(FailingHead {
|
||||
Arc::new(S3LikeStore {
|
||||
inner: original,
|
||||
fail_head_after_manifest: self.fail_head_after_manifest,
|
||||
armed: self.armed.clone(),
|
||||
aborted: self.aborted.clone(),
|
||||
recreate: self.recreate.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FailingHead {
|
||||
struct S3LikeStore {
|
||||
inner: Arc<dyn ObjectStore>,
|
||||
fail_head_after_manifest: bool,
|
||||
armed: Arc<AtomicBool>,
|
||||
aborted: Arc<AtomicBool>,
|
||||
recreate: Option<(PathBuf, Arc<AtomicBool>)>,
|
||||
}
|
||||
|
||||
impl fmt::Display for FailingHead {
|
||||
impl fmt::Display for S3LikeStore {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "FailingHead({})", self.inner)
|
||||
write!(f, "S3Like({})", self.inner)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ObjectStore for FailingHead {
|
||||
impl ObjectStore for S3LikeStore {
|
||||
async fn put_opts(
|
||||
&self,
|
||||
location: &Path,
|
||||
@@ -490,7 +550,19 @@ impl ObjectStore for FailingHead {
|
||||
) -> Result<PutResult> {
|
||||
let put = self.inner.put_opts(location, payload, opts).await?;
|
||||
if location.extension() == Some("manifest") {
|
||||
self.armed.store(true, Ordering::SeqCst);
|
||||
if self.fail_head_after_manifest {
|
||||
self.armed.store(true, Ordering::SeqCst);
|
||||
}
|
||||
if let Some((dir, fired)) = &self.recreate
|
||||
&& !fired.swap(true, Ordering::SeqCst)
|
||||
{
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
let mut again = create_empty(dir).await;
|
||||
again
|
||||
.update_config([("seaweedfs.test", "again")])
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
Ok(put)
|
||||
}
|
||||
@@ -503,12 +575,13 @@ impl ObjectStore for FailingHead {
|
||||
inner: self.inner.clone(),
|
||||
location: location.clone(),
|
||||
parts: Vec::new(),
|
||||
aborted: self.aborted.clone(),
|
||||
}))
|
||||
}
|
||||
async fn get_opts(&self, location: &Path, options: GetOptions) -> Result<GetResult> {
|
||||
if options.head && self.armed.swap(false, Ordering::SeqCst) {
|
||||
return Err(object_store::Error::Generic {
|
||||
store: "FailingHead",
|
||||
store: "S3Like",
|
||||
source: "timed out".into(),
|
||||
});
|
||||
}
|
||||
@@ -550,6 +623,7 @@ struct HeldParts {
|
||||
inner: Arc<dyn ObjectStore>,
|
||||
location: Path,
|
||||
parts: Vec<Bytes>,
|
||||
aborted: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -564,6 +638,21 @@ impl MultipartUpload for HeldParts {
|
||||
}
|
||||
async fn abort(&mut self) -> Result<()> {
|
||||
self.parts.clear();
|
||||
self.aborted.store(true, Ordering::SeqCst);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// An empty table at `dir`.
|
||||
async fn create_empty(dir: &std::path::Path) -> Dataset {
|
||||
Dataset::write(
|
||||
arrow_array::RecordBatchIterator::new(
|
||||
Vec::<std::result::Result<arrow_array::RecordBatch, arrow_schema::ArrowError>>::new(),
|
||||
Arc::new(crate::metadata_index::tests::lifecycle::base_schema()),
|
||||
),
|
||||
dir.to_str().unwrap(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
Reference in new issue
Block a user