vinothchandar commented on a change in pull request #692: HUDI-70 : Making DeltaStreamer run in continuous mode with concurrent compaction URL: https://github.com/apache/incubator-hudi/pull/692#discussion_r292155938
########## File path: hoodie-utilities/src/main/java/com/uber/hoodie/utilities/deltastreamer/AsyncCompactor.java ########## @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2019 Uber Technologies, Inc. ([email protected]) + * + * Licensed 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 com.uber.hoodie.utilities.deltastreamer; + +import com.uber.hoodie.HoodieWriteClient; +import com.uber.hoodie.WriteStatus; +import com.uber.hoodie.common.table.timeline.HoodieInstant; +import com.uber.hoodie.common.util.collection.Pair; +import com.uber.hoodie.exception.HoodieException; +import com.uber.hoodie.exception.HoodieIOException; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.spark.api.java.JavaRDD; +import org.apache.spark.api.java.JavaSparkContext; + +/** + * Async Compactor Service tha runs in separate thread. Currently, only one compactor is allowed to run at any time. + */ +public class AsyncCompactor extends AbstractBaseService { + + private final int maxConcurrentCompaction; + private transient HoodieWriteClient compactionClient; + private transient JavaSparkContext jssc; + private transient BlockingQueue<HoodieInstant> pendingCompactions = new LinkedBlockingQueue<>(); + + public AsyncCompactor(JavaSparkContext jssc, HoodieWriteClient client) { + this.jssc = jssc; + this.compactionClient = client; + // Only allow 1 compactor to run in parallel till Incremental View on MOR is fully implemented. + this.maxConcurrentCompaction = 1; + } + + /** + * Enqueues new Pending compaction + * @param instant + */ + public void enqueuePendingCompaction(HoodieInstant instant) { + pendingCompactions.add(instant); + } + + /** + * Start Compaction Service + * @return + */ + protected Pair<CompletableFuture, ExecutorService> startService() { + ExecutorService executor = Executors.newFixedThreadPool(maxConcurrentCompaction); + List<CompletableFuture<Boolean>> compactionFutures = + IntStream.range(0, maxConcurrentCompaction).mapToObj(i -> CompletableFuture.supplyAsync(() -> { + HoodieInstant instant = null; + try { + // Set Compactor Pool Name for allowing users to prioritize compaction + log.info("Setting Spark Pool name for compaction to " + SchedulerConfGenerator.COMPACT_POOL_NAME); + jssc.setLocalProperty("spark.scheduler.pool", SchedulerConfGenerator.COMPACT_POOL_NAME); + + while (!isShutdownRequested()) { + log.info("Compactor waiting for next instant for compaction upto 60 seconds"); + instant = pendingCompactions.poll(60, TimeUnit.SECONDS); Review comment: move to a final variable? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
