Skip to content

Commit

Permalink
Centralize logging in TransportTools
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Chrzan <[email protected]>
Signed-off-by: mchrza <[email protected]>
  • Loading branch information
mchrza committed Sep 25, 2024
1 parent 9fa4f5d commit 364e43a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
import java.util.UUID;

import static com.here.xyz.events.ContextAwareEvent.SpaceContext.EXTENSION;
import static com.here.xyz.jobs.steps.impl.transport.TransportTools.Phase.STEP_ON_ASYNC_SUCCESS;
import static com.here.xyz.jobs.steps.impl.transport.TransportTools.buildDropTemporaryTableQuery;
import static com.here.xyz.jobs.steps.impl.transport.TransportTools.getTemporaryJobTableName;
import static com.here.xyz.jobs.steps.impl.transport.TransportTools.Phase.STEP_EXECUTE;
import static com.here.xyz.util.web.XyzWebClient.WebClientException;

/**
* This step imports a set of user provided inputs and imports their data into a specified space.
* This step produces exactly one output of type {@link FeatureStatistics}.
*/
public class ExportSpaceToFiles extends SpaceBasedStep<ExportSpaceToFiles> {
private static final Logger logger = LogManager.getLogger();

//Defines how many features a source layer need to have to start parallelization.
//Defines how many features a source layer need to have to start parallelization.
private final int PARALLELIZTATION_MIN_THRESHOLD = 10; //TODO: put back to 500k
//Defines how many export threads are getting used
private final int PARALLELIZTATION_THREAD_COUNT = 8;
Expand Down Expand Up @@ -130,7 +130,7 @@ public ExecutionMode getExecutionMode() {
public boolean validate() throws ValidationException {
super.validate();
try {
logger.info("VALIDATE");

loadSpace(getSpaceId());

/**
Expand All @@ -157,7 +157,7 @@ public void execute() throws Exception {
runWriteQuerySync(buildTemporaryTableForExportQuery(getSchema(db())), db(), 0);

for (int i = 0; i < calculatedThreadCount; i++) {
logger.info("Start export thread number: {}", i);
infoLog(STEP_EXECUTE, "Start export thread number: " + i );
runReadQueryAsync(buildExportQuery(i), db(), 0);
}
}
Expand All @@ -172,7 +172,7 @@ protected void onAsyncSuccess() throws Exception {
//TODO
super.onAsyncSuccess();

logger.info("Clean Temp Table!");
infoLog(STEP_ON_ASYNC_SUCCESS, "Cleanup temporary table");
runWriteQuerySync(buildDropTemporaryTableQuery(getSchema(db()), getTemporaryJobTableName(this)), db(), 0);
}

Expand Down Expand Up @@ -234,4 +234,8 @@ PERFORM export_to_s3_perform(
.withNamedParameter("format", format.name())
.withNamedParameter("filesize", 0);
}

private void infoLog(TransportTools.Phase phase, String... messages){
TransportTools.infoLog(phase.name(), getSpaceId(), getGlobalStepId(), messages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.jts.io.ParseException;


Expand All @@ -78,7 +76,6 @@
*/
public class ImportFilesToSpace extends SpaceBasedStep<ImportFilesToSpace> {

private static final Logger logger = LogManager.getLogger();
private static final long MAX_INPUT_BYTES_FOR_NON_EMPTY_IMPORT = 10 * 1024 * 1024 * 1024l;
private static final long MAX_INPUT_BYTES_FOR_SYNC_IMPORT = 100 * 1024 * 1024;
private static final long MAX_INPUT_BYTES_FOR_KEEP_INDICES = 1 * 1024 * 1024 * 1024;
Expand Down Expand Up @@ -403,7 +400,7 @@ protected void onStateCheck() {
}
catch (Exception e) {
//TODO: What to do? Only log? Report Status is not that important. Further Ignore "table does not exists error" - report 0 in this case.
logger.error(e);
errorLog(STEP_ON_STATE_CHECK, e);
}
}

Expand Down Expand Up @@ -432,7 +429,7 @@ protected void onAsyncSuccess() throws WebClientException,
//relation "*_job_data" does not exist - can happen when we have received twice a SUCCESS_CALLBACK
//TODO: Find out the cases in which that could happen and prevent it from happening
if (e.getSQLState() != null && e.getSQLState().equals("42P01")) {
errorLog(STEP_ON_ASYNC_SUCCESS, "_job_data table got already deleted!", e);
errorLog(STEP_ON_ASYNC_SUCCESS, e, "_job_data table got already deleted!");
return;
}
throw e;
Expand Down Expand Up @@ -759,8 +756,8 @@ private void infoLog(Phase phase, String... messages){
TransportTools.infoLog(phase.name(), getSpaceId(), getGlobalStepId(), messages);
}

private void errorLog(Phase phase, String message, Exception e){
TransportTools.errorLog(phase.name(), getSpaceId(), getGlobalStepId(), message, e);
private void errorLog(Phase phase, Exception e, String... messages){
TransportTools.errorLog(phase.name(), getSpaceId(), getGlobalStepId(), e, messages);
}

//TODO: De-duplicate once CSV was removed (see GeoJson format class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected static void infoLog(String phase, String spaceId, String getGlobalStep
logger.info("[{}@{}] ON '{}' {}", getGlobalStepId, phase, spaceId, messages.length > 0 ? messages : "");
}

protected static void errorLog(String phase, String spaceId, String getGlobalStepId, String message, Exception e) {
protected static void errorLog(String phase, String spaceId, String getGlobalStepId, Exception e, String... message) {
logger.error("[{}@{}] ON '{}' {}", getGlobalStepId, phase, spaceId, message, e);
}

Expand Down

0 comments on commit 364e43a

Please sign in to comment.