-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[WIP] #6450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dengzhhu653
wants to merge
12
commits into
apache:master
Choose a base branch
from
dengzhhu653:split-objectstore
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[WIP] #6450
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
20daac4
TableStore
dengzhhu653 9937324
privilege store
dengzhhu653 9c248a1
minor
dengzhhu653 c87e4f6
fix
dengzhhu653 90aace2
ff
dengzhhu653 7edfc3b
review-2
dengzhhu653 f317d71
fix-ut
dengzhhu653 21100d3
fix ut - 2
dengzhhu653 9e8fff6
fix ut - 3
dengzhhu653 1be3fe1
fix
dengzhhu653 6cdcecf
fix
dengzhhu653 ad7346d
fix
dengzhhu653 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8,798 changes: 1,291 additions & 7,507 deletions
8,798
...etastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
Large diffs are not rendered by default.
Oops, something went wrong.
560 changes: 395 additions & 165 deletions
560
...e-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RawStore.java
Large diffs are not rendered by default.
Oops, something went wrong.
357 changes: 14 additions & 343 deletions
357
...re/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
275 changes: 275 additions & 0 deletions
275
.../metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metastore/GetHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,275 @@ | ||
| /* | ||
| * 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.metastore; | ||
|
|
||
| import com.codahale.metrics.Counter; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
|
|
||
| import javax.jdo.JDOException; | ||
| import javax.jdo.PersistenceManager; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.hadoop.hive.common.TableName; | ||
| import org.apache.hadoop.hive.metastore.DatabaseProduct; | ||
| import org.apache.hadoop.hive.metastore.ExceptionHandler; | ||
| import org.apache.hadoop.hive.metastore.directsql.MetaStoreDirectSql; | ||
| import org.apache.hadoop.hive.metastore.RawStore; | ||
| import org.apache.hadoop.hive.metastore.api.InvalidInputException; | ||
| import org.apache.hadoop.hive.metastore.api.InvalidObjectException; | ||
| 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.conf.MetastoreConf; | ||
| import org.apache.hadoop.hive.metastore.metrics.Metrics; | ||
| import org.apache.hadoop.hive.metastore.metrics.MetricsConstants; | ||
| import org.apache.hadoop.hive.metastore.metastore.iface.TableStore; | ||
| import org.datanucleus.api.jdo.JDOTransaction; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** Helper class for getting stuff w/transaction, direct SQL, perf logging, etc. */ | ||
| @VisibleForTesting | ||
| public abstract class GetHelper<A, T> { | ||
| private static final Logger LOG = LoggerFactory.getLogger(GetHelper.class); | ||
| private static final Counter directSqlErrors = Metrics.getRegistry() != null ? | ||
| Metrics.getOrCreateCounter(MetricsConstants.DIRECTSQL_ERRORS) : new Counter(); | ||
| private final boolean isInTxn, doTrace, allowJdo; | ||
| private boolean doUseDirectSql; | ||
| private long start; | ||
| private Table table; | ||
| protected final RawStore baseStore; | ||
| protected final PersistenceManager pm; | ||
| private MetaStoreDirectSql directSql; | ||
| protected final List<String> partitionFields; | ||
| protected final A argument; | ||
| private boolean success = false; | ||
| protected T results = null; | ||
|
|
||
| public GetHelper(RawStoreAware rsa, A args) throws MetaException { | ||
| this(rsa, args, null); | ||
| } | ||
|
|
||
| public GetHelper(RawStoreAware rsa, | ||
| A args, List<String> fields) throws MetaException { | ||
| this.baseStore = rsa.getBaseStore(); | ||
| this.partitionFields = fields; | ||
| this.argument = args; | ||
| this.doTrace = LOG.isDebugEnabled(); | ||
| this.isInTxn = baseStore.isActiveTransaction(); | ||
| this.pm = rsa.getPersistentManager(); | ||
| this.allowJdo = canUseJdoQuery(); | ||
|
|
||
| boolean isConfigEnabled = MetastoreConf.getBoolVar(baseStore.getConf(), | ||
| MetastoreConf.ConfVars.TRY_DIRECT_SQL); | ||
| if (isConfigEnabled) { | ||
| directSql = new MetaStoreDirectSql(pm, baseStore.getConf(), ""); | ||
| } | ||
|
|
||
| if (!allowJdo && isConfigEnabled && !directSql.isCompatibleDatastore()) { | ||
| throw new MetaException("SQL is not operational"); // test path; SQL is enabled and broken. | ||
| } | ||
| this.doUseDirectSql = isConfigEnabled && directSql.isCompatibleDatastore(); | ||
| } | ||
|
|
||
| protected boolean canUseDirectSql() throws MetaException { | ||
| return true; // By default, assume we can user directSQL - that's kind of the point. | ||
| } | ||
|
|
||
| protected boolean canUseJdoQuery() throws MetaException { | ||
| return true; | ||
| } | ||
|
|
||
| protected abstract String describeResult(); | ||
| protected abstract T getSqlResult() throws MetaException; | ||
| protected abstract T getJdoResult() | ||
| throws MetaException, NoSuchObjectException, InvalidObjectException, | ||
| InvalidInputException; | ||
|
|
||
| public T run(boolean initTable) throws MetaException, NoSuchObjectException { | ||
| try { | ||
| start(initTable); | ||
| String savePoint = isInTxn && allowJdo ? "rollback_" + System.nanoTime() : null; | ||
| if (doUseDirectSql) { | ||
| try { | ||
| directSql.prepareTxn(); | ||
| setTransactionSavePoint(savePoint); | ||
| this.results = getSqlResult(); | ||
| LOG.debug("Using direct SQL optimization."); | ||
| } catch (Exception ex) { | ||
| handleDirectSqlError(ex, savePoint); | ||
| } | ||
| } | ||
| // Note that this will be invoked in 2 cases: | ||
| // 1) DirectSQL was disabled to start with; | ||
| // 2) DirectSQL threw and was disabled in handleDirectSqlError. | ||
| if (!doUseDirectSql && canUseJdoQuery()) { | ||
| this.results = getJdoResult(); | ||
| LOG.debug("Not using direct SQL optimization."); | ||
| } | ||
| return commit(); | ||
| } catch (NoSuchObjectException | MetaException ex) { | ||
| throw ex; | ||
| } catch (Exception ex) { | ||
| LOG.error("", ex); | ||
| throw new MetaException(ex.getMessage()); | ||
| } finally { | ||
| close(); | ||
| } | ||
| } | ||
|
|
||
| private void start(boolean initTable) throws MetaException, NoSuchObjectException { | ||
| start = doTrace ? System.nanoTime() : 0; | ||
| baseStore.openTransaction(); | ||
| if (initTable && (argument != null)) { | ||
| TableStore store = baseStore.unwrap(TableStore.class); | ||
| table = store.getTable((TableName) argument, null, -1); | ||
| if (table == null) { | ||
| throw new NoSuchObjectException( | ||
| "Specified catalog.database.table does not exist : " + argument); | ||
| } | ||
| } | ||
| doUseDirectSql = doUseDirectSql && canUseDirectSql(); | ||
| } | ||
|
|
||
| private void handleDirectSqlError(Exception ex, String savePoint) throws MetaException, NoSuchObjectException { | ||
| String message = null; | ||
| try { | ||
| message = generateShorterMessage(ex); | ||
| } catch (Throwable t) { | ||
| message = ex.toString() + "; error building a better message: " + t.getMessage(); | ||
| } | ||
| LOG.warn(message); // Don't log the exception, people just get confused. | ||
| LOG.debug("Full DirectSQL callstack for debugging (not an error)", ex); | ||
|
|
||
| if (!allowJdo || !DatabaseProduct.isRecoverableException(ex)) { | ||
| throw ExceptionHandler.newMetaException(ex); | ||
| } | ||
|
|
||
| if (!isInTxn) { | ||
| JDOException rollbackEx = null; | ||
| try { | ||
| baseStore.rollbackTransaction(); | ||
| } catch (JDOException jex) { | ||
| rollbackEx = jex; | ||
| } | ||
| if (rollbackEx != null) { | ||
| // Datanucleus propagates some pointless exceptions and rolls back in the finally. | ||
| if (baseStore.isActiveTransaction()) { | ||
| throw rollbackEx; // Throw if the tx wasn't rolled back. | ||
| } | ||
| LOG.info("Ignoring exception, rollback succeeded: " + rollbackEx.getMessage()); | ||
| } | ||
|
|
||
| start = doTrace ? System.nanoTime() : 0; | ||
| baseStore.openTransaction(); | ||
| if (table != null) { | ||
| TableStore store = baseStore.unwrap(TableStore.class); | ||
| table = store.getTable((TableName) argument, null, -1); | ||
| if (table == null) { | ||
| throw new NoSuchObjectException( | ||
| "Specified catalog.database.table does not exist : " + argument); | ||
| } | ||
| } | ||
| } else { | ||
| rollbackTransactionToSavePoint(savePoint); | ||
| start = doTrace ? System.nanoTime() : 0; | ||
| } | ||
|
|
||
| directSqlErrors.inc(); | ||
| doUseDirectSql = false; | ||
| } | ||
|
|
||
| private void setTransactionSavePoint(String savePoint) { | ||
| if (savePoint != null) { | ||
| ((JDOTransaction) pm.currentTransaction()).setSavepoint(savePoint); | ||
| } | ||
| } | ||
|
|
||
| private void rollbackTransactionToSavePoint(String savePoint) { | ||
| if (savePoint != null) { | ||
| ((JDOTransaction) pm.currentTransaction()).rollbackToSavepoint(savePoint); | ||
| } | ||
| } | ||
|
|
||
| private String generateShorterMessage(Exception ex) { | ||
| StringBuilder message = new StringBuilder( | ||
| "Falling back to ORM path due to direct SQL failure (this is not an error): "); | ||
| Throwable t = ex; | ||
| StackTraceElement[] prevStack = null; | ||
| while (t != null) { | ||
| message.append(t.getMessage()); | ||
| StackTraceElement[] stack = t.getStackTrace(); | ||
| int uniqueFrames = stack.length - 1; | ||
| if (prevStack != null) { | ||
| int n = prevStack.length - 1; | ||
| while (uniqueFrames >= 0 && n >= 0 && stack[uniqueFrames].equals(prevStack[n])) { | ||
| uniqueFrames--; n--; | ||
| } | ||
| } | ||
| for (int i = 0; i <= uniqueFrames; ++i) { | ||
| StackTraceElement ste = stack[i]; | ||
| message.append(" at ").append(ste); | ||
| if (ste.getMethodName().contains("getSqlResult") | ||
| && (ste.getFileName() == null || ste.getFileName().contains("ObjectStore"))) { | ||
| break; | ||
| } | ||
| } | ||
| prevStack = stack; | ||
| t = t.getCause(); | ||
| if (t != null) { | ||
| message.append(";\n Caused by: "); | ||
| } | ||
| } | ||
| return message.toString(); | ||
| } | ||
|
|
||
| private T commit() { | ||
| success = baseStore.commitTransaction(); | ||
| if (doTrace) { | ||
| double time = ((System.nanoTime() - start) / 1000000.0); | ||
| String result = describeResult(); | ||
| String retrieveType = doUseDirectSql ? "SQL" : "ORM"; | ||
|
|
||
| LOG.debug("{} retrieved using {} in {}ms", result, retrieveType, time); | ||
| } | ||
| return results; | ||
| } | ||
|
|
||
| private void close() { | ||
| if (!success) { | ||
| baseStore.rollbackTransaction(); | ||
| } | ||
| } | ||
|
|
||
| public Table getTable() { | ||
| return table; | ||
| } | ||
|
|
||
| public MetaStoreDirectSql getDirectSql() { | ||
| return directSql; | ||
| } | ||
|
|
||
| public List<String> getPartitionFields() { | ||
| return partitionFields; | ||
| } | ||
|
|
||
| public static long getDirectSqlErrors() { | ||
| return directSqlErrors.getCount(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the Jenkins artifact and confirmed that the HIVE-25965 issue is being hit. However, I do not yet fully understand why this starts happening after applying this patch. Could you explain the expected connection between this patch and the failure?
Also, I may have missed something, but I could not reproduce the issue in my local environment. Were you able to reproduce it locally?