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;
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations