Skip to content

Commit

Permalink
Replace assert with Objects.requireNonNull()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie-Jiang committed Dec 1, 2021
1 parent 7f1602e commit 82aab9e
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.annotations.VisibleForTesting;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -96,9 +97,8 @@ public PartitionUpsertMetadataManager(String tableNameWithType, int partitionId,
public void addSegment(IndexSegment segment, Iterator<RecordInfo> recordInfoIterator) {
String segmentName = segment.getSegmentName();
LOGGER.info("Adding upsert metadata for segment: {}", segmentName);
ThreadSafeMutableRoaringBitmap validDocIds = segment.getValidDocIds();
assert validDocIds != null;

ThreadSafeMutableRoaringBitmap validDocIds = Objects.requireNonNull(segment.getValidDocIds());
while (recordInfoIterator.hasNext()) {
RecordInfo recordInfo = recordInfoIterator.next();
_primaryKeyToRecordLocationMap.compute(hashPrimaryKey(recordInfo._primaryKey, _hashFunction),
Expand Down Expand Up @@ -144,8 +144,7 @@ public void addSegment(IndexSegment segment, Iterator<RecordInfo> recordInfoIter
&& LLCSegmentName.isLowLevelConsumerSegmentName(currentSegmentName)
&& LLCSegmentName.getSequenceNumber(segmentName) > LLCSegmentName.getSequenceNumber(
currentSegmentName))) {
assert currentSegment.getValidDocIds() != null;
currentSegment.getValidDocIds().remove(currentRecordLocation.getDocId());
Objects.requireNonNull(currentSegment.getValidDocIds()).remove(currentRecordLocation.getDocId());
validDocIds.add(recordInfo._docId);
return new RecordLocation(segment, recordInfo._docId, recordInfo._comparisonValue);
} else {
Expand Down Expand Up @@ -182,8 +181,7 @@ public GenericRow updateRecord(IndexSegment segment, RecordInfo recordInfo, Gene
}
}

ThreadSafeMutableRoaringBitmap validDocIds = segment.getValidDocIds();
assert validDocIds != null;
ThreadSafeMutableRoaringBitmap validDocIds = Objects.requireNonNull(segment.getValidDocIds());
_result = record;
_primaryKeyToRecordLocationMap.compute(hashPrimaryKey(recordInfo._primaryKey, _hashFunction),
(primaryKey, currentRecordLocation) -> {
Expand All @@ -204,8 +202,7 @@ public GenericRow updateRecord(IndexSegment segment, RecordInfo recordInfo, Gene
if (segment == currentSegment) {
validDocIds.replace(currentDocId, recordInfo._docId);
} else {
assert currentSegment.getValidDocIds() != null;
currentSegment.getValidDocIds().remove(currentDocId);
Objects.requireNonNull(currentSegment.getValidDocIds()).remove(currentDocId);
validDocIds.add(recordInfo._docId);
}
return new RecordLocation(segment, recordInfo._docId, recordInfo._comparisonValue);
Expand Down Expand Up @@ -238,8 +235,7 @@ public void removeSegment(IndexSegment segment) {
String segmentName = segment.getSegmentName();
LOGGER.info("Removing upsert metadata for segment: {}", segmentName);

assert segment.getValidDocIds() != null;
if (!segment.getValidDocIds().getMutableRoaringBitmap().isEmpty()) {
if (!Objects.requireNonNull(segment.getValidDocIds()).getMutableRoaringBitmap().isEmpty()) {
// Remove all the record locations that point to the removed segment
_primaryKeyToRecordLocationMap.forEach((primaryKey, recordLocation) -> {
if (recordLocation.getSegment() == segment) {
Expand Down

0 comments on commit 82aab9e

Please sign in to comment.