I’ve file which can be updated from several of process, hence I want to use locking and found https://github.com/gofrs/flock which might helps
But I think that issue is a bit more complicated , for example to update the file the api needs to read the file/ section before (we are providing api to read the file
or the application
objects by name
)
Get the json data modify it in the memory and update the file.
There is two options:
- updating the all file content
- updating section on the file i.e. one application properties
The problem is like following:
1. Process A & Process B (can be more…) Reads the object of
application name `node1`
2. Process A update the section (node1) with new data (for example
change the kind property and update)
3. Process B want to do the same , the problem is that between the time
it reads the data and the time it wants to update ,the data is not
valid since other process already update it.
in addition the same scenario is valid to all the file context
Race
condition issue…
This is a short example of the file that some stateless
process can update at any given time
ID: demo
version: 0.0.1
applications:
- name: node1
kind: html5
path: node1
expose:
- name: node_api
properties:
url: ${app-url}
- name: node2
kind: nodejs
path: node2
parameters:
quota: 256M
memory: 256M
How we can overcome this issue, or maybe simplify it to avoid race condition and collusion?