use of sirius.kernel.commons.Watch in project sirius-db by scireum.
the class Finder method processCursor.
private void processCursor(MongoIterable<Document> cursor, Predicate<Doc> processor, String collection) {
Watch watch = Watch.start();
TaskContext taskContext = TaskContext.get();
Monoflop shouldHandleTracing = Monoflop.create();
for (Document doc : cursor) {
if (shouldHandleTracing.firstCall()) {
handleTracingAndReporting(collection, watch);
}
boolean keepGoing = processor.test(new Doc(doc));
if (!keepGoing || !taskContext.isActive()) {
return;
}
}
// the Microtiming...
if (shouldHandleTracing.firstCall()) {
handleTracingAndReporting(collection, watch);
}
}
use of sirius.kernel.commons.Watch in project sirius-db by scireum.
the class Updater method execute.
private UpdateResult execute(String collection, boolean forMany) {
Document updateObject = prepareUpdate(collection);
Watch w = Watch.start();
try {
if (Mongo.LOG.isFINE()) {
Mongo.LOG.FINE("UPDATE: %s\nFilter: %s\n Update:%s", collection, filterObject, updateObject);
}
UpdateOptions updateOptions = new UpdateOptions().upsert(this.upsert);
if (forMany) {
return mongo.db(database).getCollection(collection).updateMany(filterObject, updateObject, updateOptions);
} else {
return mongo.db(database).getCollection(collection).updateOne(filterObject, updateObject, updateOptions);
}
} finally {
mongo.callDuration.addValue(w.elapsedMillis());
if (Microtiming.isEnabled()) {
w.submitMicroTiming("mongo", "UPDATE - " + collection + ": " + filterObject.keySet());
}
traceIfRequired(collection, w);
}
}
use of sirius.kernel.commons.Watch in project sirius-db by scireum.
the class RequestBuilder method tryExecute.
protected RequestBuilder tryExecute(String uri) throws OptimisticLockException {
Watch w = Watch.start();
try (Operation op = new Operation(() -> Strings.apply("Elastic: %s %s", method, uri), Duration.ofSeconds(30))) {
Request request = setupRequest(uri);
responseEntity = restClient.performRequest(request).getEntity();
return this;
} catch (ResponseException e) {
return handleResponseException(e);
} catch (IOException e) {
throw Exceptions.handle().to(Elastic.LOG).error(e).withSystemErrorMessage("An IO exception occurred when performing a request against elasticsearch: %s").handle();
} finally {
elastic.callDuration.addValue(w.elapsedMillis());
if (Microtiming.isEnabled()) {
w.submitMicroTiming("ELASTIC", method + ": " + uri);
}
if (w.elapsedMillis() > Elastic.getLogQueryThresholdMillis()) {
elastic.numSlowQueries.inc();
DB.SLOW_DB_LOG.INFO("A slow Elasticsearch query was executed (%s): %s\n%s\n%s", w.duration(), method + ": " + uri, Strings.limit(buildContent().orElse("no content"), MAX_CONTENT_LONG_LENGTH), ExecutionPoint.snapshot().toString());
}
}
}
use of sirius.kernel.commons.Watch in project sirius-db by scireum.
the class BatchSQLQuery method iterate.
@Override
public void iterate(Predicate<Row> handler, @Nullable Limit limit) throws SQLException {
Watch w = Watch.start();
try (ResultSet rs = query.prepareStmt().executeQuery()) {
query.avarage.addValue(w.elapsedMillis());
TaskContext tc = TaskContext.get();
processResultSet(handler, limit, rs, tc);
}
}
use of sirius.kernel.commons.Watch in project sirius-db by scireum.
the class DeleteQuery method delete.
/**
* Deletes all entities where the compared mappings match the ones given in the <tt>example</tt>.
*
* @param example the example entity used to determine which other entities to delete
* @param invokeChecks <tt>true</tt> to signal that before- and after delete checks should be executed,
* <tt>false</tt> otherwise
* @param addBatch determines if the query should be executed instantly (<tt>false</tt>) or added to the
* batch update (<tt>true</tt>).
*/
@SuppressWarnings("unchecked")
public void delete(@Nonnull E example, boolean invokeChecks, boolean addBatch) {
try {
if (example.isNew()) {
return;
}
if (this.type == null) {
this.type = (Class<E>) example.getClass();
}
Watch w = Watch.start();
if (invokeChecks) {
getDescriptor().beforeDelete(example);
}
PreparedStatement stmt = prepareStmt();
int i = 1;
for (Tuple<Operator, Property> filter : getPropertyFilters()) {
stmt.setObject(i++, filter.getSecond().getValueForDatasource(OMA.class, example));
}
if (descriptor.isVersioned()) {
if (example.getVersion() == 0) {
throw Exceptions.handle().to(OMA.LOG).withSystemErrorMessage("Cannot execute a DeleteQuery for the versioned entity %s without a version!", descriptor.getType()).handle();
}
stmt.setObject(i, example.getVersion());
}
if (addBatch) {
addBatch();
} else {
stmt.executeUpdate();
stmt.getConnection().commit();
avarage.addValue(w.elapsedMillis());
}
if (invokeChecks) {
getDescriptor().afterDelete(example);
}
} catch (SQLException e) {
context.safeClose();
throw Exceptions.handle().to(OMA.LOG).error(e).withSystemErrorMessage("A database error occurred while executing a DeleteQuery for %s: %s (%s)", type.getName()).handle();
} catch (Exception e) {
throw Exceptions.handle().to(OMA.LOG).error(e).withSystemErrorMessage("An error occurred while executing a DeleteQuery for %s: %s (%s)", type.getName()).handle();
}
}
Aggregations