Skip to content

Conversation

gbadner
Copy link
Contributor

@gbadner gbadner commented Sep 6, 2019

…taRegion and QueryResultsRegion with the same name

https://hibernate.atlassian.net/browse/HHH-13613

See the previous PR for earlier conversation: #3006

…taRegion and QueryResultsRegion with the same name
@gbadner gbadner requested a review from sebersole September 6, 2019 19:01
sessionFactory
);
regionsByName.put( queryResultsRegion.getName(), queryResultsRegion );
domainDataAndQueryResultsRegionNames.add( queryResultsRegion.getName() );
Copy link
Contributor Author

@gbadner gbadner Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default QueryResultsRegion is not added to #legacySecondLevelCacheNames. Should it be?

If so, should it be qualified?

legacySecondLevelCacheNames.add(
		StringHelper.qualifyConditionally(
					getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(),
					queryResultsRegion.getName()
		)
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Practically speaking the default region does have a name, but conceptually that is not the case. No it should not be added to legacySecondLevelCacheNames

@Override
public void evictQueryRegion(String regionName) {
final QueryResultsCache cache = getQueryResultsCache( regionName );
final QueryResultsCache cache = namedQueryResultsCacheMap.get( regionName );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#getQueryResultsCache will create a new QueryResultsCache if one does not exist with the provided regionName.

I didn't think that it made sense to create a new QueryResultsCache when evicting, so I changed the line to lookup only an existing.

Should this be reverted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not creating the region on evict is better. So I'd leave your change

}
final QueryResultsCacheImpl regionAccess = new QueryResultsCacheImpl(
domainDataAndQueryResultsRegionNames.add( regionName );
legacySecondLevelCacheNames.add( regionName );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new named QueryResultsRegion is not qualified when added to #legacySecondLevelCacheNames.

Should it be qualified as follows?

legacySecondLevelCacheNames.add( StringHelper.qualifyConditionally( 
        getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(), 
        regionName ) 
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I believe that the legacy behavior was to not expect the user to prefix the names for query regions which is different than its expectations for domain data regions. Not completely sure, so we should maybe verify that.

@gbadner
Copy link
Contributor Author

gbadner commented Sep 6, 2019

StatisticsImpl#getCacheRegionStatistics and getQueryRegionStats call CacheImplementor#getQueryResultsCache.

Should a QueryResultsRegion really be created if one does not exist yet?

I suppose it makes sense to do this, if the application will ultimately create the region.

WDYT?

…taRegion and QueryResultsRegion with the same name
@sebersole
Copy link
Member

StatisticsImpl#getCacheRegionStatistics and getQueryRegionStats call CacheImplementor#getQueryResultsCache.

Should a QueryResultsRegion really be created if one does not exist yet?

The stats reference itself should be created. So from there it depends whether you want to have a mutable CacheRegionStatisticsImpl to be able to inject the Region later if need be or to just create the Region up front to pass along to the CacheRegionStatisticsImpl. IMO creating the Region when we create the CacheRegionStatisticsImpl makes the most sense.

@sebersole
Copy link
Member

sebersole commented Sep 9, 2019

Actually, #getQueryRegionStats is only triggered when the stats are being updated because of the execution of a query - it is only ever called from StatisticsImpl#queryCacheHit, StatisticsImpl#queryCacheMiss, etc. Here we fully expect the region to exist.

WRT StatisticsImpl#getCacheRegionStatistics, as outlined in its comments it is a deprecated legacy method and its implementation it intended to be consistent with the legacy expectation. Its replacement is StatisticsImpl#getQueryRegionStatistics which correctly uses CacheImplementor#getQueryResultsCacheStrictly instead

Base automatically changed from master to main March 19, 2021 16:00
@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Mar 19, 2021

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ The pull request title should not end with an ellipsis (make sure the title is complete)
❌ The pull request description must contain the license agreement text.
    ↳ The description of this pull request must contain the following license agreement text:

----------------------
By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.txt)
and can be relicensed under the terms of the [LGPL v2.1 license](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt) in the future at the maintainers' discretion.
For more information on licensing, please check [here](https://github.com/hibernate/hibernate-orm/blob/main/CONTRIBUTING.md#legal).

----------------------

› This message was automatically generated.

@yrodiere yrodiere added the 5.6 label Oct 3, 2025
@yrodiere yrodiere changed the title HHH-13613 : Improve CacheImplementor SPI to better support a DomainDa… [5.6] HHH-13613 : Improve CacheImplementor SPI to better support a DomainDa… Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants