Package org.apache.solr.update
Class UpdateLog
java.lang.Object
org.apache.solr.update.UpdateLog
- All Implemented Interfaces:
AutoCloseable,SolrMetricProducer,PluginInfoInitialized
This holds references to the transaction logs. It also keeps a map of unique key to location in
log (along with the update's version). This map is only cleared on soft or hard commit
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHolds the query and the version for a DeleteByQuery commandprotected static classstatic classclassstatic classstatic enumstatic enumprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected AttributedLongCounterstatic Stringprotected TransactionLogprotected booleanstatic final intprotected AttributedLongCounterprotected Stringprotected UpdateLog.SyncLevelstatic final intstatic final intprotected LinkedList<UpdateLog.DBQ> protected booleanstatic final intThe index of the flags value in an entry from the transaction log.protected Collection<String> protected longstatic Stringprotected final Deque<TransactionLog> protected Map<org.apache.lucene.util.BytesRef, UpdateLog.LogPtr> protected intprotected Deque<TransactionLog> protected final intprotected final intprotected intprotected intprotected LinkedHashMap<org.apache.lucene.util.BytesRef, UpdateLog.LogPtr> static final intstatic final intThe index of the previous pointer in an entry from the transaction log.static final intThe index of the previous version in an entry from the transaction log.protected Map<org.apache.lucene.util.BytesRef, UpdateLog.LogPtr> protected Map<org.apache.lucene.util.BytesRef, UpdateLog.LogPtr> protected TransactionLogprotected TransactionLogprotected TransactionLogprotected TransactionLogprotected UpdateLog.RecoveryInfoprotected Closeableprotected AttributedLongCounterprotected SolrMetricsContextprotected UpdateLog.Statestatic Runnablestatic Runnableprotected TransactionLogstatic Stringprotected Pathprotected String[]protected List<AutoCloseable> protected UpdateHandlerstatic final intstatic final intThe index of the _version_ value in an entry from the transaction log.protected VersionInfoFields inherited from interface org.apache.solr.metrics.SolrMetricProducer
CATEGORY_ATTR, HANDLER_ATTR, NAME_ATTR, OPERATION_ATTR, PLUGIN_NAME_ATTR, RESULT_ATTR, TYPE_ATTR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(AddUpdateCommand cmd) voidadd(AddUpdateCommand cmd, boolean clearCaches) protected voidaddOldLog(TransactionLog oldLog, boolean removeOld) Returns the Future to wait on, or null if no replay was neededlongapplyPartialUpdates(org.apache.lucene.util.BytesRef id, long prevPointer, long prevVersion, Set<String> onlyTheseFields, org.apache.solr.common.SolrDocumentBase<?, ?> latestPartialDoc) Goes over backwards, following the prevPointer, to merge all partial updates into the passed doc.voidvoidclearLog()Clears the logs on the file system.voidclose(boolean committed) voidclose(boolean committed, boolean deleteOnClose) voidBlock updates, append a commit at current tlog, then copy over updates to a new tlog.static AddUpdateCommandconvertTlogEntryToAddUpdateCommand(SolrQueryRequest req, List<?> entry, int operation, long version) Given a entry from the transaction log containing a document, return a new AddUpdateCommand that can be applied to ADD the document or do an UPDATE_INPLACE.voidBlock updates, append a commit at current tlog, then copy over buffer updates to new tlog and bring back ulog to active state.voidcopyOverOldUpdates(long commitVersion) voidcopyOverOldUpdates(long commitVersion, TransactionLog oldTlog) Copy over updates from prevTlog or last tlog (in tlog folder) to a new tlogvoidvoidcurrently for testing onlyprotected voidvoidstatic voiddeleteFile(Path file) booleanReturns true if we were able to drop buffered updates and return to the ACTIVE stateprotected voidprotected voidEnsures a transaction log is ready.booleanvoidfinish(UpdateLog.SyncLevel syncLevel) longgetDBQNewer(long version) longgetLocks()String[]getLogList(Path directory) intintThe RecentUpdates object returned must be closed after useImplementations should return the context used inSolrMetricProducer.initializeMetrics(SolrMetricsContext, Attributes)to ensure proper cleanup of metrics at the end of the life-cycle of this component.getState()longlongbooleanvoidinit(PluginInfo info) voidinit(UpdateHandler uhandler, SolrCore core) This must be called when a new log is created, or for an existing log whenever the core or update handler changes.voidinitializeMetrics(SolrMetricsContext parentContext, io.opentelemetry.api.common.Attributes attributes) Implementation should initialize all metrics to aSolrMetricsContextRegistry/MeterProvider withAttributesas the common set of attributes that will be attached to every metric that is initialized for that class/componentprotected voidinitTlogDir(SolrCore core) Based ondataDir(whose initialization must be complete before this method is called), this method is responsible for, in order: resolving the tlog dir (in an implementation-dependent way) clearing any existing entries (if applicable) by callingmaybeClearLog(SolrCore)actually creating tlog files (and handling any existing tlog files, if necessary)lookup(org.apache.lucene.util.BytesRef indexedId) lookupVersion(org.apache.lucene.util.BytesRef indexedId) protected final voidmaybeClearLog(SolrCore core) protected voidnewMap()newTransactionLog(Path tlogFile, Collection<String> globalStrings, boolean openExisting) Returns a newTransactionLog.protected static intvoidOpens a new realtime searcher and clears the id caches.voidvoidvoidvoidReplay current tlog, so all updates will be written to index.protected StringresolveDataDir(SolrCore core, String path) Resolves any relative path wrt the highest core-scoped level (whatever that means for a particular implementation).toString()protected voidtrackDeleteByQuery(String q, long version) static PathulogToTlogDir(String coreName, Path ulogDirPath, Path instancePath, String coreDataDir) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.solr.metrics.SolrMetricProducer
close
-
Field Details
-
LOG_FILENAME_PATTERN
-
TLOG_NAME
-
BUFFER_TLOG_NAME
-
ADD
public static final int ADD- See Also:
-
DELETE
public static final int DELETE- See Also:
-
DELETE_BY_QUERY
public static final int DELETE_BY_QUERY- See Also:
-
COMMIT
public static final int COMMIT- See Also:
-
UPDATE_INPLACE
public static final int UPDATE_INPLACE- See Also:
-
OPERATION_MASK
public static final int OPERATION_MASK- See Also:
-
FLAGS_IDX
public static final int FLAGS_IDXThe index of the flags value in an entry from the transaction log.- See Also:
-
VERSION_IDX
public static final int VERSION_IDXThe index of the _version_ value in an entry from the transaction log.- See Also:
-
PREV_POINTER_IDX
public static final int PREV_POINTER_IDXThe index of the previous pointer in an entry from the transaction log. This is only relevant if flags (indexed at FLAGS_IDX) includes UPDATE_INPLACE.- See Also:
-
PREV_VERSION_IDX
public static final int PREV_VERSION_IDXThe index of the previous version in an entry from the transaction log. This is only relevant if flags (indexed at FLAGS_IDX) includes UPDATE_INPLACE.- See Also:
-
id
protected long id -
state
-
bufferTlog
-
tlog
-
prevTlog
-
prevTlogOnPrecommit
-
logs
-
newestLogsOnStartup
-
numOldRecords
protected int numOldRecords -
map
-
prevMap
-
prevMap2
-
prevMapLog
-
prevMapLog2
-
numDeletesToKeep
protected final int numDeletesToKeep- See Also:
-
numDeletesByQueryToKeep
protected final int numDeletesByQueryToKeep- See Also:
-
numRecordsToKeep
protected int numRecordsToKeep -
maxNumLogsToKeep
protected int maxNumLogsToKeep -
existOldBufferLog
protected boolean existOldBufferLog -
oldDeletes
-
deleteByQueries
-
tlogFiles
-
tlogDir
-
releaseTlogDir
-
globalStrings
-
dataDir
-
versionInfo
-
defaultSyncLevel
-
uhandler
-
cancelApplyBufferUpdate
protected volatile boolean cancelApplyBufferUpdate -
startingVersions
-
applyingBufferedOpsCounter
-
replayOpsCounter
-
copyOverOldUpdatesCounter
-
toClose
-
solrMetricsContext
-
testing_logReplayHook
-
testing_logReplayFinishHook
-
recoveryInfo
-
-
Constructor Details
-
UpdateLog
public UpdateLog()
-
-
Method Details
-
getTotalLogsSize
public long getTotalLogsSize() -
getCurrentLogSizeFromStream
public long getCurrentLogSizeFromStream()- Returns:
- the current transaction log's size (based on its output stream)
-
getTotalLogsNumber
public long getTotalLogsNumber() -
getVersionInfo
-
getLocks
-
getNumRecordsToKeep
public int getNumRecordsToKeep() -
getMaxNumLogsToKeep
public int getMaxNumLogsToKeep() -
objToInt
-
ulogToTlogDir
-
init
- Specified by:
initin interfacePluginInfoInitialized
-
init
This must be called when a new log is created, or for an existing log whenever the core or update handler changes. It is called from the ctor of the specifiedUpdateHandler, so the specified uhandler will not yet be completely constructed.This method must be called after
init(PluginInfo)is called. -
maybeClearLog
-
resolveDataDir
Resolves any relative path wrt the highest core-scoped level (whatever that means for a particular implementation). For most filesystems, this will be the core instanceDir, but that is not a hard and fast rule.If the input path is already absolute, it will be returned unmodified.
This method should return the final, absolute, normalized path that defines the location of the ulog dataDir. It should not bother to resolve the tlog dir, nor do any work associated with initializing the tlog dir or its contents. Tlog dir initialization takes place later (if necessary) in
initTlogDir(SolrCore). -
initTlogDir
Based ondataDir(whose initialization must be complete before this method is called), this method is responsible for, in order:- resolving the tlog dir (in an implementation-dependent way)
- clearing any existing entries (if applicable) by calling
maybeClearLog(SolrCore) - actually creating tlog files (and handling any existing tlog files, if necessary)
Note: implementations of this method must call
maybeClearLog(SolrCore)after resolving the tlog dir, and before creating any (or handling any existing) tlog files. -
initializeMetrics
public void initializeMetrics(SolrMetricsContext parentContext, io.opentelemetry.api.common.Attributes attributes) Description copied from interface:SolrMetricProducerImplementation should initialize all metrics to aSolrMetricsContextRegistry/MeterProvider withAttributesas the common set of attributes that will be attached to every metric that is initialized for that class/component- Specified by:
initializeMetricsin interfaceSolrMetricProducer- Parameters:
parentContext- The registry that the component will initialize metrics toattributes- Base set of attributes that will be bound to all metrics for that component
-
getSolrMetricsContext
Description copied from interface:SolrMetricProducerImplementations should return the context used inSolrMetricProducer.initializeMetrics(SolrMetricsContext, Attributes)to ensure proper cleanup of metrics at the end of the life-cycle of this component. This should be the child context if one was created, or null if the parent context was used.- Specified by:
getSolrMetricsContextin interfaceSolrMetricProducer
-
newTransactionLog
public TransactionLog newTransactionLog(Path tlogFile, Collection<String> globalStrings, boolean openExisting) Returns a newTransactionLog. Sub-classes can override this method to change the implementation of the transaction log. -
getTlogDir
-
getUlogDir
-
getStartingVersions
-
existOldBufferLog
public boolean existOldBufferLog() -
addOldLog
-
getLogList
-
getLastLogId
public long getLastLogId() -
add
-
add
-
delete
-
deleteByQuery
-
openRealtimeSearcher
public void openRealtimeSearcher()Opens a new realtime searcher and clears the id caches. This may also be called when we updates are being buffered (from PeerSync/IndexFingerprint) -
deleteAll
public void deleteAll()currently for testing only -
trackDeleteByQuery
-
getDBQNewer
-
newMap
protected void newMap() -
hasUncommittedChanges
public boolean hasUncommittedChanges() -
preCommit
-
postCommit
-
preSoftCommit
-
postSoftCommit
-
applyPartialUpdates
public long applyPartialUpdates(org.apache.lucene.util.BytesRef id, long prevPointer, long prevVersion, Set<String> onlyTheseFields, org.apache.solr.common.SolrDocumentBase<?, ?> latestPartialDoc) Goes over backwards, following the prevPointer, to merge all partial updates into the passed doc. Stops at either a full document, or if there are no previous entries to follow in the update log.- Parameters:
id- Binary representation of the unique key fieldprevPointer- Pointer to the previous entry in the ulog, based on which the current in-place update was made.prevVersion- Version of the previous entry in the ulog, based on which the current in-place update was made.onlyTheseFields- When a non-null set of field names is passed in, the resolve process only attempts to populate the given fields in this set. When this set is null, it resolves all fields.latestPartialDoc- Partial document that is to be populated- Returns:
- Returns 0 if a full document was found in the log, -1 if no full document was found. If full document was supposed to be found in the tlogs, but couldn't be found (because the logs were rotated) then the prevPointer is returned.
-
lookup
-
lookupVersion
-
finish
-
recoverFromLog
-
recoverFromCurrentLog
Replay current tlog, so all updates will be written to index. This is must do task for a tlog replica become a new leader.- Returns:
- future of this task
-
copyOverBufferingUpdates
Block updates, append a commit at current tlog, then copy over buffer updates to new tlog and bring back ulog to active state. So any updates which hasn't made it to the index is preserved in the current tlog, this also make RTG work- Parameters:
cuc- any updates that have version larger than the version of cuc will be copied over
-
commitAndSwitchToNewTlog
Block updates, append a commit at current tlog, then copy over updates to a new tlog. So any updates which hasn't made it to the index is preserved in the current tlog- Parameters:
cuc- any updates that have version larger than the version of cuc will be copied over
-
copyOverOldUpdates
public void copyOverOldUpdates(long commitVersion) -
copyOverOldUpdates
Copy over updates from prevTlog or last tlog (in tlog folder) to a new tlog- Parameters:
commitVersion- any updates that have version larger than the commitVersion will be copied over
-
ensureBufferTlog
protected void ensureBufferTlog() -
deleteBufferLogs
protected void deleteBufferLogs() -
ensureLog
protected void ensureLog()Ensures a transaction log is ready. It is either the current one, or a new one. This method must be called with the synchronization monitor on thisUpdateLog. -
close
public void close(boolean committed) -
close
public void close(boolean committed, boolean deleteOnClose) -
getRecentUpdates
The RecentUpdates object returned must be closed after use -
bufferUpdates
public void bufferUpdates() -
dropBufferedUpdates
public boolean dropBufferedUpdates()Returns true if we were able to drop buffered updates and return to the ACTIVE state -
applyBufferedUpdates
Returns the Future to wait on, or null if no replay was needed -
getState
-
toString
-
convertTlogEntryToAddUpdateCommand
public static AddUpdateCommand convertTlogEntryToAddUpdateCommand(SolrQueryRequest req, List<?> entry, int operation, long version) Given a entry from the transaction log containing a document, return a new AddUpdateCommand that can be applied to ADD the document or do an UPDATE_INPLACE.- Parameters:
req- The request to use as the owner of the new AddUpdateCommandentry- Entry from the transaction log that contains the document to be addedoperation- The value of the operation flag; this must be either ADD or UPDATE_INPLACE -- if it is UPDATE_INPLACE then the previous version will also be read from the entryversion- Version already obtained from the entry.
-
deleteFile
-
clearLog
public void clearLog()Clears the logs on the file system. Only call before init.
-