-
Notifications
You must be signed in to change notification settings - Fork 332
Consolidate CallContext with PolarisCallContext #1806
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,15 @@ | |
| import java.time.Clock; | ||
| import java.time.ZoneId; | ||
| import org.apache.polaris.core.config.PolarisConfigurationStore; | ||
| import org.apache.polaris.core.context.CallContext; | ||
| import org.apache.polaris.core.context.RealmContext; | ||
| import org.apache.polaris.core.persistence.BasePersistence; | ||
|
|
||
| /** | ||
| * The Call context is allocated each time a new REST request is processed. It contains instances of | ||
| * low-level services required to process that request | ||
| */ | ||
| public class PolarisCallContext { | ||
| public class PolarisCallContext implements CallContext { | ||
|
|
||
| // meta store which is used to persist Polaris entity metadata | ||
| private final BasePersistence metaStore; | ||
|
|
@@ -40,31 +42,52 @@ public class PolarisCallContext { | |
|
|
||
| private final Clock clock; | ||
|
|
||
| // will make it final once we remove deprecated constructor | ||
| private RealmContext realmContext = null; | ||
|
|
||
| public PolarisCallContext( | ||
| @Nonnull RealmContext realmContext, | ||
| @Nonnull BasePersistence metaStore, | ||
| @Nonnull PolarisDiagnostics diagServices, | ||
| @Nonnull PolarisConfigurationStore configurationStore, | ||
| @Nonnull Clock clock) { | ||
| this.realmContext = realmContext; | ||
| this.metaStore = metaStore; | ||
| this.diagServices = diagServices; | ||
| this.configurationStore = configurationStore; | ||
| this.clock = clock; | ||
| } | ||
|
|
||
| @Deprecated | ||
| public PolarisCallContext( | ||
| @Nonnull BasePersistence metaStore, @Nonnull PolarisDiagnostics diagServices) { | ||
| @Nonnull BasePersistence metaStore, | ||
| @Nonnull PolarisDiagnostics diagServices, | ||
| @Nonnull PolarisConfigurationStore configurationStore, | ||
| @Nonnull Clock clock) { | ||
| this.metaStore = metaStore; | ||
| this.diagServices = diagServices; | ||
| this.configurationStore = configurationStore; | ||
| this.clock = clock; | ||
| } | ||
|
|
||
| public PolarisCallContext( | ||
| @Nonnull RealmContext realmContext, | ||
| @Nonnull BasePersistence metaStore, | ||
| @Nonnull PolarisDiagnostics diagServices) { | ||
| this.realmContext = realmContext; | ||
| this.metaStore = metaStore; | ||
| this.diagServices = diagServices; | ||
| this.configurationStore = new PolarisConfigurationStore() {}; | ||
| this.clock = Clock.system(ZoneId.systemDefault()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a copy from the deprecated method, see line 90. I'm OK to change it to UTC. I'd suggest to make that change in a separate PR, as it isn't related to the refactor in this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok to defer, but we must not forget... IIRC we already have a mix of clocks in the codebase. It'd be nice to have a uniform pattern. |
||
| } | ||
|
|
||
| public static PolarisCallContext copyOf(PolarisCallContext original) { | ||
| return new PolarisCallContext( | ||
| original.getMetaStore().detach(), | ||
| original.getDiagServices(), | ||
| original.getConfigurationStore(), | ||
| original.getClock()); | ||
| @Deprecated | ||
| public PolarisCallContext( | ||
| @Nonnull BasePersistence metaStore, @Nonnull PolarisDiagnostics diagServices) { | ||
| this.metaStore = metaStore; | ||
| this.diagServices = diagServices; | ||
| this.configurationStore = new PolarisConfigurationStore() {}; | ||
| this.clock = Clock.system(ZoneId.systemDefault()); | ||
| } | ||
|
|
||
| public BasePersistence getMetaStore() { | ||
|
|
@@ -82,4 +105,14 @@ public PolarisConfigurationStore getConfigurationStore() { | |
| public Clock getClock() { | ||
| return clock; | ||
| } | ||
|
|
||
| @Override | ||
| public RealmContext getRealmContext() { | ||
| return realmContext; | ||
| } | ||
|
|
||
| @Override | ||
| public PolarisCallContext getPolarisCallContext() { | ||
| return this; | ||
| } | ||
| } | ||
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.
Just curious, why not go the other way? It seems like it would be easier to have CallContext extend PolarisCallContext, since it can immediately implement all the methods just by delegating to the current PolarisCallContext
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.
I think that's also a nice idea, however, it will need to change
CallContextfrom an interface to a class, which isn't trivial -- all anonymous classes have to go. Besides, it's reasonable to keep CallContext as an interface, whilePolarisCallContextas an impl. I also list the step 3 which promotes methods inPolarisCallContextto the interfaceCallContext, likegetMetaStore(). This will even clean up more, so that,PolarisCallContextdoesn't have to return itself from the methodgetPolarisCallContext().