yifan-c commented on code in PR #147: URL: https://github.com/apache/cassandra-sidecar/pull/147#discussion_r1851032769
########## server/src/main/java/org/apache/cassandra/sidecar/routes/cdc/ListCDCDirHandler.java: ########## @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.routes.cdc; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.lang3.tuple.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.json.Json; +import io.vertx.core.net.SocketAddress; +import io.vertx.ext.web.RoutingContext; +import org.apache.cassandra.sidecar.common.response.ListCDCSegmentResponse; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.config.ServiceConfiguration; +import org.apache.cassandra.sidecar.config.SidecarConfiguration; +import org.apache.cassandra.sidecar.routes.AbstractHandler; +import org.apache.cassandra.sidecar.utils.CDCUtil; +import org.apache.cassandra.sidecar.utils.CassandraInputValidator; +import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher; + +import static org.apache.cassandra.sidecar.utils.CDCUtil.getIdxFileName; +import static org.apache.cassandra.sidecar.utils.CDCUtil.getLogFilePrefix; +import static org.apache.cassandra.sidecar.utils.CDCUtil.isIndexFile; +import static org.apache.cassandra.sidecar.utils.CDCUtil.parseIndexFile; + +/** + * Provides REST endpoint for listing commit logs in CDC directory. + */ +@Singleton +public class ListCDCDirHandler extends AbstractHandler<Void> +{ + private static final Logger LOGGER = LoggerFactory.getLogger(ListCDCDirHandler.class); + private final ServiceConfiguration config; + + @Inject + public ListCDCDirHandler(InstanceMetadataFetcher metadataFetcher, + SidecarConfiguration config, + ExecutorPools executorPools, + CassandraInputValidator validator) + { + super(metadataFetcher, executorPools, validator); + this.config = config.serviceConfiguration(); + } + + @Override + protected void handleInternal(RoutingContext context, + HttpServerRequest httpRequest, + String host, + SocketAddress remoteAddress, + Void request) + { + String cdcDir = metadataFetcher.instance(host).cdcDir(); + ListCDCSegmentResponse listCDCSegmentResponse = new ListCDCSegmentResponse(config.host(), + config.port(), + new LinkedList<>()); + try + { + addResources(cdcDir, listCDCSegmentResponse); Review Comment: The benefit of async is to improve concurrency. In the context of server, it means the server can handle more concurrent requests. Vertx is based on Netty. A good thumb of rule is avoiding block the event loop thread. Otherwise, the netty server experiences degraded concurrency and higher latency. Vertx handler runs on event loop thread directly, unless added as blockingHandler. For expensive computations (e.g. I/O access), it is generally preferred to dispatch to a dedicated thread pool to avoid blocking the event loop thread. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

