Search in sources :

Example 1 with WikibaseEntityFetchException

use of org.wikidata.query.rdf.tool.wikibase.WikibaseEntityFetchException in project wikidata-query-rdf by wikimedia.

the class Updater method handleChange.

/**
 * Handle a change.
 * <ul>
 * <li>Check if the RDF store has the version of the page.
 * <li>Fetch the RDF from the Wikibase install.
 * <li>Add revision information to the statements if it isn't there already.
 * <li>Sync data to the triple store.
 * </ul>
 *
 * @throws RetryableException if there is a retryable error updating the rdf
 *             store
 */
private void handleChange(Change change, Set<String> repoValues, Set<String> repoRefs) throws RetryableException {
    log.debug("Processing data for {}", change);
    Collection<Statement> statements;
    try {
        statements = wikibase.fetchRdfForEntity(change);
    } catch (WikibaseEntityFetchException e) {
        if (DELETE_ENTITY_ERROR_TYPE.contains(e.getErrorType())) {
            log.debug("Cannot fetch entity (deleting entity): ", e);
            statements = new ArrayList<>();
        } else {
            throw new ContainedException("Received un-recoverable error fetching entity data for " + change.entityId(), e);
        }
    }
    if (verify) {
        Set<String> entityStmtsWithoutRank = statements.stream().collect(entityStatementsWithoutRank());
        if (!entityStmtsWithoutRank.isEmpty()) {
            log.warn("Found some statements without ranks while processing {}: {}", change.entityId(), entityStmtsWithoutRank);
        }
    }
    Set<String> valuesToClean = Collections.emptySet();
    Set<String> referencesToClean = Collections.emptySet();
    if (!statements.isEmpty()) {
        valuesToClean = RdfRepository.extractValuesToCleanup(repoValues, statements);
        referencesToClean = RdfRepository.extractReferencesToCleanup(repoRefs, statements);
        long fetchedRev = munger.munge(change.entityId(), statements);
        // If we've got no statements, we have no usable loaded data, so no point in checking
        // Same if we just got back our own change - no point in checking against it
        final long sourceRev = change.revision();
        if (sourceRev > 0 && fetchedRev > 0) {
            if (fetchedRev < sourceRev) {
                // Something weird happened - we've got stale revision!
                log.warn("Stale revision on {}: change is {}, RDF is {}", change.entityId(), sourceRev, fetchedRev);
                metricsRepository.incDeferredChanges();
                deferredChanges.add(change, DEFERRAL_DELAY);
            }
            if (sourceRev < fetchedRev) {
                // We skipped some revisions, let's count it in meter
                metricsRepository.markSkipAhead();
            }
        }
    }
    /*
         * TODO: we temporarily keep all the ref data because of the issues
         * in https://phabricator.wikimedia.org/T194325
         * see Change-ID Ia6c68a5b93e8c9a35310892904819c956ca9cd95
         * or git commit hash 2931b5af725b7ab341dd60920710619fa249d1f2
         * for more context
         */
    referencesToClean = Collections.emptySet();
    change.setRefCleanupList(referencesToClean);
    /*
         * TODO: we disable values cleanup to measure the impact on the lag
         *  see: T249196
         */
    valuesToClean = Collections.emptySet();
    change.setValueCleanupList(valuesToClean);
    change.setStatements(statements);
}
Also used : Statement(org.openrdf.model.Statement) ArrayList(java.util.ArrayList) ContainedException(org.wikidata.query.rdf.tool.exception.ContainedException) WikibaseEntityFetchException(org.wikidata.query.rdf.tool.wikibase.WikibaseEntityFetchException)

Aggregations

ArrayList (java.util.ArrayList)1 Statement (org.openrdf.model.Statement)1 ContainedException (org.wikidata.query.rdf.tool.exception.ContainedException)1 WikibaseEntityFetchException (org.wikidata.query.rdf.tool.wikibase.WikibaseEntityFetchException)1