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

Update cache SPI and resource serialization #92

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wzy1935
Copy link
Contributor

@wzy1935 wzy1935 commented Jul 15, 2024

Closes #67

Updated the cache SPI and added serialization for the Resource class.

Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

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

Thank you @wzy1935 ! I did a first round of comments

src/main/java/io/vertx/httpproxy/spi/cache/Cache.java Outdated Show resolved Hide resolved
src/main/java/io/vertx/httpproxy/cache/CacheOptions.java Outdated Show resolved Hide resolved
src/main/java/io/vertx/httpproxy/impl/CacheImpl.java Outdated Show resolved Hide resolved
src/main/java/io/vertx/httpproxy/spi/cache/Resource.java Outdated Show resolved Hide resolved
@wzy1935 wzy1935 mentioned this pull request Jul 24, 2024
Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

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

Thank you @wzy1935 , I've added another batch of comments

Can you also add a test that verifies the behavior of a shared cached? That is, if it has stored a response for a one reverse proxy instance, another proxy instance will not have to contact the backend.

src/main/java/io/vertx/httpproxy/cache/CacheOptions.java Outdated Show resolved Hide resolved
src/main/java/io/vertx/httpproxy/HttpProxy.java Outdated Show resolved Hide resolved
Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

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

Thank you @wzy1935 ! Some more comments

@tsegismont
Copy link
Contributor

Can you please rebase this PR? Thank you

Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

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

Thank you @wzy1935 , another batch of reviews

@@ -15,6 +15,7 @@
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import io.vertx.core.Vertx;

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a leftover from a previous change?


/**
* Default constructor
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Default constructor
* Default constructor.

The Javadoc convention mandates there must be a first sentence ending with period.

Can you please do the same with other Javadoc comments?


@Override
public Future<Void> close() {
return Future.succeededFuture();
Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't talk about clearing the map on close, did we? Would it be necessary in your opinion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I also think there's no need, but when I called the vertx.createSharedResource() in ReverseProxy#newCache, there's a closeFuture that I don't know how to deal with it.

Maybe you could check if the following would work? I think I should change to this version:

  // ReverseProxy#newCache
  public Cache newCache(CacheOptions options, Vertx vertx) {
    if (options.getShared()) {
      CloseFuture closeFuture = new CloseFuture();
      return ((VertxInternal) vertx).createSharedResource("__vertx.shared.proxyCache", options.getName(), closeFuture, (cf_) -> {
        Cache cache = new CacheImpl(options);
        return cache;
      });
    }
    return new CacheImpl(options);
  }


/**
* Cache SPI.
*/
public interface Cache<K, V> extends Map<K, V> {
public interface Cache {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add @Unstable here as we might want to evolve the SPI after the initial design

}

public void fillResponseFromResource(ProxyResponse proxyResponse, Resource resource) {
proxyResponse.setStatusCode(200);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using the status code of the resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this part of the code is moved from Resource#init where it uses 200 in the original code. In PR I don't want to change any logic so I left it in here, instead I made this change in #93


public class ResourceParseTest {

public static boolean weakEquals(Resource r1, Resource r2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why weakEquals? Which are the fields we don't want to compare?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A silly reason cause the full equals is rather too long to implement... I can add them back though

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.

Introduce a cache storage SPI
4 participants