-
Notifications
You must be signed in to change notification settings - Fork 217
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
Fix number of parallel repair computation #108
Closed
+132
−21
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.concurrent.TimeUnit; | ||
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. |
||
import java.util.stream.Collectors; | ||
|
||
import org.slf4j.Logger; | ||
|
@@ -61,7 +62,7 @@ public class CassandraStorage implements IStorage { | |
/** simple cache of repair_id. | ||
* not accurate, only provides a floor value to shortcut looking for next appropriate id */ | ||
private final ConcurrentMap<String,Long> repairIds = new ConcurrentHashMap<>(); | ||
|
||
/* Simple statements */ | ||
private final String getClustersStmt = "SELECT * FROM cluster"; | ||
|
||
|
@@ -426,7 +427,26 @@ public Collection<RepairSegment> getRepairSegmentsForRun(long runId) { | |
// Then get segments by id | ||
segmentsFuture.add(session.executeAsync(getRepairSegmentPrepStmt.bind(segmentIdResult.getLong("segment_id")))); | ||
i++; | ||
if(i%100==0 || segmentsIdResultSet.isFullyFetched()) { | ||
if(i%100==0 || segmentsIdResultSet.isExhausted()) { | ||
segments.addAll(fetchRepairSegmentFromFutures(segmentsFuture)); | ||
segmentsFuture = Lists.newArrayList(); | ||
} | ||
} | ||
|
||
return segments; | ||
} | ||
|
||
public Collection<RepairSegment> getRepairSegmentsForRunWithCache(long runId) { | ||
List<ResultSetFuture> segmentsFuture = Lists.newArrayList(); | ||
Collection<RepairSegment> segments = Lists.newArrayList(); | ||
|
||
// First gather segments ids | ||
ResultSet segmentsIdResultSet = session.execute(getRepairSegmentByRunIdPrepStmt.bind(runId)); | ||
int i=0; | ||
for(Row segmentIdResult:segmentsIdResultSet) { | ||
segmentsFuture.add(session.executeAsync(getRepairSegmentPrepStmt.bind(segmentIdResult.getLong("segment_id")))); | ||
i++; | ||
if(i%100==0 || segmentsIdResultSet.isExhausted()) { | ||
segments.addAll(fetchRepairSegmentFromFutures(segmentsFuture)); | ||
segmentsFuture = Lists.newArrayList(); | ||
} | ||
|
@@ -441,32 +461,41 @@ private Collection<RepairSegment> fetchRepairSegmentFromFutures(List<ResultSetFu | |
for(ResultSetFuture segmentResult:segmentsFuture) { | ||
Row segmentRow = segmentResult.getUninterruptibly().one(); | ||
if(segmentRow!=null){ | ||
segments.add(createRepairSegmentFromRow(segmentRow)); | ||
RepairSegment segment = createRepairSegmentFromRow(segmentRow); | ||
segments.add(segment); | ||
} | ||
} | ||
|
||
return segments; | ||
|
||
} | ||
|
||
private boolean segmentIsWithinRange(RepairSegment segment, RingRange range) { | ||
return range.encloses(new RingRange(segment.getStartToken(), segment.getEndToken())); | ||
|
||
} | ||
|
||
private RepairSegment createRepairSegmentFromRow(Row segmentRow){ | ||
return createRepairSegmentFromRow(segmentRow, segmentRow.getLong("id")); | ||
} | ||
|
||
private RepairSegment createRepairSegmentFromRow(Row segmentRow, long segmentId){ | ||
return new RepairSegment.Builder(segmentRow.getLong("run_id"), new RingRange(new BigInteger(segmentRow.getVarint("start_token") +""), new BigInteger(segmentRow.getVarint("end_token")+"")), segmentRow.getLong("repair_unit_id")) | ||
RepairSegment segment = new RepairSegment.Builder(segmentRow.getLong("run_id"), new RingRange(new BigInteger(segmentRow.getVarint("start_token") +""), new BigInteger(segmentRow.getVarint("end_token")+"")), segmentRow.getLong("repair_unit_id")) | ||
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. |
||
.coordinatorHost(segmentRow.getString("coordinator_host")) | ||
.endTime(new DateTime(segmentRow.getTimestamp("end_time"))) | ||
.failCount(segmentRow.getInt("fail_count")) | ||
.startTime(new DateTime(segmentRow.getTimestamp("start_time"))) | ||
.state(State.values()[segmentRow.getInt("state")]) | ||
.build(segmentRow.getLong("id")); | ||
|
||
return segment; | ||
} | ||
|
||
|
||
public Optional<RepairSegment> getSegment(long runId, Optional<RingRange> range){ | ||
RepairSegment segment = null; | ||
List<RepairSegment> segments = Lists.<RepairSegment>newArrayList(); | ||
segments.addAll(getRepairSegmentsForRun(runId)); | ||
segments.addAll(getRepairSegmentsForRunWithCache(runId)); | ||
|
||
// Sort segments by fail count and start token (in order to try those who haven't failed first, in start token order) | ||
Collections.sort( segments, new Comparator<RepairSegment>(){ | ||
|
@@ -481,16 +510,16 @@ public int compare(RepairSegment seg1, RepairSegment seg2) { | |
for(RepairSegment seg:segments){ | ||
if(seg.getState().equals(State.NOT_STARTED) // State condition | ||
&& ((range.isPresent() && | ||
(range.get().getStart().compareTo(seg.getStartToken())>=0 || range.get().getEnd().compareTo(seg.getEndToken())<=0) | ||
(segmentIsWithinRange(seg, range.get())) | ||
) || !range.isPresent()) // Token range condition | ||
){ | ||
segment = seg; | ||
break; | ||
segment = seg; | ||
break; | ||
} | ||
} | ||
return Optional.fromNullable(segment); | ||
} | ||
|
||
@Override | ||
public Optional<RepairSegment> getNextFreeSegment(long runId) { | ||
return getSegment(runId, Optional.<RingRange>absent()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.