Narrowing fixes

This commit is contained in:
jeffbanks 2023-01-04 17:58:30 -06:00 committed by Mike Yaacoub
parent f1bb2ed065
commit ecfe3d633f
2 changed files with 15 additions and 15 deletions

View File

@ -22,8 +22,8 @@ import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.CycleResult
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.ResultReadable;
import io.nosqlbench.engine.api.activityapi.cyclelog.inputs.cyclelog.CanFilterResultValue;
import io.nosqlbench.engine.api.activityapi.output.Output;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collections;
import java.util.LinkedList;
@ -35,17 +35,17 @@ import java.util.function.Predicate;
*/
public class ReorderingConcurrentResultBuffer implements Output, CanFilterResultValue {
private final static Logger logger = LogManager.getLogger(ReorderingConcurrentResultBuffer.class);
private static final Logger logger = LogManager.getLogger(ReorderingConcurrentResultBuffer.class);
private final LinkedList<CycleResultsSegment> segments = new LinkedList<>();
private final Output downstream;
private final int threshold;
private int currentCount;
private int segmentCount;
private long currentCount;
private long segmentCount;
private Predicate<ResultReadable> resultFilter;
public ReorderingConcurrentResultBuffer(Output downstream) {
this(downstream,1000);
this(downstream, 1000);
}
public ReorderingConcurrentResultBuffer(Output downstream, int threshold) {
@ -61,24 +61,24 @@ public class ReorderingConcurrentResultBuffer implements Output, CanFilterResult
@Override
public synchronized void onCycleResultSegment(CycleResultsSegment segment) {
if (resultFilter!=null) {
if (resultFilter != null) {
segment = segment.filter(resultFilter);
}
if (!(segment instanceof CanSortCycles)) {
segment = new CycleResultArray(segment);
}
((CanSortCycles)segment).sort();
((CanSortCycles) segment).sort();
segments.add(segment);
segmentCount++;
currentCount+=segment.getCount();
if (currentCount>=threshold) {
logger.trace(() -> "Reordering threshold met: " + currentCount +"/" + threshold + ", sorting and pushing. (" + segments.size() + " segments)");
currentCount += segment.getCount();
if (currentCount >= threshold) {
logger.trace(() -> "Reordering threshold met: " + currentCount + "/" + threshold + ", sorting and pushing. (" + segments.size() + " segments)");
Collections.sort(segments);
while(currentCount>=threshold) {
while (currentCount >= threshold) {
CycleResultsSegment head = segments.removeFirst();
downstream.onCycleResultSegment(head);
segmentCount--;
currentCount-=head.getCount();
currentCount -= head.getCount();
}
}
}
@ -90,7 +90,7 @@ public class ReorderingConcurrentResultBuffer implements Output, CanFilterResult
for (CycleResultsSegment segment : segments) {
downstream.onCycleResultSegment(segment);
segmentCount--;
currentCount-=segment.getCount();
currentCount -= segment.getCount();
}
downstream.close();

View File

@ -130,7 +130,7 @@ public class Unit {
Matcher m = numberFmtPattern.matcher(spec);
if (m.matches()) {
String numberpart = m.group("number");
long base = Long.valueOf(numberpart);
double base = Double.parseDouble(numberpart);
String unitpart = m.group("unit");
if (unitpart != null) {
Count specifierUnit = Count.valueOfSuffix(unitpart);
@ -142,7 +142,7 @@ public class Unit {
double multiplier = (specifierScale / resultScale);
base *= multiplier;
}
return Optional.of(base);
return Optional.of((long) base);
} else {
logger.error("Parsing error for specifier:'" + spec + "'");
return Optional.empty();