Skip to content

Commit

Permalink
HIVE-7167 : Hive Metastore fails to start with SQLServerException (Xi…
Browse files Browse the repository at this point in the history
…aobing Zhou, reviewed by Sergey Shelukhin)

git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1629986 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
sershe-apache committed Oct 7, 2014
1 parent eeb5006 commit 9e39b4c
Showing 1 changed file with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;

import javax.jdo.JDOException;

import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -570,22 +572,50 @@ private void createDefaultDB_core(RawStore ms) throws MetaException, InvalidObje
}

/**
* create default database if it doesn't exist
* create default database if it doesn't exist.
*
* This is a potential contention when HiveServer2 using embedded metastore and Metastore
* Server try to concurrently invoke createDefaultDB. If one failed, JDOException was caught
* for one more time try, if failed again, simply ignored by warning, which meant another
* succeeds.
*
* @throws MetaException
*/
private void createDefaultDB() throws MetaException {
try {
createDefaultDB_core(getMS());
} catch (JDOException e) {
LOG.warn("Retrying creating default database after error: " + e.getMessage(), e);
try {
createDefaultDB_core(getMS());
} catch (InvalidObjectException e1) {
throw new MetaException(e1.getMessage());
}
} catch (InvalidObjectException e) {
throw new MetaException(e.getMessage());
} catch (MetaException e) {
throw e;
}
}


/**
* create default roles if they don't exist.
*
* This is a potential contention when HiveServer2 using embedded metastore and Metastore
* Server try to concurrently invoke createDefaultRoles. If one failed, JDOException was caught
* for one more time try, if failed again, simply ignored by warning, which meant another
* succeeds.
*
* @throws MetaException
*/
private void createDefaultRoles() throws MetaException {
try {
createDefaultRoles_core();
} catch (JDOException e) {
LOG.warn("Retrying creating default roles after error: " + e.getMessage(), e);
createDefaultRoles_core();
}
}

private void createDefaultRoles_core() throws MetaException {

RawStore ms = getMS();
try {
Expand Down Expand Up @@ -622,7 +652,25 @@ private void createDefaultRoles() throws MetaException {
}
}

/**
* add admin users if they don't exist.
*
* This is a potential contention when HiveServer2 using embedded metastore and Metastore
* Server try to concurrently invoke addAdminUsers. If one failed, JDOException was caught for
* one more time try, if failed again, simply ignored by warning, which meant another succeeds.
*
* @throws MetaException
*/
private void addAdminUsers() throws MetaException {
try {
addAdminUsers_core();
} catch (JDOException e) {
LOG.warn("Retrying adding admin users after error: " + e.getMessage(), e);
addAdminUsers_core();
}
}

private void addAdminUsers_core() throws MetaException {

// now add pre-configured users to admin role
String userStr = HiveConf.getVar(hiveConf,ConfVars.USERS_IN_ADMIN_ROLE,"").trim();
Expand Down

0 comments on commit 9e39b4c

Please sign in to comment.