Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

refactor: caching in jsonld processor #2487

Closed
wants to merge 1 commit into from
Closed

refactor: caching in jsonld processor #2487

wants to merge 1 commit into from

Conversation

aholovko
Copy link
Contributor

@aholovko aholovko commented Jan 26, 2021

This PR is a proposal on refactoring caching functionality in jsold processor.

There are 2 major issues that I have with the current approach:

  • it doesn't save from the repetitive code

Using WithDocumentLoaderCache might look like a robust solution but in practice, it requires a lot of boilerplate code (examples in Trustbloc projects: here, here, and similar should be added to edge-agent).

  • problems with API consistency

Cache is preloaded in one case and is not in another: here and here. It's also not necessarily clear that under the hood framework adds some additional opts to ones that you have specified explicitly. There is also hardcoded usage of ld.NewCachingDocumentLoader. The latter is a problem because I might want to use ld.NewCachingDocumentLoader with preloaded contexts and be able to pass it to the processor using WithDocumentLoader(...) - the current implementation will wrap it with one more ld.NewCachingDocumentLoader. UPD: existing code has guards against such scenario here

The current PR simplifies logic and adds more consistency to API. ld.NewCachingDocumentLoader with predefined contexts in the cache is used as a default. You can override it to any loader you want with options. I also moved cache.go from proof package to jsonld - for me it looks more like a processor concern.

Signed-off-by: Andriy Holovko [email protected]

@codecov
Copy link

codecov bot commented Jan 26, 2021

Codecov Report

Merging #2487 (1c929ca) into main (34e1819) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2487      +/-   ##
==========================================
- Coverage   89.29%   89.28%   -0.02%     
==========================================
  Files         250      250              
  Lines       18851    18822      -29     
==========================================
- Hits        16833    16805      -28     
+ Misses       1187     1186       -1     
  Partials      831      831              
Impacted Files Coverage Δ
pkg/doc/signature/proof/data.go 90.00% <ø> (-0.25%) ⬇️
pkg/doc/signature/jsonld/processor.go 82.03% <100.00%> (-1.99%) ⬇️
pkg/doc/signature/proof/jws.go 89.47% <100.00%> (-0.19%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34e1819...1c929ca. Read the comment docs.

@llorllale
Copy link
Contributor

Does this fix #1833?

@aholovko
Copy link
Contributor Author

aholovko commented Jan 26, 2021

Does this fix #1833?

It looks like the mentioned issue describes two problems:

  • handling of "JsonWebSignature2020" context

targeted by this PR

  • panic when the loader with pre-loaded contexts is used

I am trying to reproduce this panic with the old code. And then check it with the updated one (but I think that the problem has gone).

@llorllale plz correct me if I didn't get it right.

@aholovko
Copy link
Contributor Author

During the discussion with @kdimak, we decided that the caching functionality requires more consideration and also should account for other issues like the one mentioned by George. I am closing the current PR as it doesn't bring enough benefits to justify the risk of breaking the core stuff.

@aholovko aholovko closed this Jan 27, 2021
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code in the framework.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code in the framework.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code in the framework.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
baha-ai pushed a commit to baha-ai/aries-framework-go that referenced this pull request Mar 9, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code in the framework.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
sudeshrshetty pushed a commit to sudeshrshetty/aries-framework-go that referenced this pull request Oct 18, 2021
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code in the framework.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
sudeshrshetty pushed a commit to sudeshrshetty/aries-framework-go that referenced this pull request Jan 22, 2022
This change creates a local JSON-LD Document Cache loader using a cache of type *sync.Map
to avoid 'error on cache writes' panics.

This change also introduces the 'benchmark' Make target to support benchmarking code in the framework.

closes hyperledger-archives#1833 for the fatal error mentioned in the comment
Also related and closes the discussion about the same panic topic in hyperledger-archives#2487

Signed-off-by: Baha Shaaban <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants