*/
package org.sonar.server.db.migrations;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.core.persistence.Database;
+import org.sonar.server.util.ProgressTask;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Timer;
-import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicLong;
public class MassUpdate {
private final Database db;
private final Connection readConnection, writeConnection;
private final AtomicLong counter = new AtomicLong(0L);
- private final ProgressTask progressTask = new ProgressTask(counter);
+ private final ProgressTask progressTask = new ProgressTask(counter, LoggerFactory.getLogger("DbMigration"));
private Select select;
private Upsert update;
}
}
- public static class ProgressTask extends TimerTask {
- private static final Logger LOGGER = LoggerFactory.getLogger("DbMigration");
- public static final long PERIOD_MS = 60000L;
- private final AtomicLong counter;
- private String rowName = "rows";
-
- public ProgressTask(AtomicLong counter) {
- this.counter = counter;
- }
-
- void setRowPluralName(String s) {
- this.rowName = s;
- }
-
- @Override
- public void run() {
- log();
- }
-
- public void log() {
- LOGGER.info(String.format("%d %s processed", counter.get(), rowName));
- }
- }
-
}
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
+
+import org.slf4j.LoggerFactory;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.migration.v45.Migration45Mapper;
import org.sonar.core.persistence.migration.v45.RuleParameter;
import org.sonar.server.db.DbClient;
import org.sonar.server.db.migrations.DatabaseMigration;
-import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.util.ProgressTask;
import javax.annotation.Nullable;
private final System2 system;
private final AtomicLong counter = new AtomicLong(0L);
- private final MassUpdate.ProgressTask progressTask = new MassUpdate.ProgressTask(counter);
+ private final ProgressTask progressTask = new ProgressTask(counter, LoggerFactory.getLogger("DbMigration"));
public AddMissingCustomRuleParametersMigration(DbClient db, System2 system) {
this.db = db;
@Override
public void execute() {
Timer timer = new Timer("Db Migration Progress");
- timer.schedule(progressTask, MassUpdate.ProgressTask.PERIOD_MS, MassUpdate.ProgressTask.PERIOD_MS);
+ timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS);
DbSession session = db.openSession(false);
try {
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
+
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
+import org.slf4j.LoggerFactory;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.internal.Uuids;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.migration.v50.Migration50Mapper;
import org.sonar.server.db.DbClient;
import org.sonar.server.db.migrations.DatabaseMigration;
-import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.util.ProgressTask;
import java.util.List;
import java.util.Map;
private final DbClient db;
private final AtomicLong counter = new AtomicLong(0L);
- private final MassUpdate.ProgressTask progressTask = new MassUpdate.ProgressTask(counter);
+ private final ProgressTask progressTask = new ProgressTask(counter, LoggerFactory.getLogger("DbMigration"));
public PopulateProjectsUuidColumnsMigration(DbClient db) {
this.db = db;
@Override
public void execute() {
Timer timer = new Timer("Db Migration Progress");
- timer.schedule(progressTask, MassUpdate.ProgressTask.PERIOD_MS, MassUpdate.ProgressTask.PERIOD_MS);
+ timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS);
final DbSession readSession = db.openSession(false);
final DbSession writeSession = db.openSession(true);
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
+
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.picocontainer.Startable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.server.util.ProgressTask;
import java.util.Map;
+import java.util.Timer;
+import java.util.concurrent.atomic.AtomicLong;
/**
* Helper to bulk requests in an efficient way :
private BulkRequestBuilder bulkRequest = null;
private Map<String, Object> largeInitialSettings = null;
+ private final AtomicLong counter = new AtomicLong(0L);
+ private final ProgressTask progressTask = new ProgressTask(counter, LoggerFactory.getLogger("BulkIndex")).setRowPluralName("requests");
+ private final Timer timer = new Timer("Bulk index progress");
+
public BulkIndexer(EsClient client, String indexName) {
this.client = client;
this.indexName = indexName;
updateSettings(bulkSettings);
}
bulkRequest = client.prepareBulk();
+ timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS);
}
public void add(ActionRequest request) {
bulkRequest.request().add(request);
+ counter.getAndIncrement();
if (bulkRequest.request().estimatedSizeInBytes() >= flushByteSize) {
executeBulk(bulkRequest);
bulkRequest = client.prepareBulk();
if (bulkRequest.numberOfActions() > 0) {
executeBulk(bulkRequest);
}
+
+ // Log final advancement and reset counter
+ progressTask.log();
+ counter.set(0L);
+ timer.cancel();
+ timer.purge();
+
if (refresh) {
client.prepareRefresh(indexName).get();
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.util;
+
+import java.util.TimerTask;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProgressTask extends TimerTask {
+ private final Logger logger;
+ public static final long PERIOD_MS = 60000L;
+ private final AtomicLong counter;
+ private String rowName = "rows";
+
+ public ProgressTask(AtomicLong counter, Logger logger) {
+ this.counter = counter;
+ this.logger = logger;
+ }
+
+ public ProgressTask setRowPluralName(String s) {
+ this.rowName = s;
+ return this;
+ }
+
+ @Override
+ public void run() {
+ log();
+ }
+
+ public void log() {
+ logger.info(String.format("%d %s processed", counter.get(), rowName));
+ }
+}