From 021d5c743b39900504ce58fb0b18d9b89e54904c Mon Sep 17 00:00:00 2001 From: Deklan Dieterly Date: Tue, 4 Mar 2014 16:24:13 -0700 Subject: [PATCH] Add truncate after dedupe. --- src/main/java/com/hpcloud/MonDeDuper.java | 32 +++++++++++++++---- .../com/hpcloud/mon-persister-config.yml | 3 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hpcloud/MonDeDuper.java b/src/main/java/com/hpcloud/MonDeDuper.java index 3d505f38..22817bd0 100644 --- a/src/main/java/com/hpcloud/MonDeDuper.java +++ b/src/main/java/com/hpcloud/MonDeDuper.java @@ -8,6 +8,8 @@ import org.skife.jdbi.v2.Handle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.SQLException; + public class MonDeDuper implements Managed { private static Logger logger = LoggerFactory.getLogger(MonDeDuper.class); @@ -51,17 +53,23 @@ public class MonDeDuper implements Managed { private static final String DEDEUP_STAGING_DIMS = "insert into MonMetrics.Dimensions select distinct * from MonMetrics.StagedDimensions where metric_definition_id not in (select metric_definition_id from MonMetrics.Dimensions)"; - private static final String DROP_PARTITION_STAGING_DEFS = - "select drop partition('monmetrics.stageddefinitions', )"; + private static final String TRUNCATE_STAGING_DEFS = + "truncate table monmetrics.stageddefinitions"; - private static final String DROP_PARTITION_STAGING_DIMS = - "select drop partition('monmetrics.stageddimensions', )"; + private static final String TRUNCATE_STAGING_DIMS = + "truncate table monmetrics.stageddimensions"; private DeDuperRunnable(MonPersisterConfiguration configuration, DBI dbi) { this.configuration = configuration; this.dbi = dbi; this.handle = this.dbi.open(); this.handle.execute("SET TIME ZONE TO 'UTC'"); + try { + this.handle.getConnection().setAutoCommit(false); + } catch (SQLException e) { + logger.error("Failed to set autocommit to false", e); + System.exit(-1); + } } @@ -71,13 +79,25 @@ public class MonDeDuper implements Managed { for (; ; ) { try { Thread.sleep(seconds * 1000); + handle.begin(); logger.debug("Waited " + seconds + " seconds"); - logger.debug("Executing:" + DEDUPE_STAGING_DEFS); + logger.debug("Executing: " + DEDUPE_STAGING_DEFS); handle.execute(DEDUPE_STAGING_DEFS); - logger.debug("Executing:" + DEDEUP_STAGING_DIMS); + logger.debug("Executing: " + TRUNCATE_STAGING_DEFS); + handle.execute(TRUNCATE_STAGING_DEFS); + + handle.commit(); + + handle.begin(); + logger.debug("Executing: " + DEDEUP_STAGING_DIMS); handle.execute(DEDEUP_STAGING_DIMS); + + logger.debug("Executing: " + TRUNCATE_STAGING_DIMS); + handle.execute(TRUNCATE_STAGING_DIMS); + handle.commit(); + } catch (InterruptedException e) { logger.warn("Failed to wait for " + seconds + " between deduping", e); } diff --git a/src/main/resources/com/hpcloud/mon-persister-config.yml b/src/main/resources/com/hpcloud/mon-persister-config.yml index efc9f19f..ef641e9a 100644 --- a/src/main/resources/com/hpcloud/mon-persister-config.yml +++ b/src/main/resources/com/hpcloud/mon-persister-config.yml @@ -41,7 +41,8 @@ databaseConfiguration: # url: jdbc:vertica://mon-aw1rdd1-vertica0001.rndd.aw1.hpcloud.net:5433/som url: jdbc:vertica://15.185.94.245:5433/som # user: persister - user: mon_persister +# user: mon_persister + user: dbadmin password: password properties: ssl: false