Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.hadoop.hbase.regionserver;
 
 import static org.apache.hadoop.hbase.regionserver.StripeStoreFileManager.OPEN_KEY;
 
 import java.util.List;
 
 
Stripe implementation of StoreFlusher. Flushes files either into L0 file w/o metadata, or into separate striped files, avoiding L0.
 
 public class StripeStoreFlusher extends StoreFlusher {
   private static final Log LOG = LogFactory.getLog(StripeStoreFlusher.class);
   private final Object flushLock = new Object();
   private final StripeCompactionPolicy policy;
 
   public StripeStoreFlusher(Configuration confStore store,
       StripeCompactionPolicy policyStripeStoreFileManager stripes) {
     super(confstore);
     this. = policy;
     this. = stripes;
   }
 
   @Override
   public List<PathflushSnapshot(SortedSet<KeyValuesnapshotlong cacheFlushSeqNum,
       final TimeRangeTracker trackerAtomicLong flushedSizeMonitoredTask status)
           throws IOException {
     List<Pathresult = new ArrayList<Path>();
     int kvCount = snapshot.size();
     if (kvCount == 0) return result// don't flush if there are no entries
 
     long smallestReadPoint = .getSmallestReadPoint();
     InternalScanner scanner = createScanner(snapshotsmallestReadPoint);
     if (scanner == null) {
       return result// NULL scanner returned from coprocessor hooks means skip normal processing
     }
 
     // Let policy select flush method.
     StripeFlushRequest req = this..selectFlush(this.kvCount);
 
     long flushedBytes = 0;
     boolean success = false;
     StripeMultiFileWriter mw = null;
     try {
       mw = req.createWriter(); // Writer according to the policy.
       StripeMultiFileWriter.WriterFactory factory = createWriterFactory(trackerkvCount);
       StoreScanner storeScanner = (scanner instanceof StoreScanner) ? (StoreScanner)scanner : null;
       mw.init(storeScannerfactory.getComparator());
 
       synchronized () {
         flushedBytes = performFlush(scannermwsmallestReadPoint);
         result = mw.commitWriters(cacheFlushSeqNumfalse);
         success = true;
       }
     } finally {
       if (!success && (mw != null)) {
         for (Path leftoverFile : mw.abortWriters()) {
           try {
             .getFileSystem().delete(leftoverFilefalse);
           } catch (Exception e) {
             .error("Failed to delete a file after failed flush: " + e);
           }
        }
      }
      flushedSize.set(flushedBytes);
      try {
        scanner.close();
      } catch (IOException ex) {
        .warn("Failed to close flush scanner, ignoring"ex);
      }
    }
    return result;
  }
      final TimeRangeTracker trackerfinal long kvCount) {
    return new StripeMultiFileWriter.WriterFactory() {
      @Override
      public Writer createWriter() throws IOException {
        StoreFile.Writer writer = .createWriterInTmp(
            kvCount.getFamily().getCompression(), falsetruetrue);
        writer.setTimeRangeTracker(tracker);
        return writer;
      }
    };
  }

  
Stripe flush request wrapper that writes a non-striped file.
  public static class StripeFlushRequest {
    public StripeMultiFileWriter createWriter() throws IOException {
      StripeMultiFileWriter writer =
      writer.setNoStripeMetadata();
      return writer;
    }
  }

  
Stripe flush request wrapper based on boundaries.
  public static class BoundaryStripeFlushRequest extends StripeFlushRequest {
    private final List<byte[]> targetBoundaries;

    

Parameters:
targetBoundaries New files should be written with these boundaries.
    public BoundaryStripeFlushRequest(List<byte[]> targetBoundaries) {
      this. = targetBoundaries;
    }
    @Override
    public StripeMultiFileWriter createWriter() throws IOException {
      return new StripeMultiFileWriter.BoundaryMultiWriter(nullnull);
    }
  }

  
Stripe flush request wrapper based on size.
  public static class SizeStripeFlushRequest extends StripeFlushRequest {
    private final int targetCount;
    private final long targetKvs;

    

Parameters:
targetCount The maximum number of stripes to flush into.
targetKvs The KV count of each segment. If targetKvs*targetCount is less than total number of kvs, all the overflow data goes into the last stripe.
    public SizeStripeFlushRequest(int targetCountlong targetKvs) {
      this. = targetCount;
      this. = targetKvs;
    }
    @Override
    public StripeMultiFileWriter createWriter() throws IOException {
      return new StripeMultiFileWriter.SizeMultiWriter(
          this.this.);
    }
  }
New to GrepCode? Check out our FAQ X