From 96276a8af6a157856532b6a68794976900e2f347 Mon Sep 17 00:00:00 2001 From: Durham Goode Date: Tue, 28 Jun 2022 12:50:37 -0700 Subject: [PATCH] Persist the in-progress checkout pid Summary: The in-progress checkout pid was always serialized to the snapshot file, but we ignored it when reading the file. Let's read it and keep it in memory. This will be used by the next diff to determine if the in progress checkout is resumable or not. Reviewed By: xavierd Differential Revision: D37006722 fbshipit-source-id: 2fa374b309eda36e280bcd352abdaf03193d167e --- eden/fs/config/CheckoutConfig.cpp | 5 ++--- eden/fs/config/ParentCommit.cpp | 15 +++++++++++++++ eden/fs/config/ParentCommit.h | 6 ++++++ eden/fs/config/test/CheckoutConfigTest.cpp | 5 +++-- eden/fs/inodes/EdenMount.cpp | 7 +++++-- eden/fs/inodes/EdenMount.h | 1 + 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/eden/fs/config/CheckoutConfig.cpp b/eden/fs/config/CheckoutConfig.cpp index 7111069d3b..7e86f15f06 100644 --- a/eden/fs/config/CheckoutConfig.cpp +++ b/eden/fs/config/CheckoutConfig.cpp @@ -167,8 +167,7 @@ ParentCommit CheckoutConfig::getParentCommit() const { } case kSnapshotFormatCheckoutInProgressVersion: { - // Skip the PID - cursor.skip(sizeof(uint32_t)); + auto pid = cursor.readBE(); auto fromLength = cursor.readBE(); std::string fromRootId = cursor.readFixedString(fromLength); @@ -177,7 +176,7 @@ ParentCommit CheckoutConfig::getParentCommit() const { std::string toRootId = cursor.readFixedString(toLength); return ParentCommit::CheckoutInProgress{ - RootId{std::move(fromRootId)}, RootId{std::move(toRootId)}}; + RootId{std::move(fromRootId)}, RootId{std::move(toRootId)}, pid}; } case kSnapshotFormatWorkingCopyParentAndCheckedOutRevisionVersion: { diff --git a/eden/fs/config/ParentCommit.cpp b/eden/fs/config/ParentCommit.cpp index a0c4ec502e..be2b03b0c1 100644 --- a/eden/fs/config/ParentCommit.cpp +++ b/eden/fs/config/ParentCommit.cpp @@ -14,6 +14,21 @@ bool ParentCommit::isCheckoutInProgress() const { return std::holds_alternative(state_); } +std::optional ParentCommit::getInProgressPid() const { + return std::visit( + [](auto&& state) -> std::optional { + using StateType = std::decay_t; + if constexpr (std::is_same_v< + StateType, + WorkingCopyParentAndCheckedOutRevision>) { + return std::nullopt; + } else { + return state.pid; + } + }, + state_); +} + std::optional ParentCommit::getLastCheckoutId( RootIdPreference preference) const { return std::visit( diff --git a/eden/fs/config/ParentCommit.h b/eden/fs/config/ParentCommit.h index c355bae176..5c0819c134 100644 --- a/eden/fs/config/ParentCommit.h +++ b/eden/fs/config/ParentCommit.h @@ -33,6 +33,11 @@ class ParentCommit { */ bool isCheckoutInProgress() const; + /** + * Returns the pid of the process currently doing a checkout. + */ + std::optional getInProgressPid() const; + /** * Since the parent commit might contain multiple RootId, allows chosing * which one should be preferred. @@ -68,6 +73,7 @@ class ParentCommit { struct CheckoutInProgress { RootId from; RootId to; + pid_t pid; }; /** diff --git a/eden/fs/config/test/CheckoutConfigTest.cpp b/eden/fs/config/test/CheckoutConfigTest.cpp index b8addc69c1..a165b43928 100644 --- a/eden/fs/config/test/CheckoutConfigTest.cpp +++ b/eden/fs/config/test/CheckoutConfigTest.cpp @@ -162,7 +162,8 @@ TEST_F(CheckoutConfigTest, testInProgress) { ParentCommit inProgress = ParentCommit::CheckoutInProgress{ RootId{"99887766554433221100aabbccddeeffabcdef99"}, - RootId{"fedcba99887766554433221100ffeeddccbbaa99"}}; + RootId{"fedcba99887766554433221100ffeeddccbbaa99"}, + 123}; auto parent = config->getParentCommit(); EXPECT_EQ(inProgress, parent); @@ -174,7 +175,7 @@ TEST_F(CheckoutConfigTest, testInProgressRoundtrip) { auto from = RootId{"99887766554433221100aabbccddeeffabcdef99"}; auto to = RootId{"fedcba998887766554433221100ffeeddccbbaa99"}; - ParentCommit inProgress = ParentCommit::CheckoutInProgress{from, to}; + ParentCommit inProgress = ParentCommit::CheckoutInProgress{from, to, 123}; config->setCheckoutInProgress(from, to); diff --git a/eden/fs/inodes/EdenMount.cpp b/eden/fs/inodes/EdenMount.cpp index 806698c06f..db48f8a541 100644 --- a/eden/fs/inodes/EdenMount.cpp +++ b/eden/fs/inodes/EdenMount.cpp @@ -292,7 +292,8 @@ FOLLY_NODISCARD folly::Future EdenMount::initialize( checkoutOriginalDest = parentCommit.getLastCheckoutId( ParentCommit::RootIdPreference::To), checkoutOriginalSrc = parentCommit.getLastCheckoutId( - ParentCommit::RootIdPreference::From)]( + ParentCommit::RootIdPreference::From), + checkoutPid = parentCommit.getInProgressPid()]( std::shared_ptr parentTree) mutable { std::optional> originalCheckoutTrees = std::nullopt; @@ -305,7 +306,9 @@ FOLLY_NODISCARD folly::Future EdenMount::initialize( parentTree, workingCopyParentRootId, inProgressCheckout, - originalCheckoutTrees}; + originalCheckoutTrees, + checkoutPid, + }; // Record the transition from no snapshot to the current snapshot in // the journal. This also sets things up so that we can carry the diff --git a/eden/fs/inodes/EdenMount.h b/eden/fs/inodes/EdenMount.h index 57812db72c..f4ca4436e0 100644 --- a/eden/fs/inodes/EdenMount.h +++ b/eden/fs/inodes/EdenMount.h @@ -1155,6 +1155,7 @@ class EdenMount : public std::enable_shared_from_this { RootId workingCopyParentRootId; bool checkoutInProgress = false; std::optional> checkoutOriginalTrees; + std::optional checkoutPid; }; /**