Search in sources :

Example 1 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlBaseService method getPerformanceMonitor.

public synchronized SqlPerformanceMonitorImpl getPerformanceMonitor() {
    if (performanceMonitor == null) {
        SqlRepositoryConfiguration config = sqlConfiguration();
        performanceMonitor = new SqlPerformanceMonitorImpl(config.getPerformanceStatisticsLevel(), config.getPerformanceStatisticsFile());
        monitorsCollection.register(performanceMonitor);
    }
    return performanceMonitor;
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)

Example 2 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method returnUnusedValuesToSequence.

@Override
public void returnUnusedValuesToSequence(String oid, Collection<Long> unusedValues, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    OperationResult result = parentResult.subresult(RETURN_UNUSED_VALUES_TO_SEQUENCE).addParam("oid", oid).build();
    LOGGER.trace("Returning unused values of {} to sequence {}", unusedValues, oid);
    if (unusedValues == null || unusedValues.isEmpty()) {
        result.recordSuccess();
        return;
    }
    // TODO executeAttempts
    int attempt = 1;
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_RETURN_UNUSED_VALUES_TO_SEQUENCE, SequenceType.class);
    try {
        while (true) {
            try {
                sequenceHelper.returnUnusedValuesToSequenceAttempt(oid, unusedValues, result);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, "returnUnusedValuesToSequence", attempt, ex, null);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 3 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlAuditServiceImpl method cleanupAuditMaxAge.

private void cleanupAuditMaxAge(CleanupPolicyType policy, OperationResult parentResult) {
    if (policy.getMaxAge() == null) {
        return;
    }
    final String operation = "deletingMaxAge";
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_CLEANUP_AUDIT_MAX_AGE, AuditEventRecord.class);
    int attempt = 1;
    Duration duration = policy.getMaxAge();
    if (duration.getSign() > 0) {
        duration = duration.negate();
    }
    Date minValue = new Date();
    duration.addTo(minValue);
    checkTemporaryTablesSupport();
    long start = System.currentTimeMillis();
    boolean first = true;
    Holder<Integer> totalCountHolder = new Holder<>(0);
    try {
        while (true) {
            try {
                LOGGER.info("{} audit cleanup, deleting up to {} (duration '{}'), batch size {}{}.", first ? "Starting" : "Continuing with ", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries");
                first = false;
                int count;
                do {
                    // the following method may restart due to concurrency
                    // (or any other) problem - in any iteration
                    long batchStart = System.currentTimeMillis();
                    LOGGER.debug("Starting audit cleanup batch, deleting up to {} (duration '{}')," + " batch size {}, up to now deleted {} entries.", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, totalCountHolder.getValue());
                    count = batchDeletionAttempt((session, tempTable) -> selectRecordsByMaxAge(session, tempTable, minValue), totalCountHolder, batchStart, parentResult);
                } while (count > 0);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
        LOGGER.info("Audit cleanup based on age finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L);
    }
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) com.evolveum.midpoint.repo.sqlbase(com.evolveum.midpoint.repo.sqlbase) BiFunction(java.util.function.BiFunction) ChangeType(com.evolveum.midpoint.prism.delta.ChangeType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) com.evolveum.midpoint.repo.sql.audit.querymodel(com.evolveum.midpoint.repo.sql.audit.querymodel) ColumnMetadata(com.querydsl.sql.ColumnMetadata) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) ObjectType(com.evolveum.prism.xml.ns._public.types_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Duration(javax.xml.datatype.Duration) SystemConfigurationAuditType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationAuditType) S_MatchingRuleEntry(com.evolveum.midpoint.prism.query.builder.S_MatchingRuleEntry) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) S_ConditionEntry(com.evolveum.midpoint.prism.query.builder.S_ConditionEntry) Holder(com.evolveum.midpoint.util.Holder) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RChangeType(com.evolveum.midpoint.repo.sql.data.common.enums.RChangeType) SystemConfigurationAuditUtil.isEscapingInvalidCharacters(com.evolveum.midpoint.schema.util.SystemConfigurationAuditUtil.isEscapingInvalidCharacters) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Instant(java.time.Instant) Task(com.evolveum.midpoint.task.api.Task) com.evolveum.midpoint.repo.sql.audit.mapping(com.evolveum.midpoint.repo.sql.audit.mapping) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Nullable(org.jetbrains.annotations.Nullable) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) NotNull(org.jetbrains.annotations.NotNull) MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) Types(java.sql.Types) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ROperationResultStatus(com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus) AuditSqlQueryContext(com.evolveum.midpoint.repo.sql.audit.AuditSqlQueryContext) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) SQLQuery(com.querydsl.sql.SQLQuery) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.xml.ns._public.common.audit_3(com.evolveum.midpoint.xml.ns._public.common.audit_3) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) AuditService(com.evolveum.midpoint.audit.api.AuditService) TemporaryTableDialect(com.evolveum.midpoint.repo.sql.util.TemporaryTableDialect) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) Validate(org.apache.commons.lang3.Validate) DefaultMapper(com.querydsl.sql.dml.DefaultMapper) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) Holder(com.evolveum.midpoint.util.Holder) Duration(javax.xml.datatype.Duration) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 4 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlAuditServiceImpl method cleanupAuditMaxRecords.

private void cleanupAuditMaxRecords(CleanupPolicyType policy, OperationResult parentResult) {
    if (policy.getMaxRecords() == null) {
        return;
    }
    final String operation = "deletingMaxRecords";
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_CLEANUP_AUDIT_MAX_RECORDS, AuditEventRecord.class);
    int attempt = 1;
    int recordsToKeep = policy.getMaxRecords();
    checkTemporaryTablesSupport();
    long start = System.currentTimeMillis();
    boolean first = true;
    Holder<Integer> totalCountHolder = new Holder<>(0);
    try {
        while (true) {
            try {
                LOGGER.info("{} audit cleanup, keeping at most {} records, batch size {}{}.", first ? "Starting" : "Continuing with ", recordsToKeep, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries");
                first = false;
                int count;
                do {
                    // the following method may restart due to concurrency
                    // (or any other) problem - in any iteration
                    long batchStart = System.currentTimeMillis();
                    LOGGER.debug("Starting audit cleanup batch, keeping at most {} records," + " batch size {}, up to now deleted {} entries.", recordsToKeep, CLEANUP_AUDIT_BATCH_SIZE, totalCountHolder.getValue());
                    count = batchDeletionAttempt((session, tempTable) -> selectRecordsByNumberToKeep(session, tempTable, recordsToKeep), totalCountHolder, batchStart, parentResult);
                } while (count > 0);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
        LOGGER.info("Audit cleanup based on record count finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L);
    }
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) com.evolveum.midpoint.repo.sqlbase(com.evolveum.midpoint.repo.sqlbase) BiFunction(java.util.function.BiFunction) ChangeType(com.evolveum.midpoint.prism.delta.ChangeType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) com.evolveum.midpoint.repo.sql.audit.querymodel(com.evolveum.midpoint.repo.sql.audit.querymodel) ColumnMetadata(com.querydsl.sql.ColumnMetadata) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) ObjectType(com.evolveum.prism.xml.ns._public.types_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Duration(javax.xml.datatype.Duration) SystemConfigurationAuditType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationAuditType) S_MatchingRuleEntry(com.evolveum.midpoint.prism.query.builder.S_MatchingRuleEntry) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) S_ConditionEntry(com.evolveum.midpoint.prism.query.builder.S_ConditionEntry) Holder(com.evolveum.midpoint.util.Holder) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RChangeType(com.evolveum.midpoint.repo.sql.data.common.enums.RChangeType) SystemConfigurationAuditUtil.isEscapingInvalidCharacters(com.evolveum.midpoint.schema.util.SystemConfigurationAuditUtil.isEscapingInvalidCharacters) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Instant(java.time.Instant) Task(com.evolveum.midpoint.task.api.Task) com.evolveum.midpoint.repo.sql.audit.mapping(com.evolveum.midpoint.repo.sql.audit.mapping) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Nullable(org.jetbrains.annotations.Nullable) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) NotNull(org.jetbrains.annotations.NotNull) MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) Types(java.sql.Types) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ROperationResultStatus(com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus) AuditSqlQueryContext(com.evolveum.midpoint.repo.sql.audit.AuditSqlQueryContext) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) SQLQuery(com.querydsl.sql.SQLQuery) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.xml.ns._public.common.audit_3(com.evolveum.midpoint.xml.ns._public.common.audit_3) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) AuditService(com.evolveum.midpoint.audit.api.AuditService) TemporaryTableDialect(com.evolveum.midpoint.repo.sql.util.TemporaryTableDialect) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) Validate(org.apache.commons.lang3.Validate) DefaultMapper(com.querydsl.sql.dml.DefaultMapper) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) Holder(com.evolveum.midpoint.util.Holder) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 5 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method addObject.

@Override
@NotNull
public <T extends ObjectType> String addObject(@NotNull PrismObject<T> object, RepoAddOptions options, @NotNull OperationResult result) throws ObjectAlreadyExistsException, SchemaException {
    Validate.notNull(object, "Object must not be null.");
    validateName(object);
    Validate.notNull(result, "Operation result must not be null.");
    if (options == null) {
        options = new RepoAddOptions();
    }
    LOGGER.debug("Adding object type '{}', overwrite={}, allowUnencryptedValues={}", object.getCompileTimeClass().getSimpleName(), options.isOverwrite(), options.isAllowUnencryptedValues());
    if (InternalsConfig.encryptionChecks && !RepoAddOptions.isAllowUnencryptedValues(options)) {
        CryptoUtil.checkEncrypted(object);
    }
    if (InternalsConfig.consistencyChecks) {
        object.checkConsistence(ConsistencyCheckScope.THOROUGH);
    } else {
        object.checkConsistence(ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
    }
    if (LOGGER.isTraceEnabled()) {
        // Explicitly log name
        PolyStringType namePolyType = object.asObjectable().getName();
        LOGGER.trace("NAME: {} - {}", namePolyType.getOrig(), namePolyType.getNorm());
    }
    OperationResult subResult = result.subresult(ADD_OBJECT).addQualifier(object.asObjectable().getClass().getSimpleName()).addParam("object", object).addParam("options", options.toString()).build();
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(options.isOverwrite() ? OP_ADD_OBJECT_OVERWRITE : OP_ADD_OBJECT, object.getCompileTimeClass());
    int attempt = 1;
    int restarts = 0;
    try {
        final String operation = "adding";
        String proposedOid = object.getOid();
        while (true) {
            try {
                String createdOid = objectUpdater.addObjectAttempt(object, options, subResult);
                invokeConflictWatchers((w) -> w.afterAddObject(createdOid, object));
                return createdOid;
            } catch (RestartOperationRequestedException ex) {
                // special case: we want to restart but we do not want to count these
                LOGGER.trace("Restarting because of {}", ex.getMessage());
                restarts++;
                if (restarts > RESTART_LIMIT) {
                    throw new IllegalStateException("Too many operation restarts");
                }
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(proposedOid, operation, attempt, ex, subResult);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
        OperationLogger.logAdd(object, options, subResult);
        subResult.computeStatusIfUnknown();
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SqlPerformanceMonitorImpl (com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)34 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)25 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)16 Test (org.testng.annotations.Test)16 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 QUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser)5 NotNull (org.jetbrains.annotations.NotNull)5 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)3 com.evolveum.midpoint.prism.query (com.evolveum.midpoint.prism.query)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 Collectors (java.util.stream.Collectors)3 Nullable (org.jetbrains.annotations.Nullable)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ChangeType (com.evolveum.midpoint.prism.delta.ChangeType)2