in tcbot-teamcity-ignited/src/main/java/org/apache/ignite/tcignited/history/HistoryCollector.java [348:415]
public List<Long> findAllRecentBuilds(int days, Collection<String> allServers) {
IgniteCache<Long, BuildRefCompacted> cache = buildRefDao.buildRefsCache();
if (cache == null)
throw new ServicesStartingException(new RuntimeException("Ignite is not yet available"));
IgniteCache<Long, BinaryObject> cacheBin = cache.withKeepBinary();
final Map<Integer, Integer> preBorder = new HashMap<>();
allServers.stream()
.map(ITeamcityIgnited::serverIdToInt)
.forEach(srvId -> {
Integer borderForAgeForBuildId = buildStartTimeStorage.getBorderForAgeForBuildId(srvId, days);
if (borderForAgeForBuildId != null)
preBorder.put(srvId, borderForAgeForBuildId);
});
final int stateQueued = compactor.getStringId(BuildRef.STATE_QUEUED);
long minTs = System.currentTimeMillis() - Duration.ofDays(days).toMillis();
QueryCursor<Cache.Entry<Long, BinaryObject>> query = cacheBin.query(
new ScanQuery<Long, BinaryObject>()
.setFilter((key, v) -> {
int srvId = BuildRefDao.cacheKeyToSrvId(key);
Integer buildIdBorder = preBorder.get(srvId);
if (buildIdBorder != null) {
int id = v.field("id");
if (id < buildIdBorder)
return false;// pre-filtered build out of scope
}
int state = v.field("state");
return stateQueued != state;
}));
int cnt = 0;
List<Long> idsToCheck = new ArrayList<>();
try (QueryCursor<Cache.Entry<Long, BinaryObject>> cursor = query) {
for (Cache.Entry<Long, BinaryObject> next : cursor) {
Long key = next.getKey();
int srvId = BuildRefDao.cacheKeyToSrvId(key);
int buildId = BuildRefDao.cacheKeyToBuildId(key);
Integer borderBuildId = buildStartTimeStorage.getBorderForAgeForBuildId(srvId, days);
boolean passesDate = borderBuildId == null || buildId >= borderBuildId;
if (!passesDate)
continue;
Long startTs = getBuildStartTime(srvId, buildId);
if (startTs == null || startTs < minTs)
continue; //time not saved in the DB, skip
System.err.println("Found build at srv [" + srvId + "]: [" + buildId + "] to analyze, ts=" + startTs);
cnt++;
idsToCheck.add(key);
}
}
System.err.println("Total builds to load " + cnt);
return idsToCheck;
}