saihemanth-cloudera commented on code in PR #5851:
URL: https://github.com/apache/hive/pull/5851#discussion_r2612474097


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/TableOperationsHandler.java:
##########
@@ -0,0 +1,380 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.MoreExecutors;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.DropTableRequest;
+import org.apache.hadoop.hive.metastore.api.GetTableRequest;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.api.TableOpResp;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropTableEvent;
+import org.apache.hadoop.hive.metastore.messaging.EventMessage;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
+import org.apache.hadoop.hive.metastore.utils.SecurityUtils;
+import org.apache.thrift.TBase;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.hadoop.hive.metastore.ExceptionHandler.handleException;
+import static 
org.apache.hadoop.hive.metastore.HMSHandler.checkTableDataShouldBeDeleted;
+import static 
org.apache.hadoop.hive.metastore.HMSHandler.isDbReplicationTarget;
+import static org.apache.hadoop.hive.metastore.HMSHandler.isMustPurge;
+import static 
org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.getDefaultCatalog;
+import static 
org.apache.hadoop.hive.metastore.utils.StringUtils.normalizeIdentifier;
+
+public class TableOperationsHandler<T extends TBase> {
+  private static final Logger LOG = 
LoggerFactory.getLogger(TableOperationsHandler.class);
+  private static final Map<String, TableOperationsHandler<?>>
+      OPID_TO_HANDLER = new ConcurrentHashMap<>();
+  private static final ScheduledExecutorService OPID_CLEANER = 
Executors.newScheduledThreadPool(1, r -> {
+    Thread thread = new Thread(r);
+    thread.setDaemon(true);
+    thread.setName("TableOperationsHandler-cleaner");
+    return thread;
+  });
+
+  private volatile StringBuffer state = new StringBuffer("Preparing context");
+  private String id;
+  private final IHMSHandler handler;
+  private final T request;
+  private final ExecutorService executor;
+  private final boolean async;
+  private Future<Void> future;
+  private Path tblPath;
+  private Table tbl;
+  private TableName tableName;
+  private volatile Object result;
+  private String logMsgPrefix;
+  private final AtomicBoolean aborted = new AtomicBoolean();
+
+  private TableOperationsHandler(String id) throws TException, IOException {
+    this(null, false, null);
+    this.id = id;
+  }
+
+  private TableOperationsHandler(IHMSHandler handler, boolean async, T request)
+       throws TException, IOException {
+    this.id = UUID.randomUUID().toString();
+    this.handler = handler;
+    this.request = request;
+    this.async = async;
+    OPID_TO_HANDLER.put(id, this);
+    if (async) {
+      this.executor = Executors.newFixedThreadPool(1, r -> {
+        Thread thread = new Thread(r);
+        thread.setDaemon(true);
+        thread.setName("TableOperationsHandler " + id);
+        return thread;
+      });
+    } else {
+      this.executor = MoreExecutors.newDirectExecutorService();
+    }
+    this.runTableOperation();
+  }
+
+  public void dropTable() throws TException {
+    DropTableRequest dropReq = (DropTableRequest) request;
+    DropTableResult dropResult = (DropTableResult) result;
+    boolean success = false;
+    List<Path> partPaths = null;
+    Map<String, String> transactionalListenerResponses = 
Collections.emptyMap();
+    Database db = null;
+    boolean isReplicated = false;
+    RawStore ms = handler.getMS();
+    try {
+      ms.openTransaction();
+      String catName = tableName.getCat();
+      String dbname = tableName.getDb();
+      String name = tableName.getTable();
+      // HIVE-25282: Drop/Alter table in REMOTE db should fail
+      db = ms.getDatabase(catName, dbname);
+      if (MetaStoreUtils.isDatabaseRemote(db)) {
+        throw new MetaException("Drop table in REMOTE database " + 
db.getName() + " is not allowed");
+      }
+      isReplicated = isDbReplicationTarget(db);
+
+      checkInterrupted();
+      // Check if table is part of a materialized view.
+      // If it is, it cannot be dropped.
+      List<String> isPartOfMV = ms.isPartOfMaterializedView(catName, dbname, 
name);
+      if (!isPartOfMV.isEmpty()) {
+        throw new MetaException(String.format("Cannot drop table as it is used 
in the following materialized" +
+            " views %s%n", isPartOfMV));
+      }
+
+      ((HMSHandler) handler).firePreEvent(new PreDropTableEvent(tbl, 
dropReq.isDeleteData(), handler));
+
+      state = new StringBuffer();
+      // Drop the partitions and get a list of locations which need to be 
deleted
+      if (dropReq.isDropPartitions()) {
+        checkInterrupted();
+        List<String> locations = ms.dropAllPartitionsAndGetLocations(tableName,
+            tblPath != null ? handler.getWh().getDnsPath(tblPath).toString() : 
null, state);

Review Comment:
   Why do we need a 'state' variable here? L#163 it is anyway being overridden 
here.



-- 
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.

To unsubscribe, e-mail: [email protected]

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