aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject aurora git commit: DB cron job store: allow upsert.
Date Thu, 09 Jul 2015 20:53:43 GMT
Repository: aurora
Updated Branches:
  refs/heads/master e996ca522 -> b472af8c0


DB cron job store: allow upsert.

Bugs closed: AURORA-1390

Reviewed at https://reviews.apache.org/r/36367/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/b472af8c
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/b472af8c
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/b472af8c

Branch: refs/heads/master
Commit: b472af8c0f7adf825155090c8a95bf581f99bf46
Parents: e996ca5
Author: Bill Farner <wfarner@apache.org>
Authored: Thu Jul 9 13:53:23 2015 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Thu Jul 9 13:53:23 2015 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/storage/db/CronJobMapper.java      |  2 +-
 .../aurora/scheduler/storage/db/DbCronJobStore.java     |  2 +-
 .../aurora/scheduler/storage/db/CronJobMapper.xml       |  6 +++---
 .../scheduler/storage/AbstractCronJobStoreTest.java     | 12 ++++++++++++
 4 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/b472af8c/src/main/java/org/apache/aurora/scheduler/storage/db/CronJobMapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/CronJobMapper.java b/src/main/java/org/apache/aurora/scheduler/storage/db/CronJobMapper.java
index a272785..a5c6e99 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/CronJobMapper.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/CronJobMapper.java
@@ -27,7 +27,7 @@ import org.apache.ibatis.annotations.Param;
  */
 interface CronJobMapper {
 
-  void insert(@Param("job") IJobConfiguration job, @Param("task_config_id") long taskConfigId);
+  void merge(@Param("job") IJobConfiguration job, @Param("task_config_id") long taskConfigId);
 
   void delete(@Param("job") IJobKey job);
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/b472af8c/src/main/java/org/apache/aurora/scheduler/storage/db/DbCronJobStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbCronJobStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbCronJobStore.java
index c2696a9..c1237b7 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbCronJobStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbCronJobStore.java
@@ -51,7 +51,7 @@ class DbCronJobStore implements CronJobStore.Mutable {
   public void saveAcceptedJob(IJobConfiguration jobConfig) {
     requireNonNull(jobConfig);
     jobKeyMapper.merge(jobConfig.getKey());
-    cronJobMapper.insert(jobConfig, taskConfigManager.insert(jobConfig.getTaskConfig()));
+    cronJobMapper.merge(jobConfig, taskConfigManager.insert(jobConfig.getTaskConfig()));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/aurora/blob/b472af8c/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml
index 936c2b8..3826d9f 100644
--- a/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml
@@ -18,8 +18,8 @@
     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.apache.aurora.scheduler.storage.db.CronJobMapper">
 
-  <insert id="insert">
-    INSERT INTO cron_jobs(
+  <insert id="merge">
+    MERGE INTO cron_jobs(
       job_key_id,
       creator_user,
       cron_schedule,
@@ -28,7 +28,7 @@
       </if>
       task_config_row_id,
       instance_count
-    ) VALUES (
+    ) KEY(job_key_id) VALUES (
       (
         SELECT ID
         FROM job_keys

http://git-wip-us.apache.org/repos/asf/aurora/blob/b472af8c/src/test/java/org/apache/aurora/scheduler/storage/AbstractCronJobStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/AbstractCronJobStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/AbstractCronJobStoreTest.java
index 6b9eb34..8d9792f 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/AbstractCronJobStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/AbstractCronJobStoreTest.java
@@ -102,6 +102,18 @@ public abstract class AbstractCronJobStoreTest {
     assertEquals(staging, fetchJob(staging.getKey()).orNull());
   }
 
+  @Test
+  public void testUpdate() {
+    // Test for regression of AURORA-1390.  Updates are not normal, but are used in cases
such as
+    // backfilling fields upon storage recovery.
+
+    saveAcceptedJob(JOB_A);
+    IJobConfiguration jobAUpdated =
+        IJobConfiguration.build(JOB_A.newBuilder().setCronSchedule("changed"));
+    saveAcceptedJob(jobAUpdated);
+    assertEquals(jobAUpdated, fetchJob(KEY_A).orNull());
+  }
+
   private static IJobConfiguration makeJob(String name) {
     IJobKey job = JobKeys.from("role-" + name, "env-" + name, name);
     ITaskConfig config = TaskTestUtil.makeConfig(job);


Mime
View raw message