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 UpsertContext_contextprotected double_deletedKeysTTLprotected String_deleteRecordColumnprotected boolean_enableSnapshotprotected boolean_gotFirstConsumingSegmentprotected HashFunction_hashFunctionprotected com.google.common.util.concurrent.AtomicDouble_largestSeenComparisonValueprotected long_lastOutOfOrderEventReportTimeNsprotected org.slf4j.Logger_loggerprotected double_metadataTTLprotected int_numOutOfOrderEventsprotected PartialUpsertHandler_partialUpsertHandlerprotected int_partitionIdprotected List<String>_primaryKeyColumnsprotected ServerMetrics_serverMetricsprotected ReadWriteLock_snapshotLockprotected 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, UpsertContext context)
-
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)booleanaddRecord(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(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 booleandoAddRecord(MutableSegment segment, RecordInfo recordInfo)Returnstruewhen the record is added to the upsert metadata manager,falsewhen the record is out-of-order thus not added.protected voiddoAddSegment(ImmutableSegmentImpl segment)protected voiddoClose()protected voiddoPreloadSegment(ImmutableSegmentImpl segment)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 org.roaringbitmap.buffer.MutableRoaringBitmapgetQueryableDocIds(IndexSegment segment, org.roaringbitmap.buffer.MutableRoaringBitmap validDocIds)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 booleanstartOperation()voidstop()Stops the metadata manager.voidtakeSnapshot()Takes snapshot for all the tracked immutable segments when snapshot is enabled.protected voidupdatePrimaryKeyGauge()protected voidupdatePrimaryKeyGauge(long numPrimaryKeys)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
-
_context
protected final UpsertContext _context
-
_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
-
_deletedKeysTTL
protected final double _deletedKeysTTL
-
_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
-
_lastOutOfOrderEventReportTimeNs
protected long _lastOutOfOrderEventReportTimeNs
-
_numOutOfOrderEvents
protected int _numOutOfOrderEvents
-
_largestSeenComparisonValue
protected final com.google.common.util.concurrent.AtomicDouble _largestSeenComparisonValue
-
-
Constructor Detail
-
BasePartitionUpsertMetadataManager
protected BasePartitionUpsertMetadataManager(String tableNameWithType, int partitionId, UpsertContext context)
-
-
Method Detail
-
getPrimaryKeyColumns
public List<String> getPrimaryKeyColumns()
Description copied from interface:PartitionUpsertMetadataManagerReturns the primary key columns.- Specified by:
getPrimaryKeyColumnsin interfacePartitionUpsertMetadataManager
-
getQueryableDocIds
@Nullable protected org.roaringbitmap.buffer.MutableRoaringBitmap getQueryableDocIds(IndexSegment segment, org.roaringbitmap.buffer.MutableRoaringBitmap validDocIds)
-
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)
-
getNumPrimaryKeys
protected abstract long getNumPrimaryKeys()
-
updatePrimaryKeyGauge
protected void updatePrimaryKeyGauge(long numPrimaryKeys)
-
updatePrimaryKeyGauge
protected void updatePrimaryKeyGauge()
-
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
-
doPreloadSegment
protected void doPreloadSegment(ImmutableSegmentImpl segment)
-
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.
-
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 boolean 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 boolean doAddRecord(MutableSegment segment, RecordInfo recordInfo)
Returnstruewhen the record is added to the upsert metadata manager,falsewhen the record is out-of-order thus not added.
-
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()
-
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).
-
startOperation
protected boolean startOperation()
-
finishOperation
protected void finishOperation()
-
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
-
-