-
Notifications
You must be signed in to change notification settings - Fork 36
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
There was a problem hiding this 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.
There was a problem hiding this 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
Can you please rebase this PR? Thank you |
There was a problem hiding this 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
|
||
@Override | ||
public Future<Void> close() { | ||
return Future.succeededFuture(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The close future is not bound to anything, neither Vert.x nor the context. Take a look at how Vert.x creates shared http clients, or shared Vert.x SQL Clients, shared Kafka Producers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct then?
public Cache newCache(CacheOptions options, Vertx vertx) {
if (options.getShared()) {
VertxInternal vx = (VertxInternal) vertx;
CloseFuture closeFuture = new CloseFuture();
Cache cache = vx.createSharedResource("__vertx.shared.proxyCache", options.getName(), closeFuture, (cf_) -> {
return new CacheImpl(options);
});
ContextInternal ctx = vx.getContext();
if (ctx != null) {
ctx.addCloseHook(closeFuture);
} else {
vx.addCloseHook(closeFuture);
}
return cache;
}
return new CacheImpl(options);
}
So now I know the callback (the cf_
one) doesn't need to close anything because there's nothing to close for the Cache interface; and for the outside closeFuture
, my current understanding is that by calling closeFuture.close()
means declaring "giving up the reference holding" of this shared resource and reduce the reference counter (Hook.count
) by 1.
Correct me if I'm wrong: the outside closeFuture
still should be managed because we want to maintain the reference counter correct, and when the vertx.close()
is called, the counter will be cleared to 0 even if newCache
being called multiple times (because addCloseHook
is registered multiple times as well).
Closes #67
Updated the cache SPI and added serialization for the
Resource
class.