HDDS-946. AuditParser - insert audit to database in batches.

contributed by Dinesh Chitlangia.
This commit is contained in:
Anu Engineer 2019-01-07 11:19:42 -08:00
parent cdfbec47ce
commit 06279ecc55
1 changed files with 12 additions and 1 deletions

View File

@ -109,6 +109,10 @@ public final class DatabaseHelper {
properties.get(ParserConsts.INSERT_AUDITS))) {
ArrayList<AuditEntry> auditEntries = parseAuditLogs(logs);
final int batchSize = 1000;
int count = 0;
//Insert list to db
for(AuditEntry audit : auditEntries) {
preparedStatement.setString(1, audit.getTimestamp());
@ -121,7 +125,14 @@ public final class DatabaseHelper {
preparedStatement.setString(8, audit.getResult());
preparedStatement.setString(9, audit.getException());
preparedStatement.executeUpdate();
preparedStatement.addBatch();
if(++count % batchSize == 0) {
preparedStatement.executeBatch();
}
}
if(auditEntries.size() > 0) {
preparedStatement.executeBatch(); // insert remaining records
}
} catch (Exception e) {
LOG.error(e.getMessage());