Search in sources :

Example 1 with IndexingListener

use of org.sonar.server.es.IndexingListener in project sonarqube by SonarSource.

the class IssueIndexer method doIndexProjectItems.

private IndexingResult doIndexProjectItems(DbSession dbSession, ListMultimap<String, EsQueueDto> itemsByProjectUuid) {
    if (itemsByProjectUuid.isEmpty()) {
        return new IndexingResult();
    }
    // one project, referenced by es_queue.doc_id = many issues
    IndexingListener listener = new OneToManyResilientIndexingListener(dbClient, dbSession, itemsByProjectUuid.values());
    BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
    bulkIndexer.start();
    for (String projectUuid : itemsByProjectUuid.keySet()) {
        // TODO support loading of multiple projects in a single SQL request
        try (IssueIterator issues = issueIteratorFactory.createForProject(projectUuid)) {
            if (issues.hasNext()) {
                do {
                    IssueDoc doc = issues.next();
                    bulkIndexer.add(newIndexRequest(doc));
                } while (issues.hasNext());
            } else {
                // project does not exist or has no issues. In both case
                // all the documents related to this project are deleted.
                addProjectDeletionToBulkIndexer(bulkIndexer, projectUuid);
            }
        }
    }
    return bulkIndexer.stop();
}
Also used : IndexingListener(org.sonar.server.es.IndexingListener) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener) OneToManyResilientIndexingListener(org.sonar.server.es.OneToManyResilientIndexingListener) OneToManyResilientIndexingListener(org.sonar.server.es.OneToManyResilientIndexingListener) IndexingResult(org.sonar.server.es.IndexingResult) BulkIndexer(org.sonar.server.es.BulkIndexer)

Example 2 with IndexingListener

use of org.sonar.server.es.IndexingListener 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();
}
Also used : IndexingListener(org.sonar.server.es.IndexingListener) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener) OneToManyResilientIndexingListener(org.sonar.server.es.OneToManyResilientIndexingListener) IndexingResult(org.sonar.server.es.IndexingResult) BulkIndexer(org.sonar.server.es.BulkIndexer) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener)

Aggregations

BulkIndexer (org.sonar.server.es.BulkIndexer)2 IndexingListener (org.sonar.server.es.IndexingListener)2 IndexingResult (org.sonar.server.es.IndexingResult)2 OneToManyResilientIndexingListener (org.sonar.server.es.OneToManyResilientIndexingListener)2 OneToOneResilientIndexingListener (org.sonar.server.es.OneToOneResilientIndexingListener)2