Class BasePartitionUpsertMetadataManager
- java.lang.Object
-
- org.apache.pinot.segment.local.upsert.BasePartitionUpsertMetadataManager
-
- All Implemented Interfaces:
Closeable,AutoCloseable,PartitionUpsertMetadataManager
- Direct Known Subclasses:
ConcurrentMapPartitionUpsertMetadataManager
@ThreadSafe public abstract class BasePartitionUpsertMetadataManager extends Object implements PartitionUpsertMetadataManager
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>_comparisonColumnsprotected String_deleteRecordColumnprotected boolean_enableSnapshotprotected boolean_gotFirstConsumingSegmentprotected HashFunction_hashFunctionprotected double_largestSeenComparisonValueprotected long_lastOutOfOrderEventReportTimeNsprotected org.slf4j.Logger_loggerprotected double_metadataTTLprotected int_numOutOfOrderEventsprotected AtomicInteger_numPendingOperationsprotected PartialUpsertHandler_partialUpsertHandlerprotected int_partitionIdprotected List<String>_primaryKeyColumnsprotected ServerMetrics_serverMetricsprotected ReadWriteLock_snapshotLockprotected boolean_stoppedprotected File_tableIndexDirprotected String_tableNameWithTypeprotected Set<IndexSegment>_trackedSegmentsprotected static longOUT_OF_ORDER_EVENT_MIN_REPORT_INTERVAL_NS
-
Constructor Summary
Constructors Modifier Constructor Description protectedBasePartitionUpsertMetadataManager(String tableNameWithType, int partitionId, List<String> primaryKeyColumns, List<String> comparisonColumns, String deleteRecordColumn, HashFunction hashFunction, PartialUpsertHandler partialUpsertHandler, boolean enableSnapshot, double metadataTTL, File tableIndexDir, ServerMetrics serverMetrics)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds, ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator, IndexSegment oldSegment, org.roaringbitmap.buffer.MutableRoaringBitmap validDocIdsForOldSegment)voidaddRecord(MutableSegment segment, RecordInfo recordInfo)Updates the upsert metadata for a new consumed record in the given consuming segment.voidaddSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds, ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator)NOTE: We allow passing in validDocIds and queryableDocIds here so that the value can be easily accessed from the tests.voidaddSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds, ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator, boolean isPreloading)voidaddSegment(ImmutableSegment segment)Initializes the upsert metadata for the given immutable segment.protected voidaddSegmentWithoutUpsert(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds, ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator)voidclose()protected voiddeleteWatermark()Deletes the watermark file.protected abstract voiddoAddRecord(MutableSegment segment, RecordInfo recordInfo)protected voiddoAddSegment(ImmutableSegmentImpl segment)protected voiddoClose()protected abstract voiddoRemoveExpiredPrimaryKeys()Removes all primary keys that have comparison value smaller than (largestSeenComparisonValue - TTL).protected voiddoRemoveSegment(IndexSegment segment)protected voiddoReplaceSegment(ImmutableSegment segment, IndexSegment oldSegment)protected voiddoTakeSnapshot()protected abstract GenericRowdoUpdateRecord(GenericRow record, RecordInfo recordInfo)protected voidfinishOperation()protected abstract longgetNumPrimaryKeys()List<String>getPrimaryKeyColumns()Returns the primary key columns.protected FilegetWatermarkFile()protected voidhandleOutOfOrderEvent(Object currentComparisonValue, Object recordComparisonValue)protected doubleloadWatermark()Loads watermark from the file if exists.protected voidpersistWatermark(double watermark)Persists watermark to the file.voidpreloadSegment(ImmutableSegment segment)Different from adding a segment, when preloading a segment, the upsert metadata may be updated more efficiently.voidremoveExpiredPrimaryKeys()Remove the expired primary keys from the metadata when TTL is enabled.voidremoveSegment(IndexSegment segment)Removes the upsert metadata for the given segment.protected abstract voidremoveSegment(IndexSegment segment, org.roaringbitmap.buffer.MutableRoaringBitmap validDocIds)voidreplaceSegment(ImmutableSegment segment, ThreadSafeMutableRoaringBitmap validDocIds, ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator, IndexSegment oldSegment)NOTE: We allow passing in validDocIds and queryableDocIds here so that the value can be easily accessed from the tests.voidreplaceSegment(ImmutableSegment segment, IndexSegment oldSegment)Replaces the upsert metadata for the old segment with the new immutable segment.protected voidstartOperation()voidstop()Stops the metadata manager.voidtakeSnapshot()Takes snapshot for all the tracked immutable segments when snapshot is enabled.GenericRowupdateRecord(GenericRow record, RecordInfo recordInfo)Returns the merged record when partial-upsert is enabled.
-
-
-
Field Detail
-
OUT_OF_ORDER_EVENT_MIN_REPORT_INTERVAL_NS
protected static final long OUT_OF_ORDER_EVENT_MIN_REPORT_INTERVAL_NS
-
_tableNameWithType
protected final String _tableNameWithType
-
_partitionId
protected final int _partitionId
-
_deleteRecordColumn
protected final String _deleteRecordColumn
-
_hashFunction
protected final HashFunction _hashFunction
-
_partialUpsertHandler
protected final PartialUpsertHandler _partialUpsertHandler
-
_enableSnapshot
protected final boolean _enableSnapshot
-
_metadataTTL
protected final double _metadataTTL
-
_tableIndexDir
protected final File _tableIndexDir
-
_serverMetrics
protected final ServerMetrics _serverMetrics
-
_logger
protected final org.slf4j.Logger _logger
-
_trackedSegments
protected final Set<IndexSegment> _trackedSegments
-
_gotFirstConsumingSegment
protected volatile boolean _gotFirstConsumingSegment
-
_snapshotLock
protected final ReadWriteLock _snapshotLock
-
_stopped
protected volatile boolean _stopped
-
_numPendingOperations
protected final AtomicInteger _numPendingOperations
-
_lastOutOfOrderEventReportTimeNs
protected long _lastOutOfOrderEventReportTimeNs
-
_numOutOfOrderEvents
protected int _numOutOfOrderEvents
-
_largestSeenComparisonValue
protected volatile double _largestSeenComparisonValue
-
-
Constructor Detail
-
BasePartitionUpsertMetadataManager
protected BasePartitionUpsertMetadataManager(String tableNameWithType, int partitionId, List<String> primaryKeyColumns, List<String> comparisonColumns, @Nullable String deleteRecordColumn, HashFunction hashFunction, @Nullable PartialUpsertHandler partialUpsertHandler, boolean enableSnapshot, double metadataTTL, File tableIndexDir, ServerMetrics serverMetrics)
-
-
Method Detail
-
getPrimaryKeyColumns
public List<String> getPrimaryKeyColumns()
Description copied from interface:PartitionUpsertMetadataManagerReturns the primary key columns.- Specified by:
getPrimaryKeyColumnsin interfacePartitionUpsertMetadataManager
-
addSegment
public void addSegment(ImmutableSegment segment)
Description copied from interface:PartitionUpsertMetadataManagerInitializes the upsert metadata for the given immutable segment.- Specified by:
addSegmentin interfacePartitionUpsertMetadataManager
-
doAddSegment
protected void doAddSegment(ImmutableSegmentImpl segment)
-
preloadSegment
public void preloadSegment(ImmutableSegment segment)
Description copied from interface:PartitionUpsertMetadataManagerDifferent from adding a segment, when preloading a segment, the upsert metadata may be updated more efficiently. Basically the upsert metadata can be directly updated for each primary key, without doing the more costly read-compare-update.- Specified by:
preloadSegmentin interfacePartitionUpsertMetadataManager
-
addSegment
public void addSegment(ImmutableSegmentImpl segment, @Nullable ThreadSafeMutableRoaringBitmap validDocIds, @Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator)
NOTE: We allow passing in validDocIds and queryableDocIds here so that the value can be easily accessed from the tests. The passed in bitmaps should always be empty.
-
addSegment
public void addSegment(ImmutableSegmentImpl segment, @Nullable ThreadSafeMutableRoaringBitmap validDocIds, @Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator, boolean isPreloading)
-
getNumPrimaryKeys
protected abstract long getNumPrimaryKeys()
-
addOrReplaceSegment
protected abstract void addOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds, @Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator, @Nullable IndexSegment oldSegment, @Nullable org.roaringbitmap.buffer.MutableRoaringBitmap validDocIdsForOldSegment)
-
addSegmentWithoutUpsert
protected void addSegmentWithoutUpsert(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds, @Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator)
-
addRecord
public void addRecord(MutableSegment segment, RecordInfo recordInfo)
Description copied from interface:PartitionUpsertMetadataManagerUpdates the upsert metadata for a new consumed record in the given consuming segment.- Specified by:
addRecordin interfacePartitionUpsertMetadataManager
-
doAddRecord
protected abstract void doAddRecord(MutableSegment segment, RecordInfo recordInfo)
-
replaceSegment
public void replaceSegment(ImmutableSegment segment, IndexSegment oldSegment)
Description copied from interface:PartitionUpsertMetadataManagerReplaces the upsert metadata for the old segment with the new immutable segment.- Specified by:
replaceSegmentin interfacePartitionUpsertMetadataManager
-
doReplaceSegment
protected void doReplaceSegment(ImmutableSegment segment, IndexSegment oldSegment)
-
replaceSegment
public void replaceSegment(ImmutableSegment segment, @Nullable ThreadSafeMutableRoaringBitmap validDocIds, @Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, @Nullable Iterator<RecordInfo> recordInfoIterator, IndexSegment oldSegment)
NOTE: We allow passing in validDocIds and queryableDocIds here so that the value can be easily accessed from the tests. The passed in bitmaps should always be empty.
-
removeSegment
protected abstract void removeSegment(IndexSegment segment, org.roaringbitmap.buffer.MutableRoaringBitmap validDocIds)
-
removeSegment
public void removeSegment(IndexSegment segment)
Description copied from interface:PartitionUpsertMetadataManagerRemoves the upsert metadata for the given segment.- Specified by:
removeSegmentin interfacePartitionUpsertMetadataManager
-
doRemoveSegment
protected void doRemoveSegment(IndexSegment segment)
-
updateRecord
public GenericRow updateRecord(GenericRow record, RecordInfo recordInfo)
Description copied from interface:PartitionUpsertMetadataManagerReturns the merged record when partial-upsert is enabled.- Specified by:
updateRecordin interfacePartitionUpsertMetadataManager
-
doUpdateRecord
protected abstract GenericRow doUpdateRecord(GenericRow record, RecordInfo recordInfo)
-
handleOutOfOrderEvent
protected void handleOutOfOrderEvent(Object currentComparisonValue, Object recordComparisonValue)
-
takeSnapshot
public void takeSnapshot()
Description copied from interface:PartitionUpsertMetadataManagerTakes snapshot for all the tracked immutable segments when snapshot is enabled. This method should be invoked before a new consuming segment starts consuming.- Specified by:
takeSnapshotin interfacePartitionUpsertMetadataManager
-
doTakeSnapshot
protected void doTakeSnapshot()
-
loadWatermark
protected double loadWatermark()
Loads watermark from the file if exists.
-
persistWatermark
protected void persistWatermark(double watermark)
Persists watermark to the file.
-
deleteWatermark
protected void deleteWatermark()
Deletes the watermark file.
-
getWatermarkFile
protected File getWatermarkFile()
-
startOperation
protected void startOperation()
-
finishOperation
protected void finishOperation()
-
removeExpiredPrimaryKeys
public void removeExpiredPrimaryKeys()
Description copied from interface:PartitionUpsertMetadataManagerRemove the expired primary keys from the metadata when TTL is enabled.- Specified by:
removeExpiredPrimaryKeysin interfacePartitionUpsertMetadataManager
-
doRemoveExpiredPrimaryKeys
protected abstract void doRemoveExpiredPrimaryKeys()
Removes all primary keys that have comparison value smaller than (largestSeenComparisonValue - TTL).
-
stop
public void stop()
Description copied from interface:PartitionUpsertMetadataManagerStops the metadata manager. After invoking this method, no access to the metadata will be accepted.- Specified by:
stopin interfacePartitionUpsertMetadataManager
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
doClose
protected void doClose() throws IOException- Throws:
IOException
-
-