How do I verify the consistency level configured on the Java driver?

Viewed 25

We are currently upgrading from 3.x to 4.x. We are using the programaticBuilder for the DriverConfigLoader. Below is the code for same.

   DriverConfigLoader driverConfigLoader = DriverConfigLoader.programmaticBuilder()
     .withDuration(DefaultDriverOption.HEARTBEAT_INTERVAL, Duration.ofSeconds(60))
     .withString(DefaultDriverOption.REQUEST_CONSISTENCY, ConsistencyLevel.LOCAL_QUORUM.name())
     .withString(DefaultDriverOption.RETRY_POLICY_CLASS, "DefaultRetryPolicy")
     .withString(DefaultDriverOption.RECONNECTION_POLICY_CLASS, "ConstantReconnectionPolicy")
     .withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, Duration.ofSeconds(5))
     .withString(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, "DcInferringLoadBalancingPolicy")
     .build();

Wanted to check how to verify this correct setting of ConsistencyLevel when the write/read happens. is there a debug log print mechanism available for this purpose.

2 Answers

@Shobby, for DataStax Java Driver 4.x version you can do something like this:

CqlSession session = CqlSession.builder().withConfigLoader(driverConfigLoader).build();
DriverConfig config = session.getContext().getConfig();
config.getProfiles().forEach(
    (name, profile) -> {
      System.out.println("Profile: " + name);
      profile.entrySet().forEach(System.out::println);
      System.out.println();
    });

This will print the values for every defined option in every defined profile. It won't print undefined options though. Hope this helps!

Your question suggests that you don't trust that the configured consistency level is not being honoured by the driver so you're looking for proof that it does. To me it doesn't make sense. Perhaps you ran into another problem related to request consistency and you should post information about that instead.

In any case, the DriverConfigLoader is provided for convenience but we discourage its use because it means that you are hard-coding configuration within your app which is bad practice. If you need to make a change, you are forced to have to recompile your app again by virtue that the configuration is hardcoded. Only use the programmatic loader if you have a very specific reason.

The recommended method for configuring the driver options is to use an application configuration file (application.conf). The advantages include:

  • driver options is configured in a central location,
  • hot-reload support, and
  • changes do not require recompiling the app.

To set the basic request consistency to LOCAL_QUORUM:

datastax-java-driver {
  basic {
    request {
      consistency = LOCAL_QUORUM
    }
  }
}

For details, see Configuring the Java driver. Cheers!

Related