001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver.handler;
019
020import java.io.IOException;
021import java.util.concurrent.CountDownLatch;
022import org.apache.hadoop.hbase.Cell;
023import org.apache.hadoop.hbase.executor.EventHandler;
024import org.apache.hadoop.hbase.executor.EventType;
025import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
026import org.apache.yetus.audience.InterfaceAudience;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030/**
031 * Handler to seek storefiles in parallel.
032 */
033@InterfaceAudience.Private
034public class ParallelSeekHandler extends EventHandler {
035  private static final Logger LOG = LoggerFactory.getLogger(ParallelSeekHandler.class);
036  private KeyValueScanner scanner;
037  private Cell keyValue;
038  private long readPoint;
039  private CountDownLatch latch;
040  private Throwable err = null;
041
042  public ParallelSeekHandler(KeyValueScanner scanner, Cell keyValue, long readPoint,
043    CountDownLatch latch) {
044    super(null, EventType.RS_PARALLEL_SEEK);
045    this.scanner = scanner;
046    this.keyValue = keyValue;
047    this.readPoint = readPoint;
048    this.latch = latch;
049  }
050
051  @Override
052  public void process() {
053    try {
054      scanner.seek(keyValue);
055    } catch (IOException e) {
056      LOG.error("", e);
057      setErr(e);
058    } finally {
059      latch.countDown();
060    }
061  }
062
063  public Throwable getErr() {
064    return err;
065  }
066
067  public void setErr(Throwable err) {
068    this.err = err;
069  }
070}