fix currSize bug and maxTime bugs

This commit is contained in:
fjy 2013-05-18 13:21:45 -07:00
parent e76fd18a36
commit 8af9598157
3 changed files with 35 additions and 21 deletions

View File

@ -124,7 +124,7 @@ public class DruidServer implements Comparable
return segments.get(segmentName); return segments.get(segmentName);
} }
public DruidServer addDataSegment(String segmentName, DataSegment segment) public DruidServer addDataSegment(String segmentId, DataSegment segment)
{ {
synchronized (lock) { synchronized (lock) {
String dataSourceName = segment.getDataSource(); String dataSourceName = segment.getDataSource();
@ -138,10 +138,11 @@ public class DruidServer implements Comparable
dataSources.put(dataSourceName, dataSource); dataSources.put(dataSourceName, dataSource);
} }
dataSource.addSegment(segmentName, segment); dataSource.addSegment(segmentId, segment);
segments.put(segmentName, segment); if (!segments.containsKey(segmentId)) {
segments.put(segmentId, segment);
currSize += segment.getSize(); currSize += segment.getSize();
}
} }
return this; return this;
} }
@ -156,13 +157,13 @@ public class DruidServer implements Comparable
return this; return this;
} }
public DruidServer removeDataSegment(String segmentName) public DruidServer removeDataSegment(String segmentId)
{ {
synchronized (lock) { synchronized (lock) {
DataSegment segment = segments.get(segmentName); DataSegment segment = segments.get(segmentId);
if (segment == null) { if (segment == null) {
log.warn("Asked to remove data segment that doesn't exist!? server[%s], segment[%s]", getName(), segmentName); log.warn("Asked to remove data segment that doesn't exist!? server[%s], segment[%s]", getName(), segmentId);
return this; return this;
} }
@ -172,18 +173,21 @@ public class DruidServer implements Comparable
log.warn( log.warn(
"Asked to remove data segment from dataSource[%s] that doesn't exist, but the segment[%s] exists!?!?!?! wtf? server[%s]", "Asked to remove data segment from dataSource[%s] that doesn't exist, but the segment[%s] exists!?!?!?! wtf? server[%s]",
segment.getDataSource(), segment.getDataSource(),
segmentName, segmentId,
getName() getName()
); );
return this; return this;
} }
dataSource.removePartition(segmentName); dataSource.removePartition(segmentId);
segments.remove(segmentName); if (segments.containsKey(segmentId)) {
segments.remove(segmentId);
currSize -= segment.getSize();
}
if (dataSource.isEmpty()) { if (dataSource.isEmpty()) {
dataSources.remove(dataSource.getName()); dataSources.remove(dataSource.getName());
} }
currSize -= segment.getSize();
} }
return this; return this;

View File

@ -115,11 +115,14 @@ public class IncrementalIndexStorageAdapter implements StorageAdapter
public Iterable<Cursor> makeCursors(final Filter filter, final Interval interval, final QueryGranularity gran) public Iterable<Cursor> makeCursors(final Filter filter, final Interval interval, final QueryGranularity gran)
{ {
Interval actualIntervalTmp = interval; Interval actualIntervalTmp = interval;
Interval dataInterval = getInterval(); final Interval indexInterval = getInterval();
if (!actualIntervalTmp.overlaps(dataInterval)) {
if (!actualIntervalTmp.overlaps(indexInterval)) {
return ImmutableList.of(); return ImmutableList.of();
} }
final Interval dataInterval = new Interval(getMinTime().getMillis(), gran.next(getMaxTime().getMillis()));
if (actualIntervalTmp.getStart().isBefore(dataInterval.getStart())) { if (actualIntervalTmp.getStart().isBefore(dataInterval.getStart())) {
actualIntervalTmp = actualIntervalTmp.withStart(dataInterval.getStart()); actualIntervalTmp = actualIntervalTmp.withStart(dataInterval.getStart());
} }
@ -367,7 +370,7 @@ public class IncrementalIndexStorageAdapter implements StorageAdapter
final String columnName = column.toLowerCase(); final String columnName = column.toLowerCase();
final Integer metricIndexInt = index.getMetricIndex(columnName); final Integer metricIndexInt = index.getMetricIndex(columnName);
if(metricIndexInt != null) { if (metricIndexInt != null) {
final int metricIndex = metricIndexInt; final int metricIndex = metricIndexInt;
final ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(index.getMetricType(columnName)); final ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(index.getMetricType(columnName));
@ -390,7 +393,7 @@ public class IncrementalIndexStorageAdapter implements StorageAdapter
final Integer dimensionIndexInt = index.getDimensionIndex(columnName); final Integer dimensionIndexInt = index.getDimensionIndex(columnName);
if(dimensionIndexInt != null) { if (dimensionIndexInt != null) {
final int dimensionIndex = dimensionIndexInt; final int dimensionIndex = dimensionIndexInt;
return new ObjectColumnSelector<String>() return new ObjectColumnSelector<String>()
{ {
@ -404,10 +407,14 @@ public class IncrementalIndexStorageAdapter implements StorageAdapter
public String get() public String get()
{ {
final String[] dimVals = currEntry.getKey().getDims()[dimensionIndex]; final String[] dimVals = currEntry.getKey().getDims()[dimensionIndex];
if(dimVals.length == 1) return dimVals[0]; if (dimVals.length == 1) {
if(dimVals.length == 0) return null; return dimVals[0];
}
if (dimVals.length == 0) {
return null;
}
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"makeObjectColumnSelector does not support multivalued columns" "makeObjectColumnSelector does not support multivalued columns"
); );
} }
}; };

View File

@ -136,11 +136,14 @@ public class QueryableIndexStorageAdapter extends BaseStorageAdapter
public Iterable<Cursor> makeCursors(Filter filter, Interval interval, QueryGranularity gran) public Iterable<Cursor> makeCursors(Filter filter, Interval interval, QueryGranularity gran)
{ {
Interval actualInterval = interval; Interval actualInterval = interval;
final Interval dataInterval = getInterval(); final Interval indexInterval = getInterval();
if (!actualInterval.overlaps(dataInterval)) {
if (!actualInterval.overlaps(indexInterval)) {
return ImmutableList.of(); return ImmutableList.of();
} }
final Interval dataInterval = new Interval(getMinTime().getMillis(), gran.next(getMaxTime().getMillis()));
if (actualInterval.getStart().isBefore(dataInterval.getStart())) { if (actualInterval.getStart().isBefore(dataInterval.getStart())) {
actualInterval = actualInterval.withStart(dataInterval.getStart()); actualInterval = actualInterval.withStart(dataInterval.getStart());
} }