adesh-rao commented on a change in pull request #1109:
URL: https://github.com/apache/hive/pull/1109#discussion_r449527172



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java
##########
@@ -514,6 +655,130 @@ public boolean containsPartition(List<String> partVals) {
       return containsPart;
     }
 
+    public void removeConstraint(String name) {
+      try {
+        tableLock.writeLock().lock();
+        Object constraint = null;
+        MemberName mn = null;
+        Class constraintClass = null;
+        if (this.primaryKeyCache.containsKey(name)) {

Review comment:
       Fixed.

##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java
##########
@@ -514,6 +655,130 @@ public boolean containsPartition(List<String> partVals) {
       return containsPart;
     }
 
+    public void removeConstraint(String name) {
+      try {
+        tableLock.writeLock().lock();
+        Object constraint = null;
+        MemberName mn = null;
+        Class constraintClass = null;
+        if (this.primaryKeyCache.containsKey(name)) {
+          constraint = this.primaryKeyCache.remove(name);
+          mn = MemberName.PRIMARY_KEY_CACHE;
+          this.memberCacheDirty[mn.ordinal()].set(true);
+          constraintClass = SQLPrimaryKey.class;
+        } else if (this.foreignKeyCache.containsKey(name)) {
+          constraint = this.foreignKeyCache.remove(name);
+          mn = MemberName.FOREIGN_KEY_CACHE;
+          this.memberCacheDirty[mn.ordinal()].set(true);
+          constraintClass = SQLForeignKey.class;
+        } else if (this.notNullConstraintCache.containsKey(name)) {
+          constraint = this.notNullConstraintCache.remove(name);
+          mn = MemberName.NOTNULL_CONSTRAINT_CACHE;
+          this.memberCacheDirty[mn.ordinal()].set(true);
+          constraintClass = SQLNotNullConstraint.class;
+        } else if (this.uniqueConstraintCache.containsKey(name)) {
+          constraint = this.uniqueConstraintCache.remove(name);
+          mn = MemberName.UNIQUE_CONSTRAINT_CACHE;
+          this.memberCacheDirty[mn.ordinal()].set(true);
+          constraintClass = SQLUniqueConstraint.class;
+        }
+
+        if(constraint == null) {
+          LOG.debug("Constraint: " + name + " does not exist in cache.");
+          return;
+        }
+        int size = getObjectSize(constraintClass, constraint);
+        updateMemberSize(mn, -1 * size, SizeMode.Delta);
+
+      } finally {
+        tableLock.writeLock().unlock();
+      }
+    }
+
+    public void refreshPrimaryKeys(List<SQLPrimaryKey> keys) {
+      Map<String, SQLPrimaryKey> newKeys = new ConcurrentHashMap<>();
+      try {
+        tableLock.writeLock().lock();
+        int size = 0;
+        for (SQLPrimaryKey key : keys) {
+          if 
(this.memberCacheDirty[MemberName.PRIMARY_KEY_CACHE.ordinal()].compareAndSet(true,
 false)) {
+            LOG.debug("Skipping primary key cache update for table: " + 
getTable().getTableName()
+                    + "; the primary keys we have is dirty.");
+            return;
+          }
+          newKeys.put(key.getPk_name(), key);
+          size += getObjectSize(SQLPrimaryKey.class, key);
+        }
+        primaryKeyCache = newKeys;
+        updateMemberSize(MemberName.PRIMARY_KEY_CACHE, size, 
SizeMode.Snapshot);

Review comment:
       done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to