-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix num_rows in sys.segments #6888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f7c2633
24fbe1c
ebeff85
97721d1
22d8304
b27a3d4
68ec9c7
ae66255
1a1ccff
57778a1
24085bc
8eb2ac0
afbf83f
e29bedb
c2640e6
11b84dd
5720a96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |
| import org.apache.druid.timeline.SegmentId; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
|
|
@@ -36,15 +35,25 @@ public static Builder builder( | |
| long isPublished, | ||
| long isAvailable, | ||
| long isRealtime, | ||
| Map<SegmentId, Set<String>> segmentServerMap | ||
| Set<String> segmentServers, | ||
| RowSignature rowSignature, | ||
| long numRows | ||
| ) | ||
| { | ||
| return new Builder(segmentId, isPublished, isAvailable, isRealtime, segmentServerMap); | ||
| return new Builder(segmentId, isPublished, isAvailable, isRealtime, segmentServers, rowSignature, numRows); | ||
| } | ||
|
|
||
| public static Builder from(SegmentMetadataHolder h) | ||
| { | ||
| return new Builder(h.getSegmentId(), h.isPublished(), h.isAvailable(), h.isRealtime(), h.getReplicas()); | ||
| return new Builder( | ||
| h.getSegmentId(), | ||
| h.isPublished(), | ||
| h.isAvailable(), | ||
| h.isRealtime(), | ||
| h.getReplicas(), | ||
| h.getRowSignature(), | ||
| h.getNumRows() | ||
| ); | ||
| } | ||
|
|
||
| private final SegmentId segmentId; | ||
|
|
@@ -54,8 +63,8 @@ public static Builder from(SegmentMetadataHolder h) | |
| private final long isPublished; | ||
| private final long isAvailable; | ||
| private final long isRealtime; | ||
| //segmentId -> set of servers that contain the segment | ||
| private final Map<SegmentId, Set<String>> segmentServerMap; | ||
| // set of servers that contain the segment | ||
| private final Set<String> segmentServers; | ||
| private final long numRows; | ||
| @Nullable | ||
| private final RowSignature rowSignature; | ||
|
|
@@ -66,7 +75,7 @@ private SegmentMetadataHolder(Builder builder) | |
| this.isPublished = builder.isPublished; | ||
| this.isAvailable = builder.isAvailable; | ||
| this.isRealtime = builder.isRealtime; | ||
| this.segmentServerMap = builder.segmentServerMap; | ||
| this.segmentServers = builder.segmentServers; | ||
| this.numRows = builder.numRows; | ||
| this.segmentId = builder.segmentId; | ||
| } | ||
|
|
@@ -91,14 +100,14 @@ public SegmentId getSegmentId() | |
| return segmentId; | ||
| } | ||
|
|
||
| public Map<SegmentId, Set<String>> getReplicas() | ||
| public Set<String> getReplicas() | ||
| { | ||
| return segmentServerMap; | ||
| return segmentServers; | ||
| } | ||
|
|
||
| public long getNumReplicas(SegmentId segmentId) | ||
| public long getNumReplicas() | ||
| { | ||
| return segmentServerMap.get(segmentId).size(); | ||
| return segmentServers.size(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we return long in this method when Set#size() returns an int? Might not be worth changing because it might blow up other stuff.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It used to be int, and then got changed to long at some point. The reason is because we support nulls for long here, but not for ints ? Not very sure...but will likely leave it to be long here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
| } | ||
|
|
||
| public long getNumRows() | ||
|
|
@@ -119,7 +128,7 @@ public static class Builder | |
| private final long isAvailable; | ||
| private final long isRealtime; | ||
|
|
||
| private Map<SegmentId, Set<String>> segmentServerMap; | ||
| private Set<String> segmentServers; | ||
| @Nullable | ||
| private RowSignature rowSignature; | ||
| private long numRows; | ||
|
|
@@ -129,14 +138,18 @@ private Builder( | |
| long isPublished, | ||
| long isAvailable, | ||
| long isRealtime, | ||
| Map<SegmentId, Set<String>> segmentServerMap | ||
| Set<String> servers, | ||
| RowSignature rowSignature, | ||
| long numRows | ||
| ) | ||
| { | ||
| this.segmentId = segmentId; | ||
| this.isPublished = isPublished; | ||
| this.isAvailable = isAvailable; | ||
| this.isRealtime = isRealtime; | ||
| this.segmentServerMap = segmentServerMap; | ||
| this.segmentServers = servers; | ||
| this.rowSignature = rowSignature; | ||
| this.numRows = numRows; | ||
| } | ||
|
|
||
| public Builder withRowSignature(RowSignature rowSignature) | ||
|
|
@@ -151,9 +164,9 @@ public Builder withNumRows(long numRows) | |
| return this; | ||
| } | ||
|
|
||
| public Builder withReplicas(Map<SegmentId, Set<String>> segmentServerMap) | ||
| public Builder withReplicas(Set<String> servers) | ||
| { | ||
| this.segmentServerMap = segmentServerMap; | ||
| this.segmentServers = servers; | ||
| return this; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this comment, you could add
@GuardedBy("lock"). It sends the same message, and could also help with automated bug detection.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good suggestion, thanks.