@@ -892,7 +892,6 @@ Result<int32_t> FileStoreCommitImpl::TryCommit(
892892 Snapshot::CommitKind commit_kind, bool detect_conflicts) {
893893 int32_t retry_count = 0 ;
894894 int64_t start_millis = DateTimeUtils::GetCurrentUTCTimeUs () / 1000 ;
895- std::optional<int64_t > retry_start_snapshot_id;
896895 while (true ) {
897896 PAIMON_ASSIGN_OR_RAISE (std::optional<Snapshot> latest_snapshot,
898897 snapshot_manager_->LatestSnapshot ());
@@ -902,13 +901,10 @@ Result<int32_t> FileStoreCommitImpl::TryCommit(
902901 bool commit_success,
903902 TryCommitOnce (commit_changes->delta_files , commit_changes->changelog_files ,
904903 commit_changes->index_entries , identifier, watermark, properties,
905- commit_kind, latest_snapshot, detect_conflicts, retry_start_snapshot_id ));
904+ commit_kind, latest_snapshot, detect_conflicts));
906905 if (commit_success) {
907906 break ;
908907 }
909- retry_start_snapshot_id = latest_snapshot
910- ? std::optional<int64_t >(latest_snapshot.value ().Id () + 1 )
911- : std::optional<int64_t >(Snapshot::FIRST_SNAPSHOT_ID );
912908 int64_t current_millis = DateTimeUtils::GetCurrentUTCTimeUs () / 1000 ;
913909 if (current_millis - start_millis > options_.GetCommitTimeout () ||
914910 retry_count >= options_.GetCommitMaxRetries ()) {
@@ -923,26 +919,6 @@ Result<int32_t> FileStoreCommitImpl::TryCommit(
923919 return retry_count + 1 ;
924920}
925921
926- Result<bool > FileStoreCommitImpl::CheckCommitted (const std::optional<Snapshot>& latest_snapshot,
927- std::optional<int64_t > retry_start_snapshot_id,
928- int64_t identifier,
929- const Snapshot::CommitKind& commit_kind) const {
930- if (!latest_snapshot || !retry_start_snapshot_id ||
931- retry_start_snapshot_id.value () > latest_snapshot.value ().Id ()) {
932- return false ;
933- }
934-
935- for (int64_t snapshot_id = retry_start_snapshot_id.value ();
936- snapshot_id <= latest_snapshot.value ().Id (); ++snapshot_id) {
937- PAIMON_ASSIGN_OR_RAISE (Snapshot snapshot, snapshot_manager_->LoadSnapshot (snapshot_id));
938- if (snapshot.CommitUser () == commit_user_ && snapshot.CommitIdentifier () == identifier &&
939- snapshot.GetCommitKind () == commit_kind) {
940- return true ;
941- }
942- }
943- return false ;
944- }
945-
946922Status FileStoreCommitImpl::CheckSameBucketFromSnapshot (
947923 const std::vector<ManifestEntry>& delta_entries,
948924 const std::optional<Snapshot>& latest_snapshot) const {
@@ -1015,13 +991,7 @@ Result<bool> FileStoreCommitImpl::TryCommitOnce(
1015991 const std::vector<IndexManifestEntry>& index_entries, int64_t identifier,
1016992 std::optional<int64_t > watermark, const std::map<std::string, std::string>& properties,
1017993 Snapshot::CommitKind commit_kind, const std::optional<Snapshot>& latest_snapshot,
1018- bool detect_conflicts, std::optional<int64_t > retry_start_snapshot_id) {
1019- PAIMON_ASSIGN_OR_RAISE (bool committed, CheckCommitted (latest_snapshot, retry_start_snapshot_id,
1020- identifier, commit_kind));
1021- if (committed) {
1022- return true ;
1023- }
1024-
994+ bool detect_conflicts) {
1025995 std::vector<ManifestEntry> delta_files = delta_entries;
1026996 int64_t start_millis = DateTimeUtils::GetCurrentUTCTimeUs () / 1000 ;
1027997
@@ -1250,11 +1220,21 @@ Result<bool> FileStoreCommitImpl::TryCommitOnce(
12501220
12511221 Result<bool > commit_result = CommitSnapshotImpl (new_snapshot, delta_statistics);
12521222 if (!commit_result.ok ()) {
1253- // commit exception is uncertain; retry after checking whether this commit already exists.
1254- PAIMON_LOG_WARN (logger_, " Retry commit for exception. %s" ,
1223+ // commit exception, not sure about the situation and should not clean up the files.
1224+ PAIMON_LOG_WARN (logger_,
1225+ " You need to call FilterAndCommit to retry commit for exception. %s" ,
12551226 commit_result.status ().ToString ().c_str ());
1227+
1228+ // To prevent the case where an atomic write times out but actually succeeds,
1229+ // retrying the commit could lead to the snapshot file being committed multiple times.
1230+ // Therefore, retries should be handled by the upper layer,
1231+ // which should call FilterAndCommit to avoid duplicate commits.
1232+ // Therefore, we should not trigger cleanup here,
1233+ // as it may delete meta files from a snapshot that was just written by ourselves,
1234+ // leading to an incomplete or corrupted snapshot.
12561235 guard.Release ();
1257- return false ;
1236+ return Status::Invalid (" You need to call FilterAndCommit to retry commit for exception. " ,
1237+ commit_result.status ().ToString ());
12581238 }
12591239 bool commit_success = commit_result.value ();
12601240 if (commit_success) {
0 commit comments