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

CASSSIDECAR-208: Guice modularization #200

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

yifan-c
Copy link
Contributor

@yifan-c yifan-c commented Feb 20, 2025

Patch by Yifan Cai; Reviewed by TBD for CASSSIDECAR-208

@yifan-c yifan-c force-pushed the CASSSIDECAR-208/guice-modulization branch from 5fbc063 to 74613ae Compare February 21, 2025 03:25
@@ -124,7 +124,7 @@ public final class ApiEndpointsV1

public static final String CONNECTED_CLIENT_STATS_ROUTE = API_V1 + CASSANDRA + "/stats/connected-clients";

public static final String OPERATIONAL_JOBS = "/operational-jobs";
private static final String OPERATIONAL_JOBS = "/operational-jobs";
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 is not the route. It is the intermediate string to define routes that share the same prefix. Such intermediate string does not need to be exposed.

Comment on lines -79 to -83
api(project(path: ":server")) {
exclude(group: 'org.apache.logging.log4j')
exclude(group: 'org.slf4j')
exclude(group: 'ch.qos.logback')
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excluding the dependencies loses the test log of sidecar in the pacakge

SchemaResponse response = getBlocking(trustedClient()
.get(server.actualPort(), "localhost", testRoute)
.send()
.expecting(HttpResponseExpectation.SC_OK))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

expecting is replacing the deprecated expect

@Override
public String toString()
{
return keyspaceName() + '.' + tableName();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The string value is used when registering table schema fails

/**
* Initializer that retries until sidecar schema is initialized. Once initialized, it un-schedules itself.
*/
private class SidecarSchemaInitializer implements PeriodicTask
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SidecarSchemaInitializer is moved to its own class file.

@Override
public String toString()
{
return keyspaceName();
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 guy has multiple tables. Therefore showing the keyspace name only.

{
Objects.requireNonNull(router, "Router must be set");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

router must present now in the VertxRoute lambda

@yifan-c yifan-c force-pushed the CASSSIDECAR-208/guice-modulization branch 2 times, most recently from 66166a6 to d3f15ac Compare February 23, 2025 00:50
Copy link
Contributor

@sarankk sarankk left a comment

Choose a reason for hiding this comment

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

Thanks Yifan, modules look neat and well organized. Left some comments

CQLSessionProvider cqlSessionProvider)
{
super(restoreSlicesSchema, cqlSessionProvider);
super(sidecarSchema.tableSchema(RestoreSlicesSchema.class), cqlSessionProvider);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should we call this method tableSchemaByClass ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is to get the instance using the class to look up.

else if (ex instanceof SidecarSchemaModificationException)
{
LOGGER.warn("Failed to modify schema", ex);
schemaMetrics.failedModifications.metric.update(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are initializing, we should use failedInitializations here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original implementation is reporting as failedModifications. I would like to keep it as-is.

@@ -16,7 +16,7 @@
* limitations under the License.
*/

package org.apache.cassandra.sidecar.routes;
package org.apache.cassandra.sidecar.handlers;
Copy link
Contributor

Choose a reason for hiding this comment

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

My only concern with this package name change is, currently we have just API route specific handlers here, other speciality handlers in their respective packages, which keeps handlers more organized. Naming it generic, might lead to all handlers being put here. How about moving handlers package under routes package?

VertxRoute cassandraSchemaRoute(RouteBuilder.Factory factory,
SchemaHandler schemaHandler)
{
return factory.builderForRoute()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Getting schema information doesn't seem like a operation related. We can leave it as is for now, but later we can move it to CassandraModule or CassandraInfoModule?. Same with ring, token, gossip endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cassandra related operations, i.e. trigger task or retrieving information, are grouped in the same module. If splitting the module up helps with readability, we can do that in the future.

new AuthModule(),
new CassandraOperationsModule(),
new CdcModule(),
new ConfigurationModule(confPath),
Copy link
Contributor

@sarankk sarankk Mar 4, 2025

Choose a reason for hiding this comment

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

Nit: If we have VertxSetupModule we can move ConfigurationModule after it for easier reading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this PR, I would like to stick to the idea of group bindings by feature. VertxSetup is not a feature.

Btw, the order of the modules in the list does not affect bindings. They are just sorted alphabetically to look neat.

/**
* Allows {@literal @}{@link ProvidesIntoMap} to specify a {@link ClassKey} class as map key.
* The class must extends from {@link ClassKey}
* <p>The annotation name {@link KeyClassMapKey} is read as "map key type is of {@link ClassKey} class"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Shall we name this class to ClassKeyMapKey ? that way name matches this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The full name was ClassKey Class MapKey, map key using the class of ClassKey. There are 2 "Class" in the name, so I dropped one of them. It does not use the ClassKey instance, but its class. Therefore, the later "Class` is reserved.

TypeLiteral<Class<? extends ClassKey>> keyType = new TypeLiteral<>() {};
TypeLiteral<PeriodicTask> valueType = new TypeLiteral<>() {};
MapBinder<Class<? extends ClassKey>, PeriodicTask> periodicTaskMapBinder = MapBinder.newMapBinder(binder(), keyType, valueType);
periodicTaskMapBinder.addBinding(PeriodicTaskMapKeys.RestoreJobDiscovererKey.class).to(RestoreJobDiscoverer.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why do we inject for these periodic tasks and bind them this way. Where as for HealthCheckPeriodicTask we provide with ProvidesIntoMap

Copy link
Contributor Author

@yifan-c yifan-c Mar 5, 2025

Choose a reason for hiding this comment

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

They are equivalent. I wanted to demo that there are different ways to add bindings. Plus, binding to a class (that is annotated with @Inject) has simpler code.

@yifan-c yifan-c force-pushed the CASSSIDECAR-208/guice-modulization branch from 55a6e82 to ea31d0e Compare March 8, 2025 06:36
Patch by Yifan Cai; Reviewed by TBD for CASSSIDECAR-208
@yifan-c yifan-c force-pushed the CASSSIDECAR-208/guice-modulization branch from ea31d0e to ec0d834 Compare March 8, 2025 06:59
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.

2 participants