Giter VIP home page Giter VIP logo

Comments (5)

xetorthio avatar xetorthio commented on July 20, 2024

done. pushed to master

from johm.

Bessonov avatar Bessonov commented on July 20, 2024

I think, this is not the right way to solve id problem. We need more generic approach to support different id types such as String. At least because redis is key-value store.

from johm.

gsharma avatar gsharma commented on July 20, 2024

Anton - a String id is not a very efficient mechanism for anything. At some level, it will have to be transformed to an integer like what Redis does by converting to 64-bit signed int. Actually, if we forget about Redis and focus on our clients, can you give an example where a JOhm client will be better served by having an id String like "94588" instead of just a long/integer type? Apart from String's slowness, we are opening us up to potential number format exceptions. With that tradeoff in mind, unless there is a compelling case where a client will be using String id's (example?), I have never been convinced we should go down that route.

from johm.

Bessonov avatar Bessonov commented on July 20, 2024

My minor goal is go possibly close to JPA specification. This allow easier to migrate from RDBMS.

I don't know how Redis and clients work - it's not my domain. If you say it's bad idea, then it's bad idea :)

Specially in my use case I store user session in Redis (I see Redis/Memcached storages for jetty and tomcat, but not for both containers) and for use JOhm I must generate Long session id's and result is:

UserSessionModel:1215265415737719425

Another cases: coupons and short-url-services, or generally string to whatever mappings.

I can imagine user defined functions to generate id's - this allow generate not only sequential id's as with incr(), ex.:

@model(generator=MyIdGenerator.class)
class MyModel() [...]

class MyIdGenerator {
public static Object generateId(Class entity) {
SecureRandom sr = new SecureRandom().nextLong();
Long id;
do {
id = sr.nextLong();
while ( JOhm.exists(entity, id) );
return id;
}

Sorry, if it's nonsense :)

from johm.

gsharma avatar gsharma commented on July 20, 2024

I see what you are saying and this is good thinking and a real-world use-case. So, what you are suggesting is a pluggable IdGenerator option which I like as an idea. I was confused by your earlier suggestion of the string id type: "different id types such as String".

So, now we need to think about global uniqueness in the presence of multiple clients generating id's using the custom IdGenerators and then having to persist to Redis objects loaded with these id's. You could have 15 nodes with JOhm deployments for application persistence all writing to a Redis backing instance and in-memory IdGenerators with potential id conflicts - you get the point.

That brings us back to the search for a reliable globally unique IdGenerator-as-a-service (something like Twitter's specialized service Snowflake). Or a poor man's db-sequence or incr() function :-)

Single-node IdGeneration is relatively trivial but I would love to hear your thoughts on a cheap way (think cross-node IO) to produce global id's. And plugging into JOhm is not a problem - we can easily inject a remote IdGenerationServiceProxy into JOhm and even batch-fetch like 1000 id's and cache client-side for quick-use. Maybe we can keep it simple and just 'extend' the data retrieved by an incr() call by adding some alphanumeric fields to elongate the id.

from johm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.