This is an automated email from the ASF dual-hosted git repository.

aengineer pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 06279ec  HDDS-946. AuditParser - insert audit to database in batches. 
contributed by Dinesh Chitlangia.
06279ec is described below

commit 06279ecc554f75bf409c5af254ca101bcbdfc2f7
Author: Anu Engineer <[email protected]>
AuthorDate: Mon Jan 7 11:19:42 2019 -0800

    HDDS-946. AuditParser - insert audit to database in batches.
    contributed by Dinesh Chitlangia.
---
 .../hadoop/ozone/audit/parser/common/DatabaseHelper.java    | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/audit/parser/common/DatabaseHelper.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/audit/parser/common/DatabaseHelper.java
index 02c27b4..c1f7275 100644
--- 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/audit/parser/common/DatabaseHelper.java
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/audit/parser/common/DatabaseHelper.java
@@ -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());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to