Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIKA-4190 - set autocommit to false in jdbc emitter #1576

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,17 @@ private void emitNow(List<? extends EmitData> emitData) throws SQLException {
insertAll(d.getEmitKey().getEmitKey(), d.getMetadataList());
}
}
insertStatement.executeBatch();
if (LOGGER.isDebugEnabled()) {
long start = System.currentTimeMillis();
insertStatement.executeBatch();
connection.commit();
LOGGER.debug("took {}ms to insert {} rows ", System.currentTimeMillis() - start,
emitData.size());
} else {
insertStatement.executeBatch();
connection.commit();
}

}

private void insertAll(String emitKey, List<Metadata> metadataList) throws SQLException {
Expand Down Expand Up @@ -361,6 +371,7 @@ private void tryClose() {

if (connection != null) {
try {
connection.commit();
connection.close();
} catch (SQLException e) {
LOGGER.warn("exception closing connection", e);
Expand All @@ -370,6 +381,7 @@ private void tryClose() {

private void createConnection() throws SQLException {
connection = DriverManager.getConnection(connectionString);
connection.setAutoCommit(false);
if (postConnectionString.isPresent()) {
try (Statement st = connection.createStatement()) {
st.execute(postConnectionString.get());
Expand Down