Exemplo n.º 1
0
  @SuppressWarnings("resource") // log and writer closed by SSTableTxnWriter
  public SSTableTxnWriter createFlushWriter(
      String filename, PartitionColumns columns, EncodingStats stats) {
    // we operate "offline" here, as we expose the resulting reader consciously when done
    // (although we may want to modify this behaviour in future, to encapsulate full flush behaviour
    // in LifecycleTransaction)
    LifecycleTransaction txn = null;
    try {
      txn = LifecycleTransaction.offline(OperationType.FLUSH);
      MetadataCollector sstableMetadataCollector =
          new MetadataCollector(cfs.metadata.comparator)
              .commitLogIntervals(
                  new IntervalSet(commitLogLowerBound.get(), commitLogUpperBound.get()));

      return new SSTableTxnWriter(
          txn,
          cfs.createSSTableMultiWriter(
              Descriptor.fromFilename(filename),
              (long) partitions.size(),
              ActiveRepairService.UNREPAIRED_SSTABLE,
              sstableMetadataCollector,
              new SerializationHeader(true, cfs.metadata, columns, stats),
              txn));
    } catch (Throwable t) {
      if (txn != null) txn.close();
      throw t;
    }
  }
  @SuppressWarnings("resource")
  public MaxSSTableSizeWriter(
      ColumnFamilyStore cfs,
      Directories directories,
      LifecycleTransaction txn,
      Set<SSTableReader> nonExpiredSSTables,
      long maxSSTableSize,
      int level,
      boolean offline,
      boolean keepOriginals) {
    super(cfs, directories, txn, nonExpiredSSTables, offline, keepOriginals);
    this.allSSTables = txn.originals();
    this.level = level;
    this.maxSSTableSize = maxSSTableSize;

    long totalSize = getTotalWriteSize(nonExpiredSSTables, estimatedTotalKeys, cfs, txn.opType());
    expectedWriteSize = Math.min(maxSSTableSize, totalSize);
    estimatedSSTables = Math.max(1, totalSize / maxSSTableSize);
  }