Merge pull request '261123_01_FIX: 리스트 업로드 DB 중복 검사 쿼리 인덱스 활용 및 타임아웃(5분) 적용, 검증 실패 시 원인 예외 보존' (#48) from develop into master
Reviewed-on: #48
This commit is contained in:
@@ -9,13 +9,17 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.jspecify.annotations.NonNull;
|
import org.jspecify.annotations.NonNull;
|
||||||
|
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
|
||||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapperResultSetExtractor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ListUploadJdbcSupport {
|
public class ListUploadJdbcSupport {
|
||||||
|
private static final int DB_DUPLICATE_QUERY_TIMEOUT_SECONDS = 300;
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
public void deleteTemp(String listUploadLogId) {
|
public void deleteTemp(String listUploadLogId) {
|
||||||
@@ -115,24 +119,31 @@ public class ListUploadJdbcSupport {
|
|||||||
and t.prjct_idx = ?
|
and t.prjct_idx = ?
|
||||||
and t.normalized_val is not null
|
and t.normalized_val is not null
|
||||||
and t.specific_type in (?, ?)
|
and t.specific_type in (?, ?)
|
||||||
and lower(trim(i.list_item_val)) = t.normalized_val
|
and i.list_item_val = t.normalized_val
|
||||||
and (? = false or i.sid <> t.sid)
|
and (? = false or i.sid <> t.sid)
|
||||||
order by t.row_no, t.list_hder_id
|
order by t.row_no, t.list_hder_id
|
||||||
""";
|
""";
|
||||||
|
|
||||||
return jdbcTemplate.query(
|
return jdbcTemplate.query(
|
||||||
sql,
|
con -> {
|
||||||
(rs, rowNum) -> new DuplicateHit(
|
PreparedStatement ps = con.prepareStatement(sql);
|
||||||
rs.getInt("row_no"),
|
// Fail fast and let the driver KILL QUERY on the server instead of waiting indefinitely.
|
||||||
rs.getString("sid"),
|
ps.setQueryTimeout(DB_DUPLICATE_QUERY_TIMEOUT_SECONDS);
|
||||||
rs.getInt("list_hder_id"),
|
return ps;
|
||||||
rs.getString("raw_val")
|
},
|
||||||
),
|
new ArgumentPreparedStatementSetter(new Object[] {
|
||||||
listUploadLogId,
|
listUploadLogId,
|
||||||
prjctIdx,
|
prjctIdx,
|
||||||
ListHeaderTypeSpecific.EMAIL.getCode(),
|
ListHeaderTypeSpecific.EMAIL.getCode(),
|
||||||
ListHeaderTypeSpecific.TEL_NUM.getCode(),
|
ListHeaderTypeSpecific.TEL_NUM.getCode(),
|
||||||
excludeSameSid
|
excludeSameSid
|
||||||
|
}),
|
||||||
|
new RowMapperResultSetExtractor<>((rs, rowNum) -> new DuplicateHit(
|
||||||
|
rs.getInt("row_no"),
|
||||||
|
rs.getString("sid"),
|
||||||
|
rs.getInt("list_hder_id"),
|
||||||
|
rs.getString("raw_val")
|
||||||
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -428,6 +428,7 @@ public class ListUploadService {
|
|||||||
if (request.uploadMode() == null) {
|
if (request.uploadMode() == null) {
|
||||||
throw BusinessException.badRequest("ASYNC_UPLOAD_MODE_REQUIRED", "Upload mode is required");
|
throw BusinessException.badRequest("ASYNC_UPLOAD_MODE_REQUIRED", "Upload mode is required");
|
||||||
}
|
}
|
||||||
|
RuntimeException primaryFailure = null;
|
||||||
try {
|
try {
|
||||||
checkCancelled.run();
|
checkCancelled.run();
|
||||||
var errors = new ArrayList<ListUploadErrorDto>();
|
var errors = new ArrayList<ListUploadErrorDto>();
|
||||||
@@ -459,11 +460,18 @@ public class ListUploadService {
|
|||||||
return new PreparedUpload(validation.totalCount(), Set.copyOf(validation.uploadedSids()),
|
return new PreparedUpload(validation.totalCount(), Set.copyOf(validation.uploadedSids()),
|
||||||
List.copyOf(headers), Map.copyOf(companies), createHeaders, List.copyOf(validation.errors()));
|
List.copyOf(headers), Map.copyOf(companies), createHeaders, List.copyOf(validation.errors()));
|
||||||
} catch (RuntimeException failure) {
|
} catch (RuntimeException failure) {
|
||||||
|
primaryFailure = failure;
|
||||||
checkCancelled.run();
|
checkCancelled.run();
|
||||||
throw failure;
|
throw failure;
|
||||||
} finally {
|
} finally {
|
||||||
// All validation staging is in this transaction; a restart also rolls it back.
|
// All validation staging is in this transaction; a restart also rolls it back.
|
||||||
|
try {
|
||||||
listUploadJdbcSupport.deleteTemp(logId);
|
listUploadJdbcSupport.deleteTemp(logId);
|
||||||
|
} catch (RuntimeException cleanupFailure) {
|
||||||
|
// Keep the original failure (e.g. a broken connection) instead of masking it with the cleanup failure.
|
||||||
|
if (primaryFailure == null) throw cleanupFailure;
|
||||||
|
primaryFailure.addSuppressed(cleanupFailure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user