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.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.Cell;
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  
32  /**
33   * Handler to seek storefiles in parallel.
34   */
35  @InterfaceAudience.Private
36  public class ParallelSeekHandler extends EventHandler {
37    private static final Log LOG = LogFactory.getLog(ParallelSeekHandler.class);
38    private KeyValueScanner scanner;
39    private Cell keyValue;
40    private long readPoint;
41    private CountDownLatch latch;
42    private Throwable err = null;
43  
44    public ParallelSeekHandler(KeyValueScanner scanner,Cell keyValue, 
45        long readPoint, CountDownLatch latch) {
46      super(null, EventType.RS_PARALLEL_SEEK);
47      this.scanner = scanner;
48      this.keyValue = keyValue;
49      this.readPoint = readPoint;
50      this.latch = latch;
51    }
52  
53    @Override
54    public void process() {
55      try {
56        scanner.seek(keyValue);
57      } catch (IOException e) {
58        LOG.error("", e);
59        setErr(e);
60      } finally {
61        latch.countDown();
62      }
63    }
64  
65    public Throwable getErr() {
66      return err;
67    }
68  
69    public void setErr(Throwable err) {
70      this.err = err;
71    }
72  }