aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject git commit: Improve performance of fetching host attributes.
Date Fri, 19 Sep 2014 19:01:22 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 1fd13473c -> 54f7bede4


Improve performance of fetching host attributes.

Bugs closed: AURORA-730

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


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

Branch: refs/heads/master
Commit: 54f7bede4357c4500a4f985b5268974a522f5340
Parents: 1fd1347
Author: Bill Farner <wfarner@apache.org>
Authored: Fri Sep 19 11:58:04 2014 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Fri Sep 19 11:58:04 2014 -0700

----------------------------------------------------------------------
 .../scheduler/storage/db/DbAttributeStore.java    | 18 +++++++++++++++++-
 .../scheduler/storage/db/AttributeMapper.xml      |  1 +
 .../storage/db/DbAttributeStoreTest.java          |  1 +
 3 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/54f7bede/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
index 1b18ad5..c8b3095 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
@@ -29,6 +29,8 @@ import org.apache.aurora.scheduler.storage.AttributeStore;
 import org.apache.aurora.scheduler.storage.entities.IAttribute;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
 
+import static com.twitter.common.inject.TimedInterceptor.Timed;
+
 /**
  * Attribute store backed by a relational database.
  */
@@ -46,6 +48,7 @@ class DbAttributeStore implements AttributeStore.Mutable {
     mapper.truncate();
   }
 
+  @Timed("attribute_store_save")
   @Override
   public void saveHostAttributes(IHostAttributes hostAttributes) {
     HostAttributes mutableAttributes = hostAttributes.newBuilder();
@@ -61,11 +64,21 @@ class DbAttributeStore implements AttributeStore.Mutable {
 
     // If this is an 'upsert', don't overwrite the previously-set maintenance mode.
     Optional<IHostAttributes> existing = getHostAttributes(hostAttributes.getHost());
+    IHostAttributes toSave;
     if (existing.isPresent()) {
       mutableAttributes.setMode(existing.get().getMode());
+
+      toSave = IHostAttributes.build(mutableAttributes);
+
+      // Avoid inserting again if this is a no-op update.
+      if (existing.get().equals(toSave)) {
+        return;
+      }
+    } else {
+      toSave = IHostAttributes.build(mutableAttributes);
     }
 
-    merge(IHostAttributes.build(mutableAttributes));
+    merge(toSave);
   }
 
   private static final Predicate<IAttribute> EMPTY_VALUES = new Predicate<IAttribute>()
{
@@ -88,6 +101,7 @@ class DbAttributeStore implements AttributeStore.Mutable {
     }
   }
 
+  @Timed("attribute_store_set_mode")
   @Override
   public boolean setMaintenanceMode(String host, MaintenanceMode mode) {
     Optional<IHostAttributes> existing = getHostAttributes(host);
@@ -99,11 +113,13 @@ class DbAttributeStore implements AttributeStore.Mutable {
     }
   }
 
+  @Timed("attribute_store_fetch_one")
   @Override
   public Optional<IHostAttributes> getHostAttributes(String host) {
     return Optional.fromNullable(mapper.select(host)).transform(IHostAttributes.FROM_BUILDER);
   }
 
+  @Timed("attribute_store_fetch_all")
   @Override
   public Set<IHostAttributes> getHostAttributes() {
     return IHostAttributes.setFromBuilders(mapper.selectAll());

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/54f7bede/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml
b/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml
index 53017c8..d36b42a 100644
--- a/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml
@@ -3,6 +3,7 @@
     PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.apache.aurora.scheduler.storage.db.AttributeMapper">
+  <cache size="50000" readOnly="true" />
   <insert id="insert">
     INSERT INTO host_attributes (
       host,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/54f7bede/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
index 4a31999..c0a1aa5 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
@@ -71,6 +71,7 @@ public class DbAttributeStoreTest {
     assertEquals(ImmutableSet.of(HOST_A_ATTRS), readAll());
 
     insert(HOST_B_ATTRS);
+    insert(HOST_B_ATTRS);  // Double insert should be allowed.
     assertEquals(Optional.of(HOST_B_ATTRS), read(HOST_B));
     assertEquals(ImmutableSet.of(HOST_A_ATTRS, HOST_B_ATTRS), readAll());
 


Mime
View raw message