View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.regionserver.handler;
20  
21  import java.io.IOException;
22  import java.util.concurrent.CountDownLatch;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.hadoop.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.KeyValue;
28  import org.apache.hadoop.hbase.executor.EventHandler;
29  import org.apache.hadoop.hbase.executor.EventType;
30  import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
31  import org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl;
32  
33  /**
34   * Handler to seek storefiles in parallel.
35   */
36  @InterfaceAudience.Private
37  public class ParallelSeekHandler extends EventHandler {
38    private static final Log LOG = LogFactory.getLog(ParallelSeekHandler.class);
39    private KeyValueScanner scanner;
40    private KeyValue keyValue;
41    private long readPoint;
42    private CountDownLatch latch;
43    private Throwable err = null;
44  
45    public ParallelSeekHandler(KeyValueScanner scanner,KeyValue keyValue,
46        long readPoint, CountDownLatch latch) {
47      super(null, EventType.RS_PARALLEL_SEEK);
48      this.scanner = scanner;
49      this.keyValue = keyValue;
50      this.readPoint = readPoint;
51      this.latch = latch;
52    }
53  
54    @Override
55    public void process() {
56      try {
57        scanner.seek(keyValue);
58      } catch (IOException e) {
59        LOG.error("", e);
60        setErr(e);
61      } finally {
62        latch.countDown();
63      }
64    }
65  
66    public Throwable getErr() {
67      return err;
68    }
69  
70    public void setErr(Throwable err) {
71      this.err = err;
72    }
73  }