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

fix an annoying bug that when regularly calling invalidateAll() on a … #22

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

StephanPreibisch
Copy link
Member

…SoftRefCache, it throws a NullPointerException. Somehow "ref" can be null, check line 213 while get() is still being called

…SoftRefCache, it throws a NullPointerException. Somehow "ref" can be null, check line 213 while get() is still being called
@StephanPreibisch
Copy link
Member Author

let's maybe discuss this more @tpietzsch @axtimwalde ?

@tpietzsch tpietzsch self-assigned this Mar 25, 2023
@tpietzsch tpietzsch marked this pull request as draft March 25, 2023 11:10
@tpietzsch
Copy link
Member

Just to understand better:
The invalidataAll() javadoc says: "There must be no concurrent get() operations. This may result in cache corruption and/or a deadlock."
Did you make sure of this and are still getting this bug?

@axtimwalde
Copy link
Member

axtimwalde commented Mar 25, 2023 via email

@tpietzsch
Copy link
Member

I think it either needs to be specific to the application, or all cache accesses must be synchronized.

I would make a Lock that BDV acquires/releases before/after rendering, and that the invalidating code would also acquire/release.

Potentially, the Lock could be created by the cache and locking be done automatically in invalidateAll(). But that would be complicated by having multiple caches, caches layered on top of each other, etc. I think it makes more sense to build the locking completely outside.

To not make it super-specific in the BDV API we could add beforeRender(Runnable) and afterRender(Runnable) methods (where one could pass Runnables that acquire/release the lock).

StephanPreibisch added a commit to saalfeldlab/hot-knife that referenced this pull request Mar 28, 2023
… synchronization issue (imglib/imglib2-cache#22) -- which we will fix later differently
@StephanPreibisch
Copy link
Member Author

Hi, for now I made a local copy of SoftRefLoaderCache called RobustSoftRefLoaderCache (containing the change above) in hot-knife which temporarily solves the issue.

How should we take it from here?

@axtimwalde
Copy link
Member

I think it would be best to have an invokeAfterRender(Runnable) method in BDV that is called immediately if no rendering happens or immediately after rendering finishes and before the next rendering starts. That wouldn't require any additional synchronization.

@NicoKiaru
Copy link

@axtimwalde but what if several renderers exist ?

@tpietzsch
Copy link
Member

@axtimwalde but what if several renderers exist ?

Yes, very good point. That would be a problem.
I would go with the beforeRender(Runnable) and afterRender(Runnable) then.
The lock should then be ReentrantReadWriteLock so that multiple renderers can take read locks at the same time. (And invalidateAll would take the write lock)

@tpietzsch
Copy link
Member

@StephanPreibisch

How should we take it from here?

I'll implement the beforeRender(Runnable) and afterRender(Runnable) in BDV, then build around that in hotknife. Can you point me to where the invalidateAll() happens and something I can run to test it?

@StephanPreibisch
Copy link
Member Author

And the parameters for running PaintHeightField.java:
--n5Path=/nrs/hess/render/export/hess.n5 --n5FieldPath=/nrs/hess/render/export/hess.n5 --n5Raw=/render/wafer_52_cut_00030_to_00039/slab_013_all_align_t2_ic___20230328_105504 --n5Field=/heightfields/wafer_52_cut_00030_to_00039/slab_013_all_align_t2_ic___20230328_105504/s1/min --n5FieldOutput=/heightfields_fix/wafer_52_cut_00030_to_00039/slab_013_all_align_t2_ic___20230328_105504/min --scale=2,2,1 --offset=0 --multiSem
Guess it's best to make a local copy of the heighfield ... or just ask me to test it ...

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

Successfully merging this pull request may close these issues.

4 participants