code: private static int calculateNodeId(int partitionId, BinaryRequest request, CouchbaseBucketConfig config) {
          boolean useFastForward = request.retryCount() > 0 && config.hasFastForwardMap();
  
          if (request instanceof ReplicaGetRequest) {
              return config.nodeIndexForReplica(partitionId, ((ReplicaGetRequest) request).replica() - 1, useFastForward);
          } else if (request instanceof ObserveRequest && ((ObserveRequest) request).replica() > 0) {
              return config.nodeIndexForReplica(partitionId, ((ObserveRequest) request).replica() - 1, useFastForward);
          } else if (request instanceof ObserveSeqnoRequest && ((ObserveSeqnoRequest) request).replica() > 0) {
              return config.nodeIndexForReplica(partitionId, ((ObserveSeqnoRequest) request).replica() - 1, useFastForward);
          } else {
              return config.nodeIndexForMaster(partitionId, useFastForward);
          }
      }
docs: Helper method to calculate the node if for the given partition and request type.
  
  @param partitionId the partition id.
  @param request the request used.
  @param config the current bucket configuration.
  @return the calculated node id.