File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
dbms/src/Storages/Distributed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -355,8 +355,19 @@ struct StorageDistributedDirectoryMonitor::Batch
355355 // / we must try to re-send exactly the same batches.
356356 // / So we save contents of the current batch into the current_batch_file_path file
357357 // / and truncate it afterwards if all went well.
358- WriteBufferFromFile out{parent.current_batch_file_path };
359- writeText (out);
358+
359+ // / Temporary file is required for atomicity.
360+ String tmp_file{parent.current_batch_file_path + " .tmp" };
361+
362+ if (Poco::File{tmp_file}.exists ())
363+ LOG_ERROR (parent.log , " Temporary file `" << tmp_file << " ` exists. Unclean shutdown?" );
364+
365+ {
366+ WriteBufferFromFile out{tmp_file, O_WRONLY | O_TRUNC | O_CREAT};
367+ writeText (out);
368+ }
369+
370+ Poco::File{tmp_file}.renameTo (parent.current_batch_file_path );
360371 }
361372 auto timeouts = ConnectionTimeouts::getTCPTimeoutsWithFailover (parent.storage .global_context .getSettingsRef ());
362373 auto connection = parent.pool ->get (timeouts);
You can’t perform that action at this time.
0 commit comments