Nginx NJS fs.writeFileSync is atomic writing and race condition prevention ?

HENG ourwaiting at gmail.com
Fri Oct 19 16:58:35 UTC 2018


Thanks your reply.

When I deep into NJS source you ponit to, I found something about GCC write
file flag with O_APPEND

I google Linux GCC write file O_APPEND to learn something.

In fact NJS fs.writeFileSync() with O_APPEND, it is atomic write file if
it's buffer just write all in one time. Even mutil process to write one
file use O_APPEND.

But, if write buffer can NOT write all in one time, in mutil process, it is
NOT atomic.

I found Nginx Log write is use O_APPEND to write atomic, even Nginx has a
lot of workers.

And

I read the source code by your link `write-file-atomic`, it is hard to port
to NJS. The reason is that NJS fs without fs.rename, and Nodejs write file
atomic use temp file rename and write queue to make it.

Thanks.

HENG <ourwaiting at gmail.com> 于2018年10月20日周六 上午12:55写道:

> Thanks your reply.
>
> When I deep into NJS source you ponit to, I found something about GCC
> write file flag with O_APPEND
>
> I google Linux GCC write file O_APPEND to learn something.
>
> In fact NJS fs.writeFileSync() with O_APPEND, it is atomic write file if
> it's buffer just write all in one time. Even mutil process to write one
> file use O_APPEND.
>
> But, if write buffer can NOT write all in one time, in mutil process, it
> is NOT atomic.
>
> I found Nginx Log write is use O_APPEND to write atomic, even Nginx has a
> lot of workers.
>
> And
>
> I read the source code by your link `write-file-atomic`, it is hard to
> port to NJS. The reason is that NJS fs without fs.rename, and Nodejs write
> file atomic use temp file rename and write queue to make it.
>
> Thanks.
>
>
> --
> --------------------------------------------------------------------
> Heng
> ---------------------------------------------------------------------
> --
>


-- 
--------------------------------------------------------------------
Heng
---------------------------------------------------------------------
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20181020/df00bb96/attachment.html>


More information about the nginx-devel mailing list