Dmitry Volyntsev
October 19, 2018 07:30AM
On 19.10.2018 06:33, HENG wrote:
> Hello:
>
> I am new to Nginx NJS, and I want to write a website with NJS.
>
> I want to write a simple JSON database with NJS fs.writeFileSync ,just
> like Node.js LowDB.
>
> but I have no idea . Does NJS fs.writeFileSync is atomic writing and
> race condition prevention ?

http://hg.nginx.org/njs/file/tip/njs/njs_fs.c#l649

It simply opens the file, makes several write syscalls into it, and
closes the file.

So, it is not atomic.

Probably we need here something like

https://www.npmjs.com/package/write-file-atomic

>
> If NJS fs.writeFileSync is NOT atomic writing, it can NOT be treate as a
> normal database file write.
>
> Thank you !
>
> --
> --------------------------------------------------------------------
> Heng
> ---------------------------------------------------------------------
> --
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

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

Dmitry Volyntsev October 19, 2018 07:30AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 235
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready