Skip to content

Commit

Permalink
feat: performance problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Nov 22, 2024
1 parent d7c5501 commit 54b31f1
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 42 deletions.
2 changes: 1 addition & 1 deletion arc-batch/src/main/java/fr/insee/arc/batch/BatchARC.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ private void startMaintenanceThread() {
@Override
public void run() {
try {
DatabaseMaintenance.maintenancePgCatalogAllNods(null, FormatSQL.VACUUM_OPTION_NONE);
DatabaseMaintenance.maintenancePgCatalogAllNods(null, FormatSQL.VACUUM_OPTION_FREEZE);
DatabaseMaintenance.maintenancePilotage(null, envExecution, FormatSQL.VACUUM_OPTION_NONE);
} catch (ArcException e) {
e.logMessageException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void executer() throws ArcException {
// Met en cohérence les tables de données avec la table de pilotage de
// l'environnement
// La table de pilotage fait foi
new SynchronizeDataByPilotageOperation(this.coordinatorSandbox).synchronizeDataByPilotage();
new SynchronizeDataByPilotageOperation(this.coordinatorSandbox).synchronizeDataByPilotage(true);

// remettre les archives ou elle doivent etre en cas de restauration de la base
new RestoreFileSystem(this.coordinatorSandbox).execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void resetBAS(String env, String rootDirectory) {
new ResetEnvironmentOperation(service.getCoordinatorSandbox()).clearPilotageAndDirectories(rootDirectory);

// synchronize
new SynchronizeDataByPilotageOperation(service.getCoordinatorSandbox()).synchronizeDataByPilotage();
new SynchronizeDataByPilotageOperation(service.getCoordinatorSandbox()).synchronizeDataByPilotage(false);

} catch (ArcException e) {
e.logFullException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SynchronizeDataByPilotageOperation(Sandbox sandbox) {
* @param envExecution
* @throws ArcException
*/
public void synchronizeDataByPilotage() throws ArcException {
public void synchronizeDataByPilotage(boolean fullRebuild) throws ArcException {
LoggerHelper.info(LOGGER, "synchronisationEnvironmentByPilotage");

// maintenance de la table de pilotage
Expand All @@ -54,7 +54,7 @@ public void synchronizeDataByPilotage() throws ArcException {
resetEtapePilotage();

// recrée la table de pilotage, ses index, son trigger
rebuildPilotage();
rebuildPilotage(fullRebuild);

// drop des tables temporaires de travail
dropUnusedTemporaryTablesAllNods();
Expand Down Expand Up @@ -88,8 +88,8 @@ private void resetEtapePilotage() throws ArcException {



private void rebuildPilotage() throws ArcException {
SynchronizeDataByPilotageDao.rebuildPilotageDao(this.sandbox.getConnection(), this.sandbox.getSchema());
private void rebuildPilotage(boolean fullRebuild) throws ArcException {
SynchronizeDataByPilotageDao.rebuildPilotageDao(this.sandbox.getConnection(), this.sandbox.getSchema(), fullRebuild);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ public static void resetEtapePilotageDao(Connection connection, String envExecut
* @param envExecution
* @throws ArcException
*/
public static void rebuildPilotageDao(Connection connexion, String envExecution) throws ArcException {
public static void rebuildPilotageDao(Connection connexion, String envExecution, boolean fullRebuild) throws ArcException {

String tablePilotage = ViewEnum.PILOTAGE_FICHIER.getFullName(envExecution);

UtilitaireDao.get(0).executeRequest(connexion, new ArcPreparedStatementBuilder("analyze " + tablePilotage + ";"));

UtilitaireDao.get(0).executeImmediate(connexion, FormatSQL.vacuumSecured(tablePilotage, fullRebuild?FormatSQL.VACUUM_OPTION_FULL:FormatSQL.VACUUM_OPTION_NONE));

UtilitaireDao.get(0).executeImmediate(connexion, FormatSQL.analyzeSecured(tablePilotage));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void retourPhasePrecedente(TraitementPhase phase, List<String> querySelec
nbLignes += resetEnvironmentDao.executeDeletePhaseEntriesInPilotageAndCount(phase, querySelection);

// Run a database synchronization with the pilotage table
new SynchronizeDataByPilotageOperation(this.sandbox).synchronizeDataByPilotage();
new SynchronizeDataByPilotageOperation(this.sandbox).synchronizeDataByPilotage(false);

if (nbLignes > 0) {
DatabaseMaintenance.maintenanceDatabaseClassic(connection, envExecution);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ public void calculeNormeAndValiditeFichiers(InputStream file, FileIdCard normeOk
if (normeOk.getIdNorme()==null) {
throw new ArcException(ArcExceptionMessage.LOAD_NORM_NOT_FOUND, normeOk.getIdSource());
}

if (estHorsCalendrier(normeOk, envExecution)) {
throw new ArcException(ArcExceptionMessage.LOAD_NORM_OUT_OF_CALENDAR, normeOk.getIdNorme(), normeOk.getIdSource());
}


}

/** Retourne (par référence) la norme dans normeOk[0] et la validité dans validiteOk[0].
Expand Down Expand Up @@ -177,32 +173,6 @@ private void calculerNormeAndValidite(FileIdCard normeOk, String requeteFichier)

}

/** Retourne VRAI si la date de validité du fichier est hors de la période de validité de la norme du fichier.
* Retourne FAUX sinon.
* @param normeOk les métadonnées du fichier à vérifier
* @param envExecution le schéma d'exécution du traitement
* @throws ArcException si aucune norme ou plus d'une norme trouvée
*/
private boolean estHorsCalendrier(FileIdCard normeOk, String envExecution) throws ArcException {
ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder();
query.build(SQL.SELECT, ColumnEnum.VALIDITE_INF.getColumnName(), ",");
query.build(ColumnEnum.VALIDITE_SUP.getColumnName(), SQL.FROM, ViewEnum.CALENDRIER.getFullName(envExecution));
query.build(SQL.WHERE, ColumnEnum.ID_NORME.getColumnName(), "=", query.quoteText(normeOk.getIdNorme()));

List<List<String>> result = UtilitaireDao.get(0).executeRequestWithoutMetadata(this.connexion, query);

if (result.size() > 1) {
throw new ArcException(ArcExceptionMessage.LOAD_SEVERAL_NORM_FOUND, normeOk.getIdNorme());
} else if (result.isEmpty()) {
throw new ArcException(ArcExceptionMessage.LOAD_ZERO_NORM_FOUND);
}

String validite_inf = result.get(0).get(0);
String validite_sup = result.get(0).get(1);
String validite = normeOk.getValidite();
return (validite.compareTo(validite_inf) < 0) || (validite.compareTo(validite_sup) > 0);

}

/**
* @return the connexion
Expand Down
2 changes: 2 additions & 0 deletions arc-utils/src/main/java/fr/insee/arc/utils/dao/SQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public enum SQL {
SELECT("SELECT"), FROM("FROM"), WHERE("WHERE"), ORDER_BY("ORDER BY"), DISTINCT("DISTINCT"),

DESC("desc"), ASC("asc"),

AS("AS"),

VACUUM("VACUUM"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private FormatSQL() {
public static final int TIMEOUT_MAINTENANCE = 600000;

public static final String VACUUM_OPTION_NONE = "";
public static final String VACUUM_OPTION_FREEZE = "freeze";
public static final String VACUUM_OPTION_FULL = "full";
public static final String VACUUM_OPTION_ANALYZE = "analyze";

Expand Down

0 comments on commit 54b31f1

Please sign in to comment.