use of org.apache.hadoop.hive.metastore.api.AlreadyExistsException in project hive by apache.
the class TestHiveMetaStoreChecker method testErrorForMissingPartitionsSingleThreaded.
/*
* Test if single-threaded implementation checker throws HiveException when the there is a dummy
* directory present in the nested level
*/
@Test
public void testErrorForMissingPartitionsSingleThreaded() throws AlreadyExistsException, HiveException, IOException {
// set num of threads to 0 so that single-threaded checkMetastore is called
hive.getConf().setIntVar(HiveConf.ConfVars.METASTORE_FS_HANDLER_THREADS_COUNT, 0);
Table testTable = createPartitionedTestTable(dbName, tableName, 2, 0);
// add 10 partitions on the filesystem
createPartitionsDirectoriesOnFS(testTable, 10);
// create a fake directory to throw exception
StringBuilder sb = new StringBuilder(testTable.getDataLocation().toString());
sb.append(Path.SEPARATOR);
sb.append("dummyPart=error");
createDirectory(sb.toString());
// check result now
CheckResult result = new CheckResult();
Exception exception = null;
try {
checker.checkMetastore(dbName, tableName, null, result);
} catch (Exception e) {
exception = e;
}
assertTrue("Expected HiveException", exception != null && exception instanceof HiveException);
createFile(sb.toString(), "dummyFile");
result = new CheckResult();
exception = null;
try {
checker.checkMetastore(dbName, tableName, null, result);
} catch (Exception e) {
exception = e;
}
assertTrue("Expected HiveException", exception != null && exception instanceof HiveException);
}
use of org.apache.hadoop.hive.metastore.api.AlreadyExistsException in project hive by apache.
the class ObjectStore method createISchema.
@Override
public void createISchema(ISchema schema) throws AlreadyExistsException, MetaException, NoSuchObjectException {
boolean committed = false;
MISchema mSchema = convertToMISchema(schema);
try {
openTransaction();
if (getMISchema(schema.getDbName(), schema.getName()) != null) {
throw new AlreadyExistsException("Schema with name " + schema.getDbName() + "." + schema.getName() + " already exists");
}
pm.makePersistent(mSchema);
committed = commitTransaction();
} finally {
if (!committed)
rollbackTransaction();
}
}
use of org.apache.hadoop.hive.metastore.api.AlreadyExistsException in project hive by apache.
the class ObjectStore method createWMTrigger.
@Override
public void createWMTrigger(WMTrigger trigger) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
boolean commited = false;
try {
openTransaction();
MWMResourcePlan resourcePlan = getMWMResourcePlan(trigger.getResourcePlanName(), true);
MWMTrigger mTrigger = new MWMTrigger(resourcePlan, normalizeIdentifier(trigger.getTriggerName()), trigger.getTriggerExpression(), trigger.getActionExpression(), null, trigger.isSetIsInUnmanaged() && trigger.isIsInUnmanaged());
pm.makePersistent(mTrigger);
commited = commitTransaction();
} catch (Exception e) {
checkForConstraintException(e, "Trigger already exists, use alter: ");
throw e;
} finally {
rollbackAndCleanup(commited, (Query) null);
}
}
use of org.apache.hadoop.hive.metastore.api.AlreadyExistsException in project hive by apache.
the class ObjectStore method alterResourcePlan.
@Override
public WMFullResourcePlan alterResourcePlan(String name, WMNullableResourcePlan changes, boolean canActivateDisabled, boolean canDeactivate, boolean isReplace) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
name = name == null ? null : normalizeIdentifier(name);
if (isReplace && name == null) {
throw new InvalidOperationException("Cannot replace without specifying the source plan");
}
boolean commited = false;
Query query = null;
// This method only returns the result when activating a resource plan.
// We could also add a boolean flag to be specified by the caller to see
// when the result might be needed.
WMFullResourcePlan result = null;
try {
openTransaction();
if (isReplace) {
result = handleAlterReplace(name, changes);
} else {
result = handleSimpleAlter(name, changes, canActivateDisabled, canDeactivate);
}
commited = commitTransaction();
return result;
} catch (Exception e) {
checkForConstraintException(e, "Resource plan name should be unique: ");
throw e;
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.api.AlreadyExistsException in project hive by apache.
the class ObjectStore method createResourcePlan.
@Override
public void createResourcePlan(WMResourcePlan resourcePlan, String copyFromName, int defaultPoolSize) throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException {
boolean commited = false;
String rpName = normalizeIdentifier(resourcePlan.getName());
if (rpName.isEmpty()) {
throw new InvalidObjectException("Resource name cannot be empty.");
}
MWMResourcePlan rp = null;
if (copyFromName == null) {
Integer queryParallelism = null;
if (resourcePlan.isSetQueryParallelism()) {
queryParallelism = resourcePlan.getQueryParallelism();
if (queryParallelism <= 0) {
throw new InvalidObjectException("Query parallelism should be positive.");
}
}
rp = new MWMResourcePlan(rpName, queryParallelism, Status.DISABLED);
} else {
rp = new MWMResourcePlan(rpName, null, Status.DISABLED);
}
try {
openTransaction();
pm.makePersistent(rp);
if (copyFromName != null) {
MWMResourcePlan copyFrom = getMWMResourcePlan(copyFromName, false);
if (copyFrom == null) {
throw new NoSuchObjectException(copyFromName);
}
copyRpContents(rp, copyFrom);
} else {
// all the RawStore-s. Right now there's no method to create a pool.
if (defaultPoolSize > 0) {
MWMPool defaultPool = new MWMPool(rp, "default", 1.0, defaultPoolSize, null);
pm.makePersistent(defaultPool);
rp.setPools(Sets.newHashSet(defaultPool));
rp.setDefaultPool(defaultPool);
}
}
commited = commitTransaction();
} catch (InvalidOperationException e) {
throw new RuntimeException(e);
} catch (Exception e) {
checkForConstraintException(e, "Resource plan already exists: ");
throw e;
} finally {
if (!commited) {
rollbackTransaction();
}
}
}
Aggregations