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

[Utility] Feat: add client-side session cache #888

Merged
merged 12 commits into from
Jul 25, 2023

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Jul 6, 2023

Description

Add a client-side cache for sessions and use it in the servicer command.

Issue

Fixes #791

Type of change

Please mark the relevant option(s):

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Major breaking change
  • Documentation
  • Other

List of changes

  • A session cache in the client package
  • Use the new session cache in the servicer command

Testing

  • make develop_test; if any code changes were made
  • make test_e2e on k8s LocalNet; if any code changes were made
  • e2e-devnet-test passes tests on DevNet; if any code was changed
  • Docker Compose LocalNet; if any major functionality was changed or introduced
  • k8s LocalNet; if any infrastructure or configuration changes were made

Required Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added, or updated, godoc format comments on touched members (see: tip.golang.org/doc/comment)
  • I have tested my changes using the available tooling

If Applicable Checklist

  • I have updated the corresponding README(s); local and/or global
  • I have added tests that prove my fix is effective or that my feature works
  • I have added, or updated, mermaid.js diagrams in the corresponding README(s)
  • I have added, or updated, documentation and mermaid.js diagrams in shared/docs/* if I updated shared/*README(s)

@adshmh adshmh added the utility Utility specific changes label Jul 6, 2023
@adshmh adshmh added this to the M3: Pocket RoS (Relay or Slash) milestone Jul 6, 2023
@adshmh adshmh self-assigned this Jul 6, 2023
@reviewpad reviewpad bot added medium Pull request is medium waiting-for-review labels Jul 6, 2023
@adshmh adshmh requested review from dylanlott and h5law July 6, 2023 13:14
@Olshansk Olshansk self-requested a review July 6, 2023 18:50
// SessionCache stores and retrieves sessions for application+relaychain pairs
//
// It uses a key-value store as backing storage
type SessionCache struct {
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on making SessionCache an interface with an internal sessionCache implementation so its easy to see & understand how to interact with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not against it at all, and I have used the pattern, i.e. define a public interface and return an internal struct as the implementation, many times. However, Accept interfaces, return structs pattern is arguably a good substitute, as it matches the standard library. Either approach works here IMO, so please advise which you consider a better fit.

Copy link
Member

Choose a reason for hiding this comment

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

Let's do the following:

  1. Define a public interface
  2. Make the public interface conform to the Submodule interface
  3. Define an internal struct
  4. Have the factory function return the interface type (which is actually an initialization of the struct underneath)

Copy link
Member

Choose a reason for hiding this comment

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

Closing this out per @h5law's suggestion here: #888 (comment)

app/client/cli/cache/session.go Show resolved Hide resolved
app/client/cli/cache/session_test.go Show resolved Hide resolved
app/client/cli/servicer.go Outdated Show resolved Hide resolved
app/client/cli/servicer.go Outdated Show resolved Hide resolved
app/client/cli/servicer.go Show resolved Hide resolved
app/client/cli/servicer.go Outdated Show resolved Hide resolved
@Olshansk
Copy link
Member

@adshmh Please re-request a review when this is ready

Copy link
Contributor

@h5law h5law left a comment

Choose a reason for hiding this comment

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

Left a bump on a previous comment, and for the few improve/todo comments that have been added the only minor NIT I could add would be to create a ticket to track them and add the issue number in the comment IMPROVE(#XXX) for example.

Otherwise everything looks good! Make sure to address the linter errors and I think this will be ready to merge then

@reviewpad reviewpad bot added large Pull request is large and removed medium Pull request is medium labels Jul 20, 2023
app/client/cli/servicer.go Outdated Show resolved Hide resolved
@adshmh adshmh requested a review from Olshansk July 20, 2023 12:16
// SessionCache stores and retrieves sessions for application+relaychain pairs
//
// It uses a key-value store as backing storage
type SessionCache struct {
Copy link
Member

Choose a reason for hiding this comment

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

Let's do the following:

  1. Define a public interface
  2. Make the public interface conform to the Submodule interface
  3. Define an internal struct
  4. Have the factory function return the interface type (which is actually an initialization of the struct underneath)

app/client/cli/servicer_test.go Show resolved Hide resolved
app/client/cli/servicer_test.go Outdated Show resolved Hide resolved
app/client/cli/servicer_test.go Outdated Show resolved Hide resolved
app/client/cli/servicer.go Outdated Show resolved Hide resolved
@adshmh
Copy link
Contributor Author

adshmh commented Jul 24, 2023

Let's do the following:

  1. Define a public interface
  2. Make the public interface conform to the Submodule interface
  3. Define an internal struct
  4. Have the factory function return the interface type (which is actually an initialization of the struct underneath)

Thank you for the review. Fixed, except item 2, as conforming to the Submodule interface would require the underlying kvstore to also support Start method. In addition, IntegrableModule would require supporting SetBus and GetBus methods, which don't seem needed for the client side (please advise if I am missing something here). Updated the struct to private, added new public interface, and used Create to be more consistent with submodules style.

@h5law
Copy link
Contributor

h5law commented Jul 24, 2023

conforming to the Submodule interface would require the underlying kvstore to also support Start method. In addition, IntegrableModule would require supporting SetBus and GetBus methods, which don't seem needed for the client side (please advise if I am missing something here)

To be clear the Submodule interface only requires GetBus() SetBus() and GetModuleName(). That being said I do not think this needs to be a submodule as it does not require any access to/from the bus. That seems like overkill to me. @Olshansk is there a reason you can see to make this a submodule?

@adshmh Personally as this is not a submodule I would change your Create method to a NewSessionCache or similar name to avoid confusion with it being a submodule.

@adshmh adshmh requested a review from Olshansk July 24, 2023 19:26
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

LGTM other than the one point from Harry.

app/client/cli/cache/session.go Outdated Show resolved Hide resolved
app/client/cli/servicer_test.go Outdated Show resolved Hide resolved
@adshmh adshmh merged commit 77dc729 into main Jul 25, 2023
9 checks passed
@Olshansk Olshansk deleted the feat-client-side-session-cache branch July 25, 2023 21:22
red-0ne pushed a commit that referenced this pull request Aug 2, 2023
## Description

Add a client-side cache for sessions and use it in the `servicer`
command.

## Issue

Fixes #791

## Type of change

Please mark the relevant option(s):

- [x] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- A session cache in the client package
- Use the new session cache in the servicer command

## Testing

- [x] `make develop_test`; if any code changes were made
- [x] `make test_e2e` on [k8s
LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md);
if any code changes were made
- [ ] `e2e-devnet-test` passes tests on
[DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd);
if any code was changed
- [ ] [Docker Compose
LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md);
if any major functionality was changed or introduced
- [x] [k8s
LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md);
if any infrastructure or configuration changes were made

## Required Checklist

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added, or updated, [`godoc` format
comments](https://go.dev/blog/godoc) on touched members (see:
[tip.golang.org/doc/comment](https://tip.golang.org/doc/comment))
- [x] I have tested my changes using the available tooling

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added, or updated,
[mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding
README(s)
- [ ] I have added, or updated, documentation and
[mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*`
if I updated `shared/*`README(s)

---------

Co-authored-by: Daniel Olshansky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
large Pull request is large utility Utility specific changes waiting-for-review
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Utility] Cache session data in client
4 participants