Class CompactionAwareWriter
java.lang.Object
org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
org.apache.cassandra.db.compaction.writers.CompactionAwareWriter
- All Implemented Interfaces:
AutoCloseable,Transactional
- Direct Known Subclasses:
DefaultCompactionWriter,MajorLeveledCompactionWriter,MaxSSTableSizeWriter,ShardedCompactionWriter,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.StateNested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional
Transactional.AbstractTransactional -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ColumnFamilyStoreprotected Directories.DataDirectoryprotected final Directoriesprotected final longprotected final booleanprotected static final org.slf4j.Loggerprotected final longprotected final longprotected final Set<SSTableReader>protected final TimeUUIDprotected final SSTableRewriterprotected final LifecycleTransaction -
Constructor Summary
ConstructorsConstructorDescriptionCompactionAwareWriter(ColumnFamilyStore cfs, Directories directories, LifecycleTransaction txn, Set<SSTableReader> nonExpiredSSTables, boolean keepOriginals) -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanappend(UnfilteredRowIterator partition) Writes a partition in an implementation specific wayprotected Throwableprotected Throwableprotected ThrowabledoPostCleanup(Throwable accumulate) perform an exception-safe post-abort cleanupprotected voidDo any preparatory work prior to commit.longestimated number of keys we should writefinish()we are done, return the finished sstables so that the caller can mark the old ones as compactedThe directories we can write toprotected longfinal FilegetWriteDirectory(Iterable<SSTableReader> sstables, long estimatedWriteSize) Return a directory where we can expect expectedWriteSize to fit.protected booleanSwitches the file location and writer and returns true if the new key should be placed in a different data directory.protected voidSwitches the writer if necessary, i.e.protected SSTableWriter.Builder<?,?> newWriterBuilder(Descriptor descriptor) It is up to the caller to set the following fields: -SSTableWriter.Builder.setKeyCount(long), -SSTableWriter.Builder.setSerializationHeader(SerializationHeader)and, -SSTableWriter.Builder.setMetadataCollector(MetadataCollector)protected booleanrealAppend(UnfilteredRowIterator partition) setRepairedAt(long repairedAt) protected abstract booleanReturns true if the writer should be switched for reasons other than switching to a new data directory (e.g.protected abstract longReturns the key count with which created sstables should be set up.protected intReturns the level that should be used when creating sstables.protected SSTableWritersstableWriter(Directories.DataDirectory directory, DecoratedKey nextKey) protected voidswitchCompactionWriter(Directories.DataDirectory directory, DecoratedKey nextKey) 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, stateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cassandra.utils.concurrent.Transactional
abort, close, commit, prepareToCommit
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
cfs
-
directories
-
nonExpiredSSTables
-
estimatedTotalKeys
protected final long estimatedTotalKeys -
maxAge
protected final long maxAge -
minRepairedAt
protected final long minRepairedAt -
pendingRepair
-
isTransient
protected final boolean isTransient -
sstableWriter
-
txn
-
currentDirectory
-
-
Constructor Details
-
CompactionAwareWriter
public CompactionAwareWriter(ColumnFamilyStore cfs, Directories directories, LifecycleTransaction txn, Set<SSTableReader> nonExpiredSSTables, boolean keepOriginals)
-
-
Method Details
-
doAbort
- Specified by:
doAbortin classTransactional.AbstractTransactional
-
doCommit
- 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
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
Writes a partition in an implementation specific way- Parameters:
partition- the partition to append- Returns:
- true if the partition was written, false otherwise
-
getSStableDirectory
- Throws:
IOException
-
doPostCleanup
Description copied from class:Transactional.AbstractTransactionalperform an exception-safe post-abort cleanup- Overrides:
doPostCleanupin classTransactional.AbstractTransactional
-
realAppend
-
maybeSwitchWriter
Switches the writer if necessary, i.e. if the new key should be placed in a different data directory, or if the specific strategy has decided a new sstable is needed. Guaranteed to be called before the first call to realAppend. -
maybeSwitchLocation
Switches the file location and writer and returns true if the new key should be placed in a different data directory. -
shouldSwitchWriterInCurrentLocation
Returns true if the writer should be switched for reasons other than switching to a new data directory (e.g. because an sstable size limit has been reached). -
switchCompactionWriter
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-nextKey-
-
sstableWriter
-
sstableLevel
protected int sstableLevel()Returns the level that should be used when creating sstables. -
sstableKeyCount
protected abstract long sstableKeyCount()Returns the key count with which created sstables should be set up. -
getDirectories
The directories we can write to -
getWriteDirectory
public Directories.DataDirectory getWriteDirectory(Iterable<SSTableReader> sstables, long estimatedWriteSize) Return a directory where we can expect expectedWriteSize to fit.- Parameters:
sstables- the sstables to compact
-
setRepairedAt
-
getExpectedWriteSize
protected long getExpectedWriteSize() -
newWriterBuilder
It is up to the caller to set the following fields: -SSTableWriter.Builder.setKeyCount(long), -SSTableWriter.Builder.setSerializationHeader(SerializationHeader)and, -SSTableWriter.Builder.setMetadataCollector(MetadataCollector)
-