Page 1 of 1

Broadleaf Load Balancer + 2 hosts with site

Posted: Thu Oct 02, 2014 9:33 am
by ig0r
lets say i have a load balancer and two hosts running the same webapp and one database that is used by both hosts.

is it possible that two customer access the domain: customer A ends up on host 1 and customer B ends up on host 2 that they both receive the same customerId ? Looking at the blIdGenerationService the idTypeIdMap could get out of sync on two different hosts, correct ?

thanks

Re: Broadleaf Load Balancer + 2 hosts with site

Posted: Thu Oct 02, 2014 10:20 am
by phillipuniverse
No, this is not correct. The id generation service works in the same way that Hibernate's sequence generator does. Each host connects to the database and says "give me a batch of IDs that nobody else knows about, then increment the database". In the case you presented, Host 1 would grab a batch of ids 100-149 and then Host 2 would grab a batch of IDs 150-199, etc etc. The logic for doing this is in the dao, IdGenerationDaoImpl.findNextId() which the service uses.

Re: Broadleaf Load Balancer + 2 hosts with site

Posted: Fri Oct 03, 2014 1:55 am
by ig0r
but isn't it possible that hypothetically if both hosts call that findNextId() method at the same time that both get the same range ?

i dont see any locking of the idGeneration (blc_id_generation) table

Re: Broadleaf Load Balancer + 2 hosts with site

Posted: Fri Oct 03, 2014 10:42 am
by phillipuniverse
IdGenerationImpl has a column annotated with @Version: https://github.com/BroadleafCommerce/Br ... l.java#L53. This allows Hibernate to do optimistic locking on each record which means that if some other server tries to write a new batch of IDs, then it can't unless it has the latest version. You can see the retry logic at https://github.com/BroadleafCommerce/Br ... .java#L100.