Package org.apache.solr.update
Class TransactionLog
- java.lang.Object
- 
- org.apache.solr.update.TransactionLog
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 public class TransactionLog extends Object implements Closeable Log Format: List{Operation, Version, ...} ADD, VERSION, DOC DELETE, VERSION, ID_BYTES DELETE_BY_QUERY, VERSION, StringTODO: keep two files, one for [operation, version, id] and the other for the actual document data. That way we could throw away document log files more readily while retaining the smaller operation log files longer (and we can retrieve the stored fields from the latest documents from the index). This would require keeping all source fields stored of course. This would also allow to not log document data for requests with commit=true in them (since we know that if the request succeeds, all docs will be committed) 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classTransactionLog.ChannelFastInputStreamprotected static interfaceTransactionLog.ChannelInputStreamOpenerOpensTransactionLog.ChannelFastInputStreamfromFileChannel.classTransactionLog.FSReverseReaderclassTransactionLog.LogCodecclassTransactionLog.LogReaderprotected static interfaceTransactionLog.OutputStreamOpenerOpensOutputStreamfromFileChannel.static classTransactionLog.ReverseReaderclassTransactionLog.SortedLogReader
 - 
Field SummaryFields Modifier and Type Field Description protected FileChannelchannelprotected static TransactionLog.ChannelInputStreamOpenerCHANNEL_INPUT_STREAM_OPENERprotected TransactionLog.ChannelInputStreamOpenerchannelInputStreamOpenerprotected booleandeleteOnClosestatic StringEND_MESSAGEprotected org.apache.solr.common.util.FastOutputStreamfosprotected List<String>globalStringListprotected Map<String,Integer>globalStringMapbooleanisBufferprotected OutputStreamosprotected static TransactionLog.OutputStreamOpenerOUTPUT_STREAM_OPENERprotected AtomicIntegerrefcountprotected static org.apache.solr.common.util.JavaBinCodec.ObjectResolverresolverprotected Pathtlog
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedTransactionLog()protectedTransactionLog(Path tlogFile, Collection<String> globalStrings, boolean openExisting, TransactionLog.OutputStreamOpener outputStreamOpener, TransactionLog.ChannelInputStreamOpener channelInputStreamOpener)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddGlobalStrings(Collection<String> strings)protected voidcheckWriteHeader(TransactionLog.LogCodec codec, org.apache.solr.common.SolrInputDocument optional)voidclose()voidcloseOutput()Move to a read-only state, closing and releasing resources while keeping the log available for readsvoiddecref()protected voidendRecord(long startRecordPosition)booleanendsWithCommit()voidfinish(UpdateLog.SyncLevel syncLevel)voidforceClose()protected longgetLogFileSize()Gets the log file data size.longgetLogSize()longgetLogSizeFromStream()TransactionLog.LogReadergetReader(long startingPos)Returns a reader that can be used while a log is still in use.TransactionLog.ReverseReadergetReverseReader()Returns a single threaded reverse readerTransactionLog.LogReadergetSortedReader(long startingPos)voidincref()Objectlookup(long pos)intnumRecords()Returns the number of records in the log (currently includes the header and an optional commit).longposition()returns the current position in the log fileprotected voidsetWrittenCount(long fileStartOffset)Sets the counter of written data in theFastOutputStreamview of the log file, to reflect that we aren't starting at the beginning.StringtoString()booleantry_incref()longwrite(AddUpdateCommand cmd)Writes an add update command to the transaction log.longwrite(AddUpdateCommand cmd, long prevPointer)Writes an add update command to the transaction log.longwriteCommit(CommitUpdateCommand cmd)longwriteData(Object o)longwriteDelete(DeleteUpdateCommand cmd)longwriteDeleteByQuery(DeleteUpdateCommand cmd)protected voidwriteLogHeader(TransactionLog.LogCodec codec)
 
- 
- 
- 
Field Detail- 
END_MESSAGEpublic static final String END_MESSAGE - See Also:
- Constant Field Values
 
 - 
tlogprotected Path tlog 
 - 
channelprotected FileChannel channel 
 - 
osprotected OutputStream os 
 - 
fosprotected org.apache.solr.common.util.FastOutputStream fos 
 - 
channelInputStreamOpenerprotected TransactionLog.ChannelInputStreamOpener channelInputStreamOpener 
 - 
isBufferpublic boolean isBuffer 
 - 
deleteOnCloseprotected volatile boolean deleteOnClose 
 - 
refcountprotected AtomicInteger refcount 
 - 
resolverprotected static final org.apache.solr.common.util.JavaBinCodec.ObjectResolver resolver 
 - 
OUTPUT_STREAM_OPENERprotected static final TransactionLog.OutputStreamOpener OUTPUT_STREAM_OPENER 
 - 
CHANNEL_INPUT_STREAM_OPENERprotected static final TransactionLog.ChannelInputStreamOpener CHANNEL_INPUT_STREAM_OPENER 
 
- 
 - 
Constructor Detail- 
TransactionLogprotected TransactionLog(Path tlogFile, Collection<String> globalStrings, boolean openExisting, TransactionLog.OutputStreamOpener outputStreamOpener, TransactionLog.ChannelInputStreamOpener channelInputStreamOpener) 
 - 
TransactionLogprotected TransactionLog() 
 
- 
 - 
Method Detail- 
setWrittenCountprotected void setWrittenCount(long fileStartOffset) throws IOExceptionSets the counter of written data in theFastOutputStreamview of the log file, to reflect that we aren't starting at the beginning.- Throws:
- IOException
 
 - 
getLogFileSizeprotected long getLogFileSize() throws IOExceptionGets the log file data size.- Throws:
- IOException
 
 - 
numRecordspublic int numRecords() Returns the number of records in the log (currently includes the header and an optional commit). Note: currently returns 0 for reopened existing log files.
 - 
endsWithCommitpublic boolean endsWithCommit() throws IOException- Throws:
- IOException
 
 - 
writeDatapublic long writeData(Object o) 
 - 
addGlobalStringsprotected void addGlobalStrings(Collection<String> strings) 
 - 
writeLogHeaderprotected void writeLogHeader(TransactionLog.LogCodec codec) throws IOException - Throws:
- IOException
 
 - 
endRecordprotected void endRecord(long startRecordPosition) throws IOException- Throws:
- IOException
 
 - 
checkWriteHeaderprotected void checkWriteHeader(TransactionLog.LogCodec codec, org.apache.solr.common.SolrInputDocument optional) throws IOException - Throws:
- IOException
 
 - 
writepublic long write(AddUpdateCommand cmd) Writes an add update command to the transaction log. This is not applicable for in-place updates; usewrite(AddUpdateCommand, long). (The previous pointer (applicable for in-place updates) is set to -1 while writing the command to the transaction log.)- Parameters:
- cmd- The add update command to be written
- Returns:
- Returns the position pointer of the written update command
- See Also:
- write(AddUpdateCommand, long)
 
 - 
writepublic long write(AddUpdateCommand cmd, long prevPointer) Writes an add update command to the transaction log. This should be called only for writing in-place updates, or else pass -1 as the prevPointer.- Parameters:
- cmd- The add update command to be written
- prevPointer- The pointer in the transaction log which this update depends on (applicable for in-place updates)
- Returns:
- Returns the position pointer of the written update command
 
 - 
writeDeletepublic long writeDelete(DeleteUpdateCommand cmd) 
 - 
writeDeleteByQuerypublic long writeDeleteByQuery(DeleteUpdateCommand cmd) 
 - 
writeCommitpublic long writeCommit(CommitUpdateCommand cmd) 
 - 
lookuppublic Object lookup(long pos) 
 - 
increfpublic void incref() 
 - 
try_increfpublic boolean try_incref() 
 - 
decrefpublic void decref() 
 - 
positionpublic long position() returns the current position in the log file
 - 
closeOutputpublic void closeOutput() Move to a read-only state, closing and releasing resources while keeping the log available for reads
 - 
finishpublic void finish(UpdateLog.SyncLevel syncLevel) 
 - 
closepublic void close() - Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 - 
forceClosepublic void forceClose() 
 - 
getLogSizepublic long getLogSize() 
 - 
getLogSizeFromStreampublic long getLogSizeFromStream() - Returns:
- the FastOutputStream size
 
 - 
getReaderpublic TransactionLog.LogReader getReader(long startingPos) throws IOException Returns a reader that can be used while a log is still in use. Currently only *one* LogReader may be outstanding, and that log may only be used from a single thread.- Throws:
- IOException
 
 - 
getSortedReaderpublic TransactionLog.LogReader getSortedReader(long startingPos) throws IOException - Throws:
- IOException
 
 - 
getReverseReaderpublic TransactionLog.ReverseReader getReverseReader() throws IOException Returns a single threaded reverse reader- Throws:
- IOException
 
 
- 
 
-