@@ -160,26 +160,35 @@ Status ExternalSstFileIngestionJob::Prepare(
160160 // It is unsafe to assume application had sync the file and file
161161 // directory before ingest the file. For integrity of RocksDB we need
162162 // to sync the file.
163- TEST_SYNC_POINT (" ExternalSstFileIngestionJob::BeforeSyncIngestedFile" );
164- auto s = fs_->SyncFile (path_inside_db, env_options_, IOOptions (),
165- db_options_.use_fsync , nullptr );
166- TEST_SYNC_POINT (" ExternalSstFileIngestionJob::AfterSyncIngestedFile" );
167- TEST_SYNC_POINT_CALLBACK (
168- " ExternalSstFileIngestionJob::CheckSyncReturnCode" , &s);
169- if (!s.ok ()) {
170- if (s.IsNotSupported ()) {
171- // Some file systems (especially remote/distributed) don't support
172- // SyncFile API. Ignore the NotSupported error in that case.
173- ROCKS_LOG_WARN (db_options_.info_log ,
174- " After link the file, SyncFile API is not supported "
175- " for file %s: %s" ,
176- path_inside_db.c_str (), status.ToString ().c_str ());
177- } else {
178- // for other errors, propagate the error
179- status = s;
180- ROCKS_LOG_WARN (db_options_.info_log ,
181- " Failed to sync ingested file %s: %s" ,
182- path_inside_db.c_str (), status.ToString ().c_str ());
163+
164+ // TODO(xingbo), We should in general be moving away from production
165+ // uses of ReuseWritableFile (except explicitly for WAL recycling),
166+ // ReopenWritableFile, and NewRandomRWFile. We should create a
167+ // FileSystem::SyncFile/FsyncFile API that by default does the
168+ // re-open+sync+close combo but can (a) be reused easily, and (b) be
169+ // overridden to do that more cleanly, e.g. in EncryptedEnv.
170+ // https://github.com/facebook/rocksdb/issues/13741
171+ std::unique_ptr<FSWritableFile> file_to_sync;
172+ Status s = fs_->ReopenWritableFile (path_inside_db, env_options_,
173+ &file_to_sync, nullptr );
174+ TEST_SYNC_POINT_CALLBACK (" ExternalSstFileIngestionJob::Prepare:Reopen" ,
175+ &s);
176+ // Some file systems (especially remote/distributed) don't support
177+ // reopening a file for writing and don't require reopening and
178+ // syncing the file. Ignore the NotSupported error in that case.
179+ if (!s.IsNotSupported ()) {
180+ status = s;
181+ if (status.ok ()) {
182+ TEST_SYNC_POINT (
183+ " ExternalSstFileIngestionJob::BeforeSyncIngestedFile" );
184+ status = SyncIngestedFile (file_to_sync.get ());
185+ TEST_SYNC_POINT (
186+ " ExternalSstFileIngestionJob::AfterSyncIngestedFile" );
187+ if (!status.ok ()) {
188+ ROCKS_LOG_WARN (db_options_.info_log ,
189+ " Failed to sync ingested file %s: %s" ,
190+ path_inside_db.c_str (), status.ToString ().c_str ());
191+ }
183192 }
184193 }
185194 } else if (status.IsNotSupported () &&
0 commit comments