Code review comment: I think we should not save Unknown stats into statsTable.

Code before review:
private void doPreHeat() {
List<ResultRow> recentStatsUpdatedCols = null;
long retryTimes = 0;
while (!StatisticsUtil.statsTblAvailable()) {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
}
}
while (retryTimes < StatisticConstants.PRELOAD_RETRY_TIMES) {
try {
recentStatsUpdatedCols = StatisticsRepository.fetchRecentStatsUpdatedCol();
break;
} catch (Throwable t) {
}
retryTimes++;
try {
Thread.sleep(StatisticConstants.PRELOAD_RETRY_INTERVAL_IN_SECONDS);
} catch (Throwable t) {
}
}
if (CollectionUtils.isEmpty(recentStatsUpdatedCols)) {
return;
}
for (ResultRow r : recentStatsUpdatedCols) {
try {
String tblId = r.getColumnValue("tbl_id");
String idxId = r.getColumnValue("idx_id");
String colId = r.getColumnValue("col_id");
final StatisticsCacheKey k =
new StatisticsCacheKey(Long.parseLong(tblId), Long.parseLong(idxId), colId);
final ColumnStatistic c = ColumnStatistic.fromResultRow(r);
CompletableFuture<Optional<ColumnStatistic>> f = new CompletableFuture<Optional<ColumnStatistic>>() {
@Override
public Optional<ColumnStatistic> get() throws InterruptedException, ExecutionException {
return Optional.of(c);
}
@Override
public boolean isDone() {
return true;
}
@Override
public boolean complete(Optional<ColumnStatistic> value) {
return true;
}
@Override
public Optional<ColumnStatistic> join() {
return Optional.of(c);
}
};
if (c == ColumnStatistic.UNKNOWN) {
continue;
}
columnStatisticsCache.put(k, f);
} catch (Throwable t) {
LOG.warn("Error when preheating stats cache", t);
}
}
}

Line under review: if (c == ColumnStatistic.UNKNOWN) {

Code after addressing the review:
private void doPreHeat() {
List<ResultRow> recentStatsUpdatedCols = null;
long retryTimes = 0;
while (!StatisticsUtil.statsTblAvailable()) {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
}
}
while (retryTimes < StatisticConstants.PRELOAD_RETRY_TIMES) {
try {
recentStatsUpdatedCols = StatisticsRepository.fetchRecentStatsUpdatedCol();
break;
} catch (Throwable t) {
}
retryTimes++;
try {
Thread.sleep(StatisticConstants.PRELOAD_RETRY_INTERVAL_IN_SECONDS);
} catch (Throwable t) {
}
}
if (CollectionUtils.isEmpty(recentStatsUpdatedCols)) {
return;
}
for (ResultRow r : recentStatsUpdatedCols) {
try {
String tblId = r.getColumnValue("tbl_id");
String idxId = r.getColumnValue("idx_id");
String colId = r.getColumnValue("col_id");
final StatisticsCacheKey k =
new StatisticsCacheKey(Long.parseLong(tblId), Long.parseLong(idxId), colId);
final ColumnStatistic c = ColumnStatistic.fromResultRow(r);
CompletableFuture<Optional<ColumnStatistic>> f = new CompletableFuture<Optional<ColumnStatistic>>() {
@Override
public Optional<ColumnStatistic> get() throws InterruptedException, ExecutionException {
return Optional.of(c);
}
@Override
public boolean isDone() {
return true;
}
@Override
public boolean complete(Optional<ColumnStatistic> value) {
return true;
}
@Override
public Optional<ColumnStatistic> join() {
return Optional.of(c);
}
};
if (c == ColumnStatistic.UNKNOWN) {
continue;
}
columnStatisticsCache.put(k, f);
} catch (Throwable t) {
LOG.warn("Error when preheating stats cache", t);
}
}
}