Package org.apache.cassandra.io.sstable
Class SSTableRewriter
- java.lang.Object
-
- org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
-
- org.apache.cassandra.io.sstable.SSTableRewriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,Transactional
public class SSTableRewriter extends Transactional.AbstractTransactional implements Transactional
Wraps one or more writers as output for rewriting one or more readers: every sstable_preemptive_open_interval we look in the summary we're collecting for the latest writer for the penultimate key that we know to have been fully flushed to the index file, and then double check that the key is fully present in the flushed data file. Then we move the starts of each reader forwards to that point, replace them in the Tracker, and attach a runnable for on-close (i.e. when all references expire) that drops the page cache prior to that key position hard-links are created for each partially written sstable so that readers opened against them continue to work past renaming of the temporary file, which is deleted once all readers against the hard-link have been closed. If for any reason the writer is rolled over, we immediately rename and fully expose the completed file in the Tracker. On abort, we restore the original lower bounds to the existing readers and delete any temporary files we had in progress, but leave any hard-links in place for the readers we opened, and clean-up when the readers finish as we would do if we had finished successfully.
-
-
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 static boolean
disableEarlyOpeningForTests
-
Constructor Summary
Constructors Constructor Description SSTableRewriter(ILifecycleTransaction transaction, long maxAge, long preemptiveOpenInterval, boolean keepOriginals)
Deprecated.See CASSANDRA-11148
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractRowIndexEntry
append(UnfilteredRowIterator partition)
long
bytesWritten()
static SSTableRewriter
construct(ColumnFamilyStore cfs, ILifecycleTransaction transaction, boolean keepOriginals, long maxAge)
static SSTableRewriter
constructKeepingOriginals(ILifecycleTransaction transaction, boolean keepOriginals, long maxAge)
static SSTableRewriter
constructWithoutEarlyOpening(ILifecycleTransaction transaction, boolean keepOriginals, long maxAge)
SSTableWriter
currentWriter()
protected java.lang.Throwable
doAbort(java.lang.Throwable accumulate)
protected java.lang.Throwable
doCommit(java.lang.Throwable accumulate)
protected void
doPrepare()
Do any preparatory work prior to commit.java.util.List<SSTableReader>
finish()
Finishes the new file(s) Creates final files, adds the new files to the Tracker (via replaceReader).java.util.List<SSTableReader>
finished()
void
forEachWriter(java.util.function.Consumer<SSTableWriter> op)
SSTableRewriter
setRepairedAt(long repairedAt)
void
switchWriter(SSTableWriter newWriter)
void
throwDuringPrepare(boolean earlyException)
AbstractRowIndexEntry
tryAppend(UnfilteredRowIterator partition)
-
Methods inherited from class org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
abort, abort, close, commit, commit, doPostCleanup, 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
-
-
-
-
Constructor Detail
-
SSTableRewriter
@Deprecated(since="3.4") public SSTableRewriter(ILifecycleTransaction transaction, long maxAge, long preemptiveOpenInterval, boolean keepOriginals)
Deprecated.See CASSANDRA-11148
-
-
Method Detail
-
constructKeepingOriginals
public static SSTableRewriter constructKeepingOriginals(ILifecycleTransaction transaction, boolean keepOriginals, long maxAge)
-
constructWithoutEarlyOpening
public static SSTableRewriter constructWithoutEarlyOpening(ILifecycleTransaction transaction, boolean keepOriginals, long maxAge)
-
construct
public static SSTableRewriter construct(ColumnFamilyStore cfs, ILifecycleTransaction transaction, boolean keepOriginals, long maxAge)
-
currentWriter
public SSTableWriter currentWriter()
-
bytesWritten
public long bytesWritten()
-
forEachWriter
public void forEachWriter(java.util.function.Consumer<SSTableWriter> op)
-
append
public AbstractRowIndexEntry append(UnfilteredRowIterator partition)
-
tryAppend
public AbstractRowIndexEntry tryAppend(UnfilteredRowIterator partition)
-
doAbort
protected java.lang.Throwable doAbort(java.lang.Throwable accumulate)
- Specified by:
doAbort
in classTransactional.AbstractTransactional
-
doCommit
protected java.lang.Throwable doCommit(java.lang.Throwable accumulate)
- Specified by:
doCommit
in classTransactional.AbstractTransactional
-
switchWriter
public void switchWriter(SSTableWriter newWriter)
-
setRepairedAt
public SSTableRewriter setRepairedAt(long repairedAt)
- Parameters:
repairedAt
- the repair time, -1 if we should use the time we supplied when we created the SSTableWriter (and called rewriter.switchWriter(..)), actual time if we want to override the repair time.
-
finish
public java.util.List<SSTableReader> finish()
Finishes the new file(s) Creates final files, adds the new files to the Tracker (via replaceReader). We add them to the tracker to be able to get rid of the tmpfiles It is up to the caller to do the compacted sstables replacement gymnastics (ie, call Tracker#markCompactedSSTablesReplaced(..))- Overrides:
finish
in classTransactional.AbstractTransactional
-
finished
public java.util.List<SSTableReader> finished()
-
doPrepare
protected void doPrepare()
Description copied from class:Transactional.AbstractTransactional
Do any preparatory work prior to commit. This method should throw any exceptions that can be encountered during the finalization of the behaviour.- Specified by:
doPrepare
in classTransactional.AbstractTransactional
-
throwDuringPrepare
public void throwDuringPrepare(boolean earlyException)
-
-