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

version annotation used in BLC_ID_GENERATION is unnecessary #2485

Open
project-concerto opened this issue Jan 31, 2021 · 0 comments
Open

version annotation used in BLC_ID_GENERATION is unnecessary #2485

project-concerto opened this issue Jan 31, 2021 · 0 comments

Comments

@project-concerto
Copy link

Problem

Optimistic lock @Version used in IdGenerationImpl is redundant, and it can be removed to obtain better performance.

Detail Description

When a kind of id in memory is used up, a new batch of id would be retrieved from BLC_ID_GENERATION as show below. version field in BLC_ID_GENERATION is used as an optimistic lock to avoid concurrent modification to BLC_ID_GENERATION.

begin
# read a new batch of id <= [BATCH_START, BATCH_START+BATCH_SIZE)
select ID_TYPE, BATCH_SIZE, BATCH_START, ID_MIN, ID_MAX, version from BLC_ID_GENERATION where ID_TYPE='org.broadleafcommerce.profile.core.domain.Customer'
# when update id information in database, use version field to ensure no other concurrent transaction has modified it
# if there is no row updated, then it will throw OptimisticLockException 
update BLC_ID_GENERATION set BATCH_SIZE=50, BATCH_START=100, ID_MIN=null, ID_MAX=null, version=21 where ID_TYPE='org.broadleafcommerce.profile.core.domain.Customer' and version=20
commit

This optimistic lock is redundant, because in IdGererationServiceImpl#findNextId, which is the only function that may retrieve id from database, java synchronized has been used to prevent threads from access the same id type concurrently. So removing version field in BLC_ID_GENERATION to obtain slightly better performance is feasiable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant