Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,7 @@ public void addSegment(ImmutableSegmentImpl segment, @Nullable ThreadSafeMutable
if (queryableDocIds == null && _deleteRecordColumn != null) {
queryableDocIds = new ThreadSafeMutableRoaringBitmap();
}
addOrReplaceSegment(segment, validDocIds, queryableDocIds, recordInfoIterator, null, null);
}

protected void addOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds,
@Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator,
@Nullable IndexSegment oldSegment, @Nullable MutableRoaringBitmap validDocIdsForOldSegment) {
if (_partialUpsertHandler != null) {
recordInfoIterator = resolveComparisonTies(recordInfoIterator, _hashFunction);
}
doAddOrReplaceSegment(segment, validDocIds, queryableDocIds, recordInfoIterator, oldSegment,
validDocIdsForOldSegment);
doAddOrReplaceSegment(segment, validDocIds, queryableDocIds, recordInfoIterator, null, null);
}

protected abstract void doAddOrReplaceSegment(ImmutableSegmentImpl segment,
Expand All @@ -514,7 +504,7 @@ protected abstract void doAddOrReplaceSegment(ImmutableSegmentImpl segment,

protected void addSegmentWithoutUpsert(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds,
@Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator) {
addOrReplaceSegment(segment, validDocIds, queryableDocIds, recordInfoIterator, null, null);
doAddOrReplaceSegment(segment, validDocIds, queryableDocIds, recordInfoIterator, null, null);
}

/**
Expand Down Expand Up @@ -668,8 +658,8 @@ public void replaceSegment(ImmutableSegment segment, @Nullable ThreadSafeMutable
if (queryableDocIds == null && _deleteRecordColumn != null) {
queryableDocIds = new ThreadSafeMutableRoaringBitmap();
}
addOrReplaceSegment((ImmutableSegmentImpl) segment, validDocIds, queryableDocIds, recordInfoIterator, oldSegment,
validDocIdsForOldSegment);
doAddOrReplaceSegment((ImmutableSegmentImpl) segment, validDocIds, queryableDocIds, recordInfoIterator,
oldSegment, validDocIdsForOldSegment);
}
if (_upsertViewManager != null) {
// When using consistency mode, the old segment's bitmap is updated in place, so we get the validDocIds after
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ protected long getNumPrimaryKeys() {
protected void doAddOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds,
@Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator,
@Nullable IndexSegment oldSegment, @Nullable MutableRoaringBitmap validDocIdsForOldSegment) {
if (_partialUpsertHandler != null) {
recordInfoIterator = resolveComparisonTies(recordInfoIterator, _hashFunction);
}
Comment on lines +74 to +76
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this method resolveComparisonTies can we try to not construct the entire Map in-memory here just to get the iterator?

We have something similar in BasePartitionDedupMetadataManager#addOrReplaceSegment, and it's creating the iterator properly via some readers without allocating the memory all at once.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay it seems we need to do a deduplication here on all records from recordInfoIterator, so a huge on-heap allocation is inevitable.

String segmentName = segment.getSegmentName();
segment.enableUpsert(this, validDocIds, queryableDocIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ protected long getNumPrimaryKeys() {
protected void doAddOrReplaceSegment(ImmutableSegmentImpl segment, ThreadSafeMutableRoaringBitmap validDocIds,
@Nullable ThreadSafeMutableRoaringBitmap queryableDocIds, Iterator<RecordInfo> recordInfoIterator,
@Nullable IndexSegment oldSegment, @Nullable MutableRoaringBitmap validDocIdsForOldSegment) {
if (_partialUpsertHandler == null) {
if (_partialUpsertHandler != null) {
recordInfoIterator = resolveComparisonTies(recordInfoIterator, _hashFunction);
} else {
// for full upsert, we are de-duping primary key once here to make sure that we are not adding
// primary-key multiple times and subtracting just once in removeSegment.
// for partial-upsert, we call this method in base class.
Expand Down Expand Up @@ -298,7 +300,7 @@ public void replaceSegment(ImmutableSegment segment, @Nullable ThreadSafeMutable
if (queryableDocIds == null && _deleteRecordColumn != null) {
queryableDocIds = new ThreadSafeMutableRoaringBitmap();
}
addOrReplaceSegment((ImmutableSegmentImpl) segment, validDocIds, queryableDocIds, recordInfoIterator,
doAddOrReplaceSegment((ImmutableSegmentImpl) segment, validDocIds, queryableDocIds, recordInfoIterator,
oldSegment, validDocIdsForOldSegment);
}
if (validDocIdsForOldSegment != null && !validDocIdsForOldSegment.isEmpty()) {
Expand Down
Loading