Class CompactionAwareWriter
- java.lang.Object
-
- org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
-
- org.apache.cassandra.db.compaction.writers.CompactionAwareWriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable,Transactional
- Direct Known Subclasses:
DefaultCompactionWriter,MajorLeveledCompactionWriter,MaxSSTableSizeWriter,SplittingSizeTieredCompactionWriter
public abstract class CompactionAwareWriter extends Transactional.AbstractTransactional implements Transactional
Class that abstracts away the actual writing of files to make it possible to use CompactionTask for more use cases.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
Transactional.AbstractTransactional.State
-
Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional
Transactional.AbstractTransactional
-
-
Field Summary
Fields Modifier and Type Field Description protected ColumnFamilyStorecfsprotected Directoriesdirectoriesprotected longestimatedTotalKeysprotected booleanisTransientprotected static org.slf4j.Loggerloggerprotected longmaxAgeprotected longminRepairedAtprotected java.util.Set<SSTableReader>nonExpiredSSTablesprotected TimeUUIDpendingRepairprotected SSTableRewritersstableWriterprotected LifecycleTransactiontxn
-
Constructor Summary
Constructors Constructor Description CompactionAwareWriter(ColumnFamilyStore cfs, Directories directories, LifecycleTransaction txn, java.util.Set<SSTableReader> nonExpiredSSTables, boolean keepOriginals)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanappend(UnfilteredRowIterator partition)Writes a partition in an implementation specific wayprotected java.lang.ThrowabledoAbort(java.lang.Throwable accumulate)protected java.lang.ThrowabledoCommit(java.lang.Throwable accumulate)protected java.lang.ThrowabledoPostCleanup(java.lang.Throwable accumulate)perform an exception-safe post-abort cleanupprotected voiddoPrepare()Do any preparatory work prior to commit.longestimatedKeys()estimated number of keys we should writejava.util.Collection<SSTableReader>finish()we are done, return the finished sstables so that the caller can mark the old ones as compactedDirectoriesgetDirectories()The directories we can write toprotected longgetExpectedWriteSize()Directories.DataDirectorygetWriteDirectory(java.lang.Iterable<SSTableReader> sstables, long estimatedWriteSize)Return a directory where we can expect expectedWriteSize to fit.protected voidmaybeSwitchWriter(DecoratedKey key)Guaranteed to be called before the first call to realAppend.protected abstract booleanrealAppend(UnfilteredRowIterator partition)CompactionAwareWritersetRepairedAt(long repairedAt)protected abstract voidswitchCompactionLocation(Directories.DataDirectory directory)Implementations of this method should finish the current sstable writer and start writing to this directory.-
Methods inherited from class org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
abort, abort, close, commit, commit, doPreCleanup, prepareToCommit, state
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.utils.concurrent.Transactional
abort, close, commit, prepareToCommit
-
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
cfs
protected final ColumnFamilyStore cfs
-
directories
protected final Directories directories
-
nonExpiredSSTables
protected final java.util.Set<SSTableReader> nonExpiredSSTables
-
estimatedTotalKeys
protected final long estimatedTotalKeys
-
maxAge
protected final long maxAge
-
minRepairedAt
protected final long minRepairedAt
-
pendingRepair
protected final TimeUUID pendingRepair
-
isTransient
protected final boolean isTransient
-
sstableWriter
protected final SSTableRewriter sstableWriter
-
txn
protected final LifecycleTransaction txn
-
-
Constructor Detail
-
CompactionAwareWriter
public CompactionAwareWriter(ColumnFamilyStore cfs, Directories directories, LifecycleTransaction txn, java.util.Set<SSTableReader> nonExpiredSSTables, boolean keepOriginals)
-
-
Method Detail
-
doAbort
protected java.lang.Throwable doAbort(java.lang.Throwable accumulate)
- Specified by:
doAbortin classTransactional.AbstractTransactional
-
doCommit
protected java.lang.Throwable doCommit(java.lang.Throwable accumulate)
- Specified by:
doCommitin classTransactional.AbstractTransactional
-
doPrepare
protected void doPrepare()
Description copied from class:Transactional.AbstractTransactionalDo any preparatory work prior to commit. This method should throw any exceptions that can be encountered during the finalization of the behaviour.- Specified by:
doPreparein classTransactional.AbstractTransactional
-
finish
public java.util.Collection<SSTableReader> finish()
we are done, return the finished sstables so that the caller can mark the old ones as compacted- Overrides:
finishin classTransactional.AbstractTransactional- Returns:
- all the written sstables sstables
-
estimatedKeys
public long estimatedKeys()
estimated number of keys we should write
-
append
public final boolean append(UnfilteredRowIterator partition)
Writes a partition in an implementation specific way- Parameters:
partition- the partition to append- Returns:
- true if the partition was written, false otherwise
-
doPostCleanup
protected java.lang.Throwable doPostCleanup(java.lang.Throwable accumulate)
Description copied from class:Transactional.AbstractTransactionalperform an exception-safe post-abort cleanup- Overrides:
doPostCleanupin classTransactional.AbstractTransactional
-
realAppend
protected abstract boolean realAppend(UnfilteredRowIterator partition)
-
maybeSwitchWriter
protected void maybeSwitchWriter(DecoratedKey key)
Guaranteed to be called before the first call to realAppend.- Parameters:
key-
-
switchCompactionLocation
protected abstract void switchCompactionLocation(Directories.DataDirectory directory)
Implementations of this method should finish the current sstable writer and start writing to this directory. Called once before starting to append and then whenever we see a need to start writing to another directory.- Parameters:
directory-
-
getDirectories
public Directories getDirectories()
The directories we can write to
-
getWriteDirectory
public Directories.DataDirectory getWriteDirectory(java.lang.Iterable<SSTableReader> sstables, long estimatedWriteSize)
Return a directory where we can expect expectedWriteSize to fit.- Parameters:
sstables- the sstables to compact- Returns:
-
setRepairedAt
public CompactionAwareWriter setRepairedAt(long repairedAt)
-
getExpectedWriteSize
protected long getExpectedWriteSize()
-
-