[ https://issues.apache.org/jira/browse/HIVE-27186?focusedWorklogId=857930&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-857930 ]
ASF GitHub Bot logged work on HIVE-27186: ----------------------------------------- Author: ASF GitHub Bot Created on: 19/Apr/23 12:36 Start Date: 19/Apr/23 12:36 Worklog Time Spent: 10m Work Description: dengzhhu653 commented on code in PR #4194: URL: https://github.com/apache/hive/pull/4194#discussion_r1171273793 ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java: ########## @@ -5665,6 +5678,212 @@ private String getGuidFromDB() throws MetaException { return null; } + @Override + public boolean runInTransaction(Runnable exec) throws MetaException { + boolean success = false; + Transaction tx = null; + try { + if (openTransaction()) { + exec.run(); + success = commitTransaction(); + } + } catch (Exception e) { + LOG.warn("Metastore operation failed", e); + } finally { + rollbackAndCleanup(success, null); + } + return success; + } + + @Override + public boolean dropProperties(String key) throws MetaException { + boolean success = false; + Transaction tx = null; + Query query = null; + try { + if (openTransaction()) { + query = pm.newQuery(MMetastoreDBProperties.class, "this.propertyKey == key"); + query.declareParameters("java.lang.String key"); + Collection<MMetastoreDBProperties> properties = (Collection<MMetastoreDBProperties>) query.execute(key); + if (!properties.isEmpty()) { + pm.deletePersistentAll(properties); + } + success = commitTransaction(); + } + } catch (Exception e) { + LOG.warn("Metastore property drop failed", e); + } finally { + rollbackAndCleanup(success, query); + } + return success; + } + + @Override + public MMetastoreDBProperties putProperties(String key, String value, String description, byte[] content) throws MetaException { + boolean success = false; + try { + if (openTransaction()) { + //pm.currentTransaction().setOptimistic(false); + // fetch first to determine new vs update + MMetastoreDBProperties properties = doGetProperties(key, null); + final boolean newInstance; + if (properties == null) { + newInstance = true; + properties = new MMetastoreDBProperties(); + properties.setPropertykey(key); + } else { + newInstance = false; + } + properties.setDescription(description); + properties.setPropertyValue(value); + properties.setPropertyContent(content); + LOG.debug("Attempting to add property {} for the metastore db", key); + properties.setDescription("Metastore property " + + (newInstance ? "created" : "updated") + + " " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))); + if (newInstance) { + pm.makePersistent(properties); + } + success = commitTransaction(); + if (success) { + LOG.info("Metastore property {} created successfully", key); + return properties; + } + } + } catch (Exception e) { + LOG.warn("Metastore property save failed", e); + } finally { + rollbackAndCleanup(success, null); + } + return null; + } + + @Override + public boolean renameProperties(String mapKey, String newKey) throws MetaException { + boolean success = false; + Transaction tx = null; + Query query = null; Review Comment: there is a `QueryWrapper` that can wrap the Query, it makes try-with-resources easy to use for `Query` Issue Time Tracking ------------------- Worklog Id: (was: 857930) Time Spent: 2.5h (was: 2h 20m) > A persistent property store > ---------------------------- > > Key: HIVE-27186 > URL: https://issues.apache.org/jira/browse/HIVE-27186 > Project: Hive > Issue Type: Improvement > Components: Metastore > Affects Versions: 4.0.0-alpha-2 > Reporter: Henri Biestro > Assignee: Henri Biestro > Priority: Major > Labels: pull-request-available > Time Spent: 2.5h > Remaining Estimate: 0h > > WHAT > A persistent property store usable as a support facility for any metadata > augmentation feature. > WHY > When adding new meta-data oriented features, we usually need to persist > information linking the feature data and the HiveMetaStore objects it applies > to. Any information related to a database, a table or the cluster - like > statistics for example or any operational data state or data (think rolling > backup) - fall in this use-case. > Typically, accommodating such a feature requires modifying the Metastore > database schema by adding or altering a table. It also usually implies > modifying the thrift APIs to expose such meta-data to consumers. > The proposed feature wants to solve the persistence and query/transport for > these types of use-cases by exposing a 'key/(meta)value' store exposed as a > property system. > HOW > A property-value model is the simple and generic exposed API. > To provision for several usage scenarios, the model entry point is a > 'namespace' that qualifies the feature-component property manager. For > example, 'stats' could be the namespace for all properties related to the > 'statistics' feature. > The namespace identifies a manager that handles property-groups persisted as > property-maps. For instance, all statistics pertaining to a given table would > be collocated in the same property-group. As such, all properties (say number > of 'unique_values' per columns) for a given HMS table 'relation0' would all > be stored and persisted in the same property-map instance. > Property-maps may be decorated by an (optional) schema that may declare the > name and value-type of allowed properties (and their optional default value). > Each property is addressed by a name, a path uniquely identifying the > property in a given property map. > The manager also handles transforming property-map names to the property-map > keys used to persist them in the DB. > The API provides inserting/updating properties in bulk transactionally. It > also provides selection/projection to help reduce the volume of exchange > between client/server; selection can use (JEXL expression) predicates to > filter maps. -- This message was sent by Atlassian Jira (v8.20.10#820010)