lorenwest / node-red-contrib-state

Node-RED shared logical state with persistence, notification, and history
MIT License
7 stars 6 forks source link

Shared state does not save onto the filesystem #3

Closed steff75 closed 4 years ago

steff75 commented 4 years ago

I can't get this node to save the state that it will remain after a reboot. The shared-state directory that is created remains empty.

The output of the node during the session before a reboot contains the current state and the previous state, but history always shows array[0].

My system is the official node-red docker container on a diskstation, but I have tried it without success and with the same result with windows subsystem for linux (debian) and Android (Termux).

Do I miss a dependency or am I doing something wrong? Here is my simple test flow:

[{"id":"66da60b5.1d8de","type":"inject","z":"7e3eb10c.d00b48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":120,"wires":[["7dd152b1.5d6c44"]]},{"id":"7dd152b1.5d6c44","type":"set-shared-state","z":"7e3eb10c.d00b48","state":"8507f128.265b08","name":"timestampTest","triggerOnInit":true,"provideOutput":false,"outputs":0,"x":280,"y":120,"wires":[]},{"id":"fc79be3f.e9347","type":"get-shared-state","z":"7e3eb10c.d00b48","state":"8507f128.265b08","name":"timestampTest","triggerOnInit":true,"x":110,"y":200,"wires":[["c226b206.d952c","5d6e9628.12c498"]]},{"id":"5d6e9628.12c498","type":"debug","z":"7e3eb10c.d00b48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":270,"y":180,"wires":[]},{"id":"c226b206.d952c","type":"debug","z":"7e3eb10c.d00b48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"state","targetType":"msg","x":260,"y":220,"wires":[]},{"id":"8507f128.265b08","type":"shared-state","z":"","name":"timestampTest","historyCount":"5"}]

Thank you!

lorenwest commented 4 years ago

Docker containers lose all filesystem writes on restart. You will need to start the container with an externally mounted volume, and write to that volume. Subsequent restarts mounted to that same volume will read data from prior docker runs.

Search for docker run -v

This isn't a node-red-contrib-state issue, so I'm closing it from here. There's plenty of online resources for working with docker containers that persist across restarts.

steff75 commented 4 years ago

Hello and thank you for your time.

It is of course possible and to assume that I make a mistake when using the node, since this error does not seem to occur with others.

But it cannot be the mistake you state in your argumentation.

Docker containers lose all filesystem writes on restart.

As I wrote above, I have the same behavior on two non-container-based systems I tested.

My system is the official node-red docker container on a diskstation, but I have tried it without success and with the same result with windows subsystem for linux (debian) and Android (Termux).

The writable layer of a docker container with all its changes remains intact after a restart. It is only deleted when I recreate the container. (docker run documentation)

Search for docker run -v

I have been using this function since I started using docker. Also I had tried to use the shared-state folder in my bind-mounted folder with the functionGlobalContext option instead. Same result.

Since the issue is already closed, I have now found another working solution for me to get a status over a restart.

Thank you and have a nice weekend.

lorenwest commented 4 years ago

My apologies for misunderstanding. If your problem goes away when you persist the global state to the filesystem, maybe the issue is you need at least one GET State node in your flow for the state you are requesting from global state. Does the problem go away if you place a GET State node for the state your are requesting?

If that is the issue, I'd be happy to discuss a way to populate the global state without requiring a GET State node. Not sure how that would work, but I'd like to get verification that this is your problem first.

steff75 commented 4 years ago

Thanks. I have placed a Get-State Node in the example flow (see at the end of the first post), but it does not store the data in the shared state folder. In the gif you can also see that my history remains empty, although I chose 5 entries for it. It probably shouldn't be a permission problem with the filesystem, because the folder is created? Then the creation of files should also work, right?

test

lorenwest commented 4 years ago

Thank you - a picture is worth 1,000 words. I'll try running from a raw node-red container. Could you give me the run command that you see the issue with?

steff75 commented 4 years ago

Sorry for the delay, but I've been working long shifts this week.

My container in use has some environment variables set, but for testing this run command is sufficient: docker run --net=host --name nodered nodered/node-red I built another container with this command myself, and there the problem is the same.

lorenwest commented 4 years ago

Found the issue and resolved in newly published version 1.4.2. Works across node-red restarts with internal mounts as long as it's the same container, and across containers with external mounts.

Thank you for taking the time to show the bug in action. It really helped with the resolution.