use of org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties in project hive by apache.
the class ObjectStore method createDbGuidAndPersist.
private String createDbGuidAndPersist() throws MetaException {
boolean success = false;
Query query = null;
try {
openTransaction();
MMetastoreDBProperties prop = new MMetastoreDBProperties();
prop.setPropertykey("guid");
final String guid = UUID.randomUUID().toString();
LOG.debug("Attempting to add a guid {} for the metastore db", guid);
prop.setPropertyValue(guid);
prop.setDescription("Metastore DB GUID generated on " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
pm.makePersistent(prop);
success = commitTransaction();
if (success) {
LOG.info("Metastore db guid {} created successfully", guid);
return guid;
}
} catch (Exception e) {
LOG.warn("Metastore db guid creation failed", e);
} finally {
rollbackAndCleanup(success, query);
}
// it possible that some other HMS instance could have created the guid
// at the same time due which this instance could not create a guid above
// in such case return the guid already generated
final String guid = getGuidFromDB();
if (guid == null) {
throw new MetaException("Unable to create or fetch the metastore database uuid");
}
return guid;
}
use of org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties in project hive by apache.
the class ObjectStore method getGuidFromDB.
private String getGuidFromDB() throws MetaException {
boolean success = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MMetastoreDBProperties.class, "this.propertyKey == key");
query.declareParameters("java.lang.String key");
Collection<MMetastoreDBProperties> names = (Collection<MMetastoreDBProperties>) query.execute("guid");
List<String> uuids = new ArrayList<>();
for (Iterator<MMetastoreDBProperties> i = names.iterator(); i.hasNext(); ) {
String uuid = i.next().getPropertyValue();
LOG.debug("Found guid {}", uuid);
uuids.add(uuid);
}
success = commitTransaction();
if (uuids.size() > 1) {
throw new MetaException("Multiple uuids found");
}
if (!uuids.isEmpty()) {
LOG.debug("Returning guid of metastore db : {}", uuids.get(0));
return uuids.get(0);
}
} finally {
rollbackAndCleanup(success, query);
}
LOG.warn("Guid for metastore db not found");
return null;
}
Aggregations