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

Updating bean - L2 Bean cache update + l2 cache update on "Many Ids" when they have not change - can lead to race #2063

Closed
rbygrave opened this issue Oct 7, 2020 · 0 comments
Assignees
Labels
Milestone

Comments

@rbygrave
Copy link
Member

rbygrave commented Oct 7, 2020

Steps to reproduce

	@Test
	public void testLazyLoad(){

		DB.script().run("/test-setup.sql");
		// Please execute the script in [test.sql] every time you execute the test to reset the data
		Config c1 = new QConfig().setUseCache(true).setId("config_1").findOne();
		List<ConfCp> confCpList = c1.getConfCpList();
		if(confCpList != null && !confCpList.isEmpty()){
			List<ConfCpCon> conList = confCpList.get(0).getConList();
			if (!conList.isEmpty()) {
				conList.get(0);
			}
		}
		c1.setConfigName("c1");

		Config c2 = new QConfig().setUseCache(true).setId("config_1").findOne();
		ConfCp confCp = c2.getConfCpList().get(0);

		ConfCpCon con = new ConfCpCon();
		con.setId("newCon");
		con.setEnabled("N");
		confCp.getConList().clear();
		confCp.getConList().add(con);

		c2.getConfCpList().clear();
		c2.getConfCpList().add(confCp);

		//DB.markAsDirty(c2);
		c2.save();

		c1.save();   // THIS UPDATE HERE ... will also push L2 cache update of ManyIds which have changed by c2.save()

		Config config = new QConfig().setUseCache(true).setId("config_1").findOne();
		List<ConfCp> confCpList1 = config.getConfCpList();
		if(confCpList1 != null && !confCpList1.isEmpty()){
			List<ConfCpCon> conList = confCpList1.get(0).getConList();
			if (conList != null) {
				for (ConfCpCon confCpCon : conList) {
					System.out.println("---- id: "+confCpCon.getId());
					// An exception will be thrown here
					// EntityNotFoundException: Bean not found during lazy load or refresh
					System.out.println(confCpCon.getId()+":"+confCpCon.getEnabled());
				}
			}
		}

	}

The issue can be seen in the logs as the last 2 PUT calls here should not really be made as the collection hasn't actually been mutated in terms of additions or removals.

14:01:51.160 [main] DEBUG io.ebean.SUM - txn[1006] Updated [Config] [config_1]
14:01:51.161 [main] DEBUG io.ebean.TXN - txn[1006] Commit
14:01:51.161 [main] DEBUG io.ebean.cache.BEAN -    UPDATE Config(config_1)  changes:{configName=c1, version=2}
14:01:51.161 [main] DEBUG io.ebean.cache.COLL -    PUT Config(config_1).confCpList - ids:[cp_id]
14:01:51.162 [main] DEBUG io.ebean.cache.COLL -    PUT ConfCp(cp_id).conList - ids:[confCpCon]
@rbygrave rbygrave self-assigned this Oct 7, 2020
@rbygrave rbygrave added the bug label Oct 7, 2020
rbygrave added a commit that referenced this issue Oct 7, 2020
…cache update on "Many Ids" when they have not change - can lead to race
rbygrave added a commit that referenced this issue Oct 7, 2020
…ny Ids" when they have not change - can lead to race
@rbygrave rbygrave added this to the 12.4.2 milestone Oct 7, 2020
@rbygrave rbygrave closed this as completed Oct 7, 2020
rPraml pushed a commit to FOCONIS/ebean that referenced this issue Jan 11, 2021
…ate + l2 cache update on "Many Ids" when they have not change - can lead to race
rPraml pushed a commit to FOCONIS/ebean that referenced this issue Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant