use of org.sonar.server.es.OneToOneResilientIndexingListener in project sonarqube by SonarSource.
the class UserIndexer method index.
/**
* @return the number of items that have been successfully indexed
*/
@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
if (items.isEmpty()) {
return new IndexingResult();
}
Set<String> uuids = items.stream().map(EsQueueDto::getDocId).collect(toHashSet(items.size()));
BulkIndexer bulkIndexer = newBulkIndexer(Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items));
bulkIndexer.start();
dbClient.userDao().scrollByUuids(dbSession, uuids, // Deactivated users are not deleted but updated.
u -> {
uuids.remove(u.getUuid());
bulkIndexer.add(newIndexRequest(u));
});
// the remaining uuids reference rows that don't exist in db. They must
// be deleted from index.
uuids.forEach(uuid -> bulkIndexer.addDeletion(TYPE_USER, uuid));
return bulkIndexer.stop();
}
use of org.sonar.server.es.OneToOneResilientIndexingListener in project sonarqube by SonarSource.
the class IssueIndexer method doIndexIssueItems.
private IndexingResult doIndexIssueItems(DbSession dbSession, ListMultimap<String, EsQueueDto> itemsByIssueKey) {
if (itemsByIssueKey.isEmpty()) {
return new IndexingResult();
}
IndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, itemsByIssueKey.values());
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
bulkIndexer.start();
try (IssueIterator issues = issueIteratorFactory.createForIssueKeys(itemsByIssueKey.keySet())) {
while (issues.hasNext()) {
IssueDoc issue = issues.next();
bulkIndexer.add(newIndexRequest(issue));
itemsByIssueKey.removeAll(issue.getId());
}
}
// the remaining uuids reference issues that don't exist in db. They must
// be deleted from index.
itemsByIssueKey.values().forEach(item -> bulkIndexer.addDeletion(TYPE_ISSUE.getMainType(), item.getDocId(), item.getDocRouting()));
return bulkIndexer.stop();
}
Aggregations