Search in sources :

Example 1 with IOpenBitSet

use of org.alfresco.solr.adapters.IOpenBitSet in project SearchServices by Alfresco.

the class SolrInformationServer method reportTransactionInfo.

private void reportTransactionInfo(TransactionInfoReporter reporter, Long minId, long maxId, IOpenBitSet idsInDb, SolrQueryRequest request, String field) {
    if (minId != null) {
        IOpenBitSet idsInIndex = this.getOpenBitSetInstance();
        long batchStartId = minId;
        long batchEndId = Math.min(batchStartId + BATCH_FACET_TXS, maxId);
        // Continues as long as the batch does not pass the maximum
        while (batchStartId <= maxId) {
            long iterationStart = batchStartId;
            NamedList<Integer> idCounts = this.getFacets(request, field + ":[" + batchStartId + " TO " + batchEndId + "]", field, // Min count of 1 ensures that the id returned is in the index
            1);
            for (Map.Entry<String, Integer> idCount : idCounts) {
                long idInIndex = Long.valueOf(idCount.getKey());
                // Only looks at facet values that fit the query
                if (batchStartId <= idInIndex && idInIndex <= batchEndId) {
                    idsInIndex.set(idInIndex);
                    // The sequence of ids in the index could look like this: 1, 2, 5, 7...
                    for (long id = iterationStart; id <= idInIndex; id++) {
                        if (id == idInIndex) {
                            iterationStart = idInIndex + 1;
                            if (!idsInDb.get(id)) {
                                reporter.reportIdInIndexButNotInDb(id);
                            }
                        } else if (idsInDb.get(id)) {
                            reporter.reportIdInDbButNotInIndex(id);
                        }
                    }
                    if (idCount.getValue().intValue() > 1) {
                        reporter.reportDuplicatedIdInIndex(idInIndex);
                    }
                } else {
                    break;
                }
            }
            batchStartId = batchEndId + 1;
            batchEndId = Math.min(batchStartId + BATCH_FACET_TXS, maxId);
        }
        reporter.reportUniqueIdsInIndex(idsInIndex.cardinality());
    }
}
Also used : IOpenBitSet(org.alfresco.solr.adapters.IOpenBitSet) Map(java.util.Map) SolrSimpleOrderedMap(org.alfresco.solr.adapters.SolrSimpleOrderedMap) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) ISimpleOrderedMap(org.alfresco.solr.adapters.ISimpleOrderedMap)

Example 2 with IOpenBitSet

use of org.alfresco.solr.adapters.IOpenBitSet in project SearchServices by Alfresco.

the class AlfrescoCoreAdminHandler method actionFIX.

private void actionFIX(String coreName) throws AuthenticationException, IOException, JSONException, EncoderException {
    // Gets Metadata health and fixes any problems
    MetadataTracker metadataTracker = trackerRegistry.getTrackerForCore(coreName, MetadataTracker.class);
    IndexHealthReport indexHealthReport = metadataTracker.checkIndex(null, null, null, null);
    IOpenBitSet toReindex = indexHealthReport.getTxInIndexButNotInDb();
    toReindex.or(indexHealthReport.getDuplicatedTxInIndex());
    toReindex.or(indexHealthReport.getMissingTxFromIndex());
    long current = -1;
    // Goes through problems in the index
    while ((current = toReindex.nextSetBit(current + 1)) != -1) {
        metadataTracker.addTransactionToReindex(current);
    }
    // Gets the Acl health and fixes any problems
    AclTracker aclTracker = trackerRegistry.getTrackerForCore(coreName, AclTracker.class);
    indexHealthReport = aclTracker.checkIndex(null, null, null, null);
    toReindex = indexHealthReport.getAclTxInIndexButNotInDb();
    toReindex.or(indexHealthReport.getDuplicatedAclTxInIndex());
    toReindex.or(indexHealthReport.getMissingAclTxFromIndex());
    current = -1;
    // Goes through the problems in the index
    while ((current = toReindex.nextSetBit(current + 1)) != -1) {
        aclTracker.addAclChangeSetToReindex(current);
    }
}
Also used : IOpenBitSet(org.alfresco.solr.adapters.IOpenBitSet)

Example 3 with IOpenBitSet

use of org.alfresco.solr.adapters.IOpenBitSet in project SearchServices by Alfresco.

the class MetadataTracker method checkIndex.

public IndexHealthReport checkIndex(Long toTx, Long toAclTx, Long fromTime, Long toTime) throws IOException, AuthenticationException, JSONException, EncoderException {
    // DB TX Count
    long firstTransactionCommitTime = 0;
    Transactions firstTransactions = client.getTransactions(null, 0L, null, 2000L, 1);
    if (firstTransactions.getTransactions().size() > 0) {
        Transaction firstTransaction = firstTransactions.getTransactions().get(0);
        firstTransactionCommitTime = firstTransaction.getCommitTimeMs();
    }
    IOpenBitSet txIdsInDb = infoSrv.getOpenBitSetInstance();
    Long lastTxCommitTime = Long.valueOf(firstTransactionCommitTime);
    if (fromTime != null) {
        lastTxCommitTime = fromTime;
    }
    long maxTxId = 0;
    Long minTxId = null;
    Transactions transactions;
    BoundedDeque<Transaction> txnsFound = new BoundedDeque<Transaction>(100);
    long endTime = System.currentTimeMillis() + infoSrv.getHoleRetention();
    DO: do {
        transactions = getSomeTransactions(txnsFound, lastTxCommitTime, TIME_STEP_1_HR_IN_MS, 2000, endTime);
        for (Transaction info : transactions.getTransactions()) {
            // include
            if (toTime != null) {
                if (info.getCommitTimeMs() > toTime.longValue()) {
                    break DO;
                }
            }
            if (toTx != null) {
                if (info.getId() > toTx.longValue()) {
                    break DO;
                }
            }
            // bounds for later loops
            if (minTxId == null) {
                minTxId = info.getId();
            }
            if (maxTxId < info.getId()) {
                maxTxId = info.getId();
            }
            lastTxCommitTime = info.getCommitTimeMs();
            txIdsInDb.set(info.getId());
            txnsFound.add(info);
        }
    } while (transactions.getTransactions().size() > 0);
    return this.infoSrv.reportIndexTransactions(minTxId, txIdsInDb, maxTxId);
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) BoundedDeque(org.alfresco.solr.BoundedDeque) IOpenBitSet(org.alfresco.solr.adapters.IOpenBitSet)

Example 4 with IOpenBitSet

use of org.alfresco.solr.adapters.IOpenBitSet in project SearchServices by Alfresco.

the class AclTracker method checkIndex.

public IndexHealthReport checkIndex(Long toTx, Long toAclTx, Long fromTime, Long toTime) throws AuthenticationException, IOException, JSONException {
    // DB ACL TX Count
    long firstChangeSetCommitTimex = 0;
    AclChangeSets firstChangeSets = client.getAclChangeSets(null, 0L, null, 2000L, 1);
    if (firstChangeSets.getAclChangeSets().size() > 0) {
        AclChangeSet firstChangeSet = firstChangeSets.getAclChangeSets().get(0);
        firstChangeSetCommitTimex = firstChangeSet.getCommitTimeMs();
    }
    IOpenBitSet aclTxIdsInDb = infoSrv.getOpenBitSetInstance();
    Long lastAclTxCommitTime = Long.valueOf(firstChangeSetCommitTimex);
    if (fromTime != null) {
        lastAclTxCommitTime = fromTime;
    }
    long maxAclTxId = 0;
    Long minAclTxId = null;
    long endTime = System.currentTimeMillis() + infoSrv.getHoleRetention();
    AclChangeSets aclTransactions;
    BoundedDeque<AclChangeSet> changeSetsFound = new BoundedDeque<AclChangeSet>(100);
    DO: do {
        aclTransactions = getSomeAclChangeSets(changeSetsFound, lastAclTxCommitTime, TIME_STEP_1_HR_IN_MS, 2000, endTime);
        for (AclChangeSet set : aclTransactions.getAclChangeSets()) {
            // include
            if (toTime != null) {
                if (set.getCommitTimeMs() > toTime.longValue()) {
                    break DO;
                }
            }
            if (toAclTx != null) {
                if (set.getId() > toAclTx.longValue()) {
                    break DO;
                }
            }
            // bounds for later loops
            if (minAclTxId == null) {
                minAclTxId = set.getId();
            }
            if (maxAclTxId < set.getId()) {
                maxAclTxId = set.getId();
            }
            lastAclTxCommitTime = set.getCommitTimeMs();
            aclTxIdsInDb.set(set.getId());
            changeSetsFound.add(set);
        }
    } while (aclTransactions.getAclChangeSets().size() > 0);
    return this.infoSrv.reportAclTransactionsInIndex(minAclTxId, aclTxIdsInDb, maxAclTxId);
}
Also used : BoundedDeque(org.alfresco.solr.BoundedDeque) AclChangeSets(org.alfresco.solr.client.AclChangeSets) IOpenBitSet(org.alfresco.solr.adapters.IOpenBitSet) AclChangeSet(org.alfresco.solr.client.AclChangeSet)

Aggregations

IOpenBitSet (org.alfresco.solr.adapters.IOpenBitSet)4 BoundedDeque (org.alfresco.solr.BoundedDeque)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ISimpleOrderedMap (org.alfresco.solr.adapters.ISimpleOrderedMap)1 SolrSimpleOrderedMap (org.alfresco.solr.adapters.SolrSimpleOrderedMap)1 AclChangeSet (org.alfresco.solr.client.AclChangeSet)1 AclChangeSets (org.alfresco.solr.client.AclChangeSets)1 Transaction (org.alfresco.solr.client.Transaction)1 Transactions (org.alfresco.solr.client.Transactions)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1