-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to save in an external database #305
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days |
Not stale. With something like Sequelize it would be possible to maintain the current SQLite implementation as backwards compatible option. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days |
Still not stale though haha |
+1 to this. But you mention a NAS - you could always mount the k8s container storage on a NFS shared drive. Or GlusterFS. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days |
I suppose there is still no support for external databases? |
@Koenkk I think this is still not stale? I'd be interested in having a little dig into this if there is might be any interest in accepting changes. |
@judahrand changes are welcome, but note that it's not just the |
Fantastic! I took an initial look at this last night and it (obviously) won't be a trivial change but I do think there could be significant value to using a 'real' database in terms of stability, extensibility (litestream, Postgres, etc.), and, I suspect, even performance. I'm not a Typescript developer normally so I'm not familiar with the ORM landscape in Typescript but from my investigation last night I think that using Drizzle probably makes the most sense. It seems to aim to be as lightweight as possible seems to fit well for There are a few design considerations to make too, I think. One that jumps to mind is how the 'backups' would work. For Coordinator backups this could probably just be versioned rows in a table and the newest row is always used by default or a given row could be marked as 'active'. A limited number of these backups could be kept at any given time and they could be timestamped. When it comes to the backup logic when a I'm sure there are other decisions that would need to be made but from what I can tell, as long as the API for Controller is maintained and a migration path for the current files exists then other breaking changes should be acceptable. Is this correct? |
I'm not convinced that a SQL database will have any impact on performance, the whole database is loaded in memory and all devices are resolved through a very efficient lookup. A typical database is also nothing in terms of size, mine is 102KB (+- 80 devices). An external database will also not solve the problem of needing persistent storage, z2m still stores I think a better approach here is to allow the Z2M data directory to be stored on a remote filesystem. If we use for example OpenDAL you could store the directory on almost any remote file system, e.g. via sftp or even OneDrive! 😄 |
That's a fair point on performance. I hadn't initially realized that the whole database is loaded into memory. There are other advantages to using SQLite at least, however, imo.
Does the I've got a branch which implements a SQLite database which almost passes all the tests so I'll get that working and put it up at least for consideration. |
Yes, e.g. the |
I think orm is much too complex for the 100 or so lines that Z2M needs. There is practically no use for the features since, like Koenkk said, everything is cached in memory on startup and read/parsed from there at runtime, not from the database. The tiny size allows this without creating RAM issues, and makes it a hard-to-beat option as far as speed is concerned. As for writes, a quick bench on current vs drizzle orm branch shows a 2x drop in performance minimum. No doubt the overhead alone is a killer :/ Coordinator backups in the database is definitely a no-go for me. This is not portable. |
What benchmark are you running? I suspect it can be improved substantially - the current implementation is the simplest lift and shift possible.
I'm not sure I'm understanding you here. Why is it not portable? Easy to get back to the same JSON by pulling it out of a db table. |
The usual, tinybench, with a
Not without dependencies and with extra parsing required. Current file is natively supported and follows the open backup format. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days |
Same issue as Koenkk/zigbee2mqtt#4947
As stated in the linked issue this would be a welcome addition for users who write on SD card like storage.
My usecase is a bit specific but nonetheless a bit of explanation.
I am trying to get a stateless Zigbee2MQTT implementation so it can failover between Kubernetes nodes (external CC2530 TCP serial) without the need of a volume (since distributed storage is hard on low power devices).
I am using Kubernetes configmaps for the configuration so only the
database.db
and thecoordinator_backup.json
are blocking a completely stateless approach.If these could be stored in an external database then the image can be run without a volume (stateless) which offloads the persistence to a NAS for example.
The text was updated successfully, but these errors were encountered: