Skip to content
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

Handle persistence with DB layer #2

Open
infusion opened this issue Jun 25, 2017 · 16 comments
Open

Handle persistence with DB layer #2

infusion opened this issue Jun 25, 2017 · 16 comments

Comments

@infusion
Copy link
Owner

Implement session storage of the server in either

  • mongodb
  • sqlite
  • MySQL/PgSQL
@fredericosilva
Copy link
Contributor

Hi, any those storages will require _selectAddress to be an asynchronous. How are you thinking about exposing this to the user? (parameter on server config?)

@infusion
Copy link
Owner Author

infusion commented Jun 28, 2017

The previous idea is emitting an event, which can be handled by a storage solution to write down the information. On startup the data must be fetched asynchronously. Exposing parameters via the server config would be another option. What do you think is the better way?

@gregorybrzeski
Copy link

On startup the data must be fetched asynchronously.

What about data which changes while server is running ?

Maybe dynamic requests to backend with some type of local (in memory or persistent) cache ?

@infusion
Copy link
Owner Author

You mean administrative changes in the DB? Every change the server makes while running should affect the actual state and should simply be mirrored to the db layer. Handling administrative changes would require to query the db more frequently.

@fredericosilva
Copy link
Contributor

Maybe, one could abstract those requirements in some kind of provider. That implements the selectAddress on an async fashion.

That will handle storage/backend scenarios.

Actual range/static/random may even be different provider implementations.

@fredericosilva
Copy link
Contributor

Have a look on my fork, I've extracted the _getLease to have a single place where _selectAddress is called.

On _selectAddress I'm testing if a selectAddress exists on the config.

Any thoughts?

@infusion
Copy link
Owner Author

this.config('leaseTime');

shouldn't work in the callback. You should reference this to the outer scope. But I like the async nature, you introduced to the address selection. I wonder if we should make it more general to store any config, or at least the lease storage (aka _state).

@fredericosilva
Copy link
Contributor

It works because I'm using an arrow function, 'this' is not changed.

Do you mean abstracting the access to _state with async get/set? and using it to implement different persistence layers?

@infusion
Copy link
Owner Author

Ahh, sorry. I only read the diff and missed the arrow function.

Yep exactly. What do you think about it?

@fredericosilva
Copy link
Contributor

I like the ideia. If we have it like that, there is no need of exposing the selectAddress everything can be handled on the storage layer. Besides get/set what else do we need on that layer?

@infusion
Copy link
Owner Author

I think that's it and yep, it doesn't need to expose individual features like selectAddress this way :)

The remaining question is, how the storage interface is fed into the server. If it's a config option like:

dhcp.createServer({
...
storage: new dhcp.createMongoStorage('127.0.0.1', ...),
... 
});

or something else.

@gregorybrzeski
Copy link

Should it be called storage ? Maybe it should be called a provider.

It would be providers decision if to store it persistently, in memory or in any other way. Each provider can also make own decision if to provide response based on dynamic or static data.

@infusion
Copy link
Owner Author

You're right, Gregory. Provider might be a better name for it.

@SridharRamasami
Copy link

Hi,
I am using this module and would like to add this functionality. However, I am not clear on the requirements per the conversation in this thread. Need some feedback and better instructions :-)
Sridhar

@roccomuso
Copy link

Consider using something like keyv for the storage layer.

@infusion
Copy link
Owner Author

Oh, thanks for introducing keyv!

@UrielCh UrielCh mentioned this issue Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants