protected HiveTxnManager getTxnMgr() { if (txnManager != null) { return txnManager; } return SessionState.get().getTxnMgr(); }
/** * Returns ValidWriteIdList for the table with the given "dbName" and "tableName". * This is called when HiveConf has no list for the table. * Otherwise use getTableSnapshot(). * @param conf Configuration * @param dbName * @param tableName * @return ValidWriteIdList on success, null on failure to get a list. * @throws LockException */ public static ValidWriteIdList getTableValidWriteIdListWithTxnList( Configuration conf, String dbName, String tableName) throws LockException { HiveTxnManager sessionTxnMgr = SessionState.get().getTxnMgr(); if (sessionTxnMgr == null) { return null; } ValidWriteIdList validWriteIdList = null; ValidTxnWriteIdList validTxnWriteIdList = null; String validTxnList = conf.get(ValidTxnList.VALID_TXNS_KEY); List<String> tablesInput = new ArrayList<>(); String fullTableName = getFullTableName(dbName, tableName); tablesInput.add(fullTableName); validTxnWriteIdList = sessionTxnMgr.getValidWriteIds(tablesInput, validTxnList); return validTxnWriteIdList != null ? validTxnWriteIdList.getTableValidWriteIdList(fullTableName) : null; }
private void recordValidTxns() throws LockException { HiveTxnManager txnMgr = SessionState.get().getTxnMgr(); ValidTxnList txns = txnMgr.getValidTxns(); String txnStr = txns.toString(); conf.set(ValidTxnList.VALID_TXNS_KEY, txnStr); if(plan.getFetchTask() != null) { /** * This is needed for {@link HiveConf.ConfVars.HIVEFETCHTASKCONVERSION} optimization which * initializes JobConf in FetchOperator before recordValidTxns() but this has to be done * after locks are acquired to avoid race conditions in ACID. */ plan.getFetchTask().setValidTxnList(txnStr); } LOG.debug("Encoding valid txns info " + txnStr + " txnid:" + txnMgr.getCurrentTxnId()); }
private AcidUtils.Operation getAcidType(Class<? extends OutputFormat> of, String dest) { if (SessionState.get() == null || !SessionState.get().getTxnMgr().supportsAcid()) { return AcidUtils.Operation.NOT_ACID; } else if (isAcidOutputFormat(of)) { return getAcidType(dest); } else { return AcidUtils.Operation.NOT_ACID; } }
ValidWriteIdList validWriteIdList = null; HiveTxnManager sessionTxnMgr = SessionState.get().getTxnMgr(); String fullTableName = getFullTableName(dbName, tblName); if (sessionTxnMgr != null && sessionTxnMgr.getCurrentTxnId() > 0) { validWriteIdList = getTableValidWriteIdList(conf, fullTableName); if (isStatsUpdater) { writeId = SessionState.get().getTxnMgr() != null ? SessionState.get().getTxnMgr().getAllocatedTableWriteId( dbName, tblName) : -1; if (writeId < 1) {
List<String> partNames = result.values().stream().map(Partition::getName).collect(Collectors.toList()); getMSC().addDynamicPartitions(parentSession.getTxnMgr().getCurrentTxnId(), writeId, tbl.getDbName(), tbl.getTableName(), partNames, AcidUtils.toDataOperationType(operation));
protected void checkAcidTxnManager(Table table) throws SemanticException { if (SessionState.get() != null && !SessionState.get().getTxnMgr().supportsAcid()) { throw new SemanticException(ErrorMsg.TXNMGR_NOT_ACID, table.getDbName(), table.getTableName()); } }
Long txnId = SessionState.get().getTxnMgr().getCurrentTxnId();
public int persistColumnStats(Hive db, Table tbl) throws HiveException, MetaException, IOException { // Construct a column statistics object from the result List<ColumnStatistics> colStats = constructColumnStatsFromPackedRows(tbl); // Persist the column statistics object to the metastore // Note, this function is shared for both table and partition column stats. if (colStats.isEmpty()) { return 0; } SetPartitionsStatsRequest request = new SetPartitionsStatsRequest(colStats); request.setNeedMerge(colStatDesc.isNeedMerge()); HiveTxnManager txnMgr = AcidUtils.isTransactionalTable(tbl) ? SessionState.get().getTxnMgr() : null; if (txnMgr != null) { request.setValidWriteIdList(AcidUtils.getTableValidWriteIdList(conf, AcidUtils.getFullTableName(tbl.getDbName(), tbl.getTableName())).toString()); request.setWriteId(txnMgr.getAllocatedTableWriteId(tbl.getDbName(), tbl.getTableName())); } db.setPartitionColumnStatistics(request); return 0; }
SessionState.get().getTxnMgr().getValidWriteIds(tablesUsed, validTxnsList);
new ArrayList<>(tbl.getCreationMetadata().getTablesUsed()); final ValidTxnWriteIdList currentTxnWriteIds = SessionState.get().getTxnMgr().getValidWriteIds(tablesUsed, validTxnsList); final long defaultTimeWindow = HiveConf.getTimeVar(db.getConf(), HiveConf.ConfVars.HIVE_MATERIALIZED_VIEW_REWRITING_TIME_WINDOW,
@Override public void analyzeInternal(ASTNode tree) throws SemanticException { if (useSuper) { super.analyzeInternal(tree); } else { if (!SessionState.get().getTxnMgr().supportsAcid()) { throw new SemanticException(ErrorMsg.ACID_OP_ON_NONACID_TXNMGR.getMsg()); } switch (tree.getToken().getType()) { case HiveParser.TOK_DELETE_FROM: analyzeDelete(tree); break; case HiveParser.TOK_UPDATE_TABLE: analyzeUpdate(tree); break; case HiveParser.TOK_MERGE: analyzeMerge(tree); break; default: throw new RuntimeException("Asked to parse token " + tree.getName() + " in " + "UpdateDeleteSemanticAnalyzer"); } cleanUpMetaColumnAccessControl(); } } private boolean updating() {
SessionState.get().getTxnMgr().openTxn(ctx, conf.getUser()); db = sem.getDb();
if (txnManager == null) { SessionState ss = SessionState.get(); txnMgr = ss.getTxnMgr(); } else { txnMgr = txnManager;
isSkewedStoredAsDirs(tbd), work.getLoadTableWork().getWriteType() != AcidUtils.Operation.NOT_ACID, SessionState.get().getTxnMgr().getCurrentTxnId(), hasFollowingStatsTask(), work.getLoadTableWork().getWriteType());
HiveTxnManager txnMgr = ss.getTxnMgr(); if(startTxnImplicitly) { assert !txnMgr.getAutoCommit();
@Before public void setUp() throws Exception { SessionState.start(conf); ctx = new Context(conf); driver = new Driver(new QueryState.Builder().withHiveConf(conf).nonIsolated().build(), null); driver2 = new Driver(new QueryState.Builder().withHiveConf(conf).build(), null); TxnDbUtil.cleanDb(conf); TxnDbUtil.prepDb(conf); SessionState ss = SessionState.get(); ss.initTxnMgr(conf); txnMgr = ss.getTxnMgr(); Assert.assertTrue(txnMgr instanceof DbTxnManager); txnHandler = TxnUtils.getTxnStore(conf); } @After
HiveTxnManager txnManager = SessionState.get().getTxnMgr(); ctx.setHiveTxnManager(txnManager);
public static boolean isAcidTable(Table tab) { if (tab == null) return false; if (!SessionState.get().getTxnMgr().supportsAcid()) return false; String tableIsTransactional = tab.getProperty(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL); return tableIsTransactional != null && tableIsTransactional.equalsIgnoreCase("true"); }