Welcome! Log In Create A New Profile

Advanced

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

Valentin V. Bartenev
October 19, 2018 01:04PM
On Friday, 19 October 2018 06:33:57 MSK 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 ?
>
> If NJS fs.writeFileSync is NOT atomic writing, it can NOT be treate as a
> normal database file write.
>
> Thank you !
>

The fs.writeFileSync function calls a simple write(), which is atomic with
regular files.

But at the first glance to work with file like a database using multiple
nginx worker processes it's not enough to have atomic writing function.

You need to have atomic the whole sequence of operations:
read file -> update data -> write file.

Since currently there's no locking functionality in njs, the only way to
achieve this is to use only one worker process.

wbr, Valentin V. Bartenev



_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

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

HENG 390 October 18, 2018 11:36PM

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

Dmitry Volyntsev 125 October 19, 2018 07:28AM

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

HENG 168 October 19, 2018 01:00PM

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

Valentin V. Bartenev 150 October 19, 2018 01:04PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 133
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