diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/SQLGenerator.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/SQLGenerator.java index 49b737ecf9..aa3dbfa79e 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/SQLGenerator.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/SQLGenerator.java @@ -30,8 +30,10 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** * Helper class that generates SQL queries with syntax specific to target DB @@ -292,4 +294,19 @@ public String addEscapeCharacters(String s) { return s; } + public String getDefaultValuesClause() { + if (dbProduct == DatabaseProduct.SQLSERVER) { + return "DEFAULT VALUES"; + } else { + return "VALUES(DEFAULT)"; + } + } + + public String concat(String... parts) { + if (dbProduct == DatabaseProduct.DERBY) { + return String.join(" || ", parts); + } else { + return "CONCAT(" + String.join(", ", parts) + ")"; + } + } } diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java index bb29410e7d..deed2a2534 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java @@ -156,8 +156,7 @@ public static synchronized void prepDb(Configuration conf) throws Exception { " PRIMARY KEY(HL_LOCK_EXT_ID, HL_LOCK_INT_ID))"); stmt.execute("CREATE INDEX HL_TXNID_INDEX ON HIVE_LOCKS (HL_TXNID)"); - stmt.execute("CREATE TABLE NEXT_LOCK_ID (" + " NL_NEXT bigint NOT NULL)"); - stmt.execute("INSERT INTO NEXT_LOCK_ID VALUES(1)"); + stmt.execute("CREATE TABLE NEXT_LOCK_ID (NL_NEXT bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"); stmt.execute("CREATE TABLE COMPACTION_QUEUE (" + " CQ_ID bigint PRIMARY KEY," + diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java index e7910c1c5d..682ab49df3 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java @@ -180,7 +180,6 @@ private static final int ALLOWED_REPEATED_DEADLOCKS = 10; private static final Logger LOG = LoggerFactory.getLogger(TxnHandler.class.getName()); - private static final Long TEMP_HIVE_LOCK_ID = -1L; private static final Long TEMP_COMMIT_ID = -1L; private static DataSource connPool; @@ -194,8 +193,6 @@ private static final String TXN_COMPONENTS_INSERT_QUERY = "INSERT INTO \"TXN_COMPONENTS\" (" + "\"TC_TXNID\", \"TC_DATABASE\", \"TC_TABLE\", \"TC_PARTITION\", \"TC_OPERATION_TYPE\", \"TC_WRITEID\")" + " VALUES (?, ?, ?, ?, ?, ?)"; - private static final String INCREMENT_NEXT_LOCK_ID_QUERY = "UPDATE \"NEXT_LOCK_ID\" SET \"NL_NEXT\" = %s"; - private static final String UPDATE_HIVE_LOCKS_EXT_ID_QUERY = "UPDATE \"HIVE_LOCKS\" SET \"HL_LOCK_EXT_ID\" = %s WHERE \"HL_LOCK_EXT_ID\" = %s"; private static final String SELECT_WRITE_ID_QUERY = "SELECT \"T2W_WRITEID\" FROM \"TXN_TO_WRITE_ID\" WHERE" + " \"T2W_DATABASE\" = ? AND \"T2W_TABLE\" = ? AND \"T2W_TXNID\" = ?"; private static final String COMPL_TXN_COMPONENTS_INSERT_QUERY = "INSERT INTO \"COMPLETED_TXN_COMPONENTS\" " + @@ -2320,7 +2317,7 @@ public LockResponse lock(LockRequest rqst) throws NoSuchTxnException, TxnAborted try { return checkLockWithRetry(connAndLockId.dbConn, connAndLockId.extLockId, rqst.getTxnid()); } - catch(NoSuchLockException e) { + catch (NoSuchLockException e) { // This should never happen, as we just added the lock id throw new MetaException("Couldn't find a lock we just created! " + e.getMessage()); } @@ -2389,19 +2386,18 @@ private ConnectionLockIdPair enqueueLockWithRetry(LockRequest rqst) throws NoSuc shouldNeverHappen(txnid); } } - /* Insert txn components and hive locks (with a temp extLockId) first, before getting the next lock ID in a select-for-update. - This should minimize the scope of the S4U and decrease the table lock duration. */ + insertTxnComponents(txnid, rqst, dbConn); - insertHiveLocksWithTemporaryExtLockId(txnid, dbConn, rqst); + // TODO: update doc /** Get the next lock id. * This has to be atomic with adding entries to HIVE_LOCK entries (1st add in W state) to prevent a race. * Suppose ID gen is a separate txn and 2 concurrent lock() methods are running. 1st one generates nl_next=7, * 2nd nl_next=8. Then 8 goes first to insert into HIVE_LOCKS and acquires the locks. Then 7 unblocks, * and add it's W locks but it won't see locks from 8 since to be 'fair' {@link #checkLock(java.sql.Connection, long)} * doesn't block on locks acquired later than one it's checking*/ - long extLockId = getNextLockIdForUpdate(dbConn, stmt); - incrementLockIdAndUpdateHiveLocks(stmt, extLockId); + long extLockId = getNextLockId(dbConn, stmt); + insertHiveLocks(dbConn, rqst, extLockId); dbConn.commit(); success = true; @@ -2427,10 +2423,11 @@ private ConnectionLockIdPair enqueueLockWithRetry(LockRequest rqst) throws NoSuc } } - private long getNextLockIdForUpdate(Connection dbConn, Statement stmt) throws SQLException, MetaException { - String s = sqlGenerator.addForUpdateClause("SELECT \"NL_NEXT\" FROM \"NEXT_LOCK_ID\""); + private long getNextLockId(Connection dbConn, Statement stmt) throws SQLException, MetaException { + String s = "INSERT INTO \"NEXT_LOCK_ID\" " + sqlGenerator.getDefaultValuesClause(); LOG.debug("Going to execute query <" + s + ">"); - try (ResultSet rs = stmt.executeQuery(s)) { + stmt.executeUpdate(s, Statement.RETURN_GENERATED_KEYS); + try (ResultSet rs = stmt.getGeneratedKeys()) { if (!rs.next()) { LOG.debug("Going to rollback"); dbConn.rollback(); @@ -2441,16 +2438,6 @@ private long getNextLockIdForUpdate(Connection dbConn, Statement stmt) throws SQ } } - private void incrementLockIdAndUpdateHiveLocks(Statement stmt, long extLockId) throws SQLException { - String incrCmd = String.format(INCREMENT_NEXT_LOCK_ID_QUERY, (extLockId + 1)); - // update hive locks entries with the real EXT_LOCK_ID (replace temp ID) - String updateLocksCmd = String.format(UPDATE_HIVE_LOCKS_EXT_ID_QUERY, extLockId, TEMP_HIVE_LOCK_ID); - LOG.debug("Going to execute updates in batch: <" + incrCmd + ">, and <" + updateLocksCmd + ">"); - stmt.addBatch(incrCmd); - stmt.addBatch(updateLocksCmd); - stmt.executeBatch(); - } - private void insertTxnComponents(long txnid, LockRequest rqst, Connection dbConn) throws SQLException { if (txnid > 0) { Map, Optional> writeIdCache = new HashMap<>(); @@ -2565,9 +2552,9 @@ private boolean shouldUpdateTxnComponent(long txnid, LockRequest rqst, LockCompo } } - private void insertHiveLocksWithTemporaryExtLockId(long txnid, Connection dbConn, LockRequest rqst) throws MetaException, SQLException { + private void insertHiveLocks(Connection dbConn, LockRequest rqst, long extLockId) throws MetaException, SQLException { - String lastHB = isValidTxn(txnid) ? "0" : TxnDbUtil.getEpochFn(dbProduct); + String lastHB = isValidTxn(rqst.getTxnid()) ? "0" : TxnDbUtil.getEpochFn(dbProduct); String insertLocksQuery = String.format(HIVE_LOCKS_INSERT_QRY, lastHB); long intLockId = 0; @@ -2587,9 +2574,9 @@ private void insertHiveLocksWithTemporaryExtLockId(long txnid, Connection dbConn intLockId++; String lockType = LockTypeUtil.getEncodingAsStr(lc.getType()); - pstmt.setLong(1, TEMP_HIVE_LOCK_ID); + pstmt.setLong(1, extLockId); pstmt.setLong(2, intLockId); - pstmt.setLong(3, txnid); + pstmt.setLong(3, rqst.getTxnid()); pstmt.setString(4, normalizeCase(lc.getDbname())); pstmt.setString(5, normalizeCase(lc.getTablename())); pstmt.setString(6, normalizeCase(lc.getPartitionname())); @@ -4349,11 +4336,15 @@ private LockResponse checkLock(Connection dbConn, long extLockId, long txnId) close(rs, stmt, null); } + // S4U on our lock components + lockComponentsForUpdate(dbConn, extLockId); + String queryStr = " \"EX\".*, \"REQ\".\"HL_LOCK_INT_ID\" AS \"REQ_LOCK_INT_ID\" FROM (" + " SELECT \"HL_LOCK_EXT_ID\", \"HL_LOCK_INT_ID\", \"HL_TXNID\", \"HL_DB\", \"HL_TABLE\", \"HL_PARTITION\"," + " \"HL_LOCK_STATE\", \"HL_LOCK_TYPE\" FROM \"HIVE_LOCKS\"" + - " WHERE \"HL_LOCK_EXT_ID\" < " + extLockId + ") \"EX\"" + + " WHERE \"HL_LOCK_EXT_ID\" < " + extLockId + + " OR (\"HL_LOCK_EXT_ID\" > " + extLockId + " AND \"HL_LOCK_STATE\" = '" + LOCK_ACQUIRED + "')) \"EX\"" + " INNER JOIN (" + " SELECT \"HL_LOCK_INT_ID\", \"HL_TXNID\", \"HL_DB\", \"HL_TABLE\", \"HL_PARTITION\"," + " \"HL_LOCK_TYPE\" FROM \"HIVE_LOCKS\"" + @@ -4432,6 +4423,18 @@ is performed on that db (e.g. show tables, created table, etc). return response; } + private void lockComponentsForUpdate(Connection dbConn, long extLockId) throws MetaException, SQLException { + String dbTablePartTriplet = sqlGenerator.concat( + "COALESCE(\"HL_DB\", 'NULL')", "','", "COALESCE(\"HL_TABLE\", 'NULL')", "','", "COALESCE(\"HL_PARTITION\", 'NULL')"); + String s = String.format("SELECT * FROM \"HIVE_LOCKS\" WHERE %s IN " + + " (SELECT %s FROM \"HIVE_LOCKS\" WHERE \"HL_LOCK_EXT_ID\" = %s)", dbTablePartTriplet, dbTablePartTriplet, extLockId); + String lockComponentsQuery = sqlGenerator.addForUpdateClause(s); + LOG.debug("Going to execute select for update: <" + lockComponentsQuery + ">"); + try (Statement st = dbConn.createStatement()) { + st.executeQuery(lockComponentsQuery); + } + } + private void acquire(Connection dbConn, Statement stmt, List locksBeingChecked) throws SQLException, NoSuchLockException, MetaException { if(locksBeingChecked == null || locksBeingChecked.isEmpty()) { diff --git standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql index 1ace9d3ef0..2131fddb16 100644 --- standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql +++ standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql @@ -585,9 +585,8 @@ CREATE TABLE HIVE_LOCKS ( CREATE INDEX HL_TXNID_INDEX ON HIVE_LOCKS (HL_TXNID); CREATE TABLE NEXT_LOCK_ID ( - NL_NEXT bigint NOT NULL + NL_NEXT bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY ); -INSERT INTO NEXT_LOCK_ID VALUES(1); CREATE TABLE COMPACTION_QUEUE ( CQ_ID bigint PRIMARY KEY, diff --git standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql index 8a3cd56658..f35437b5af 100644 --- standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql +++ standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql @@ -68,5 +68,13 @@ ALTER TABLE "APP"."DBS" ADD COLUMN "DB_MANAGED_LOCATION_URI" VARCHAR(4000); ALTER TABLE COMPACTION_QUEUE ADD CQ_NEXT_TXN_ID bigint; DROP TABLE MIN_HISTORY_LEVEL; +-- HIVE-23236 +CREATE TABLE TMP_NEXT_LOCK_ID( + NL_NEXT bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY +); +INSERT INTO TMP_NEXT_LOCK_ID (NL_NEXT) SELECT NL_NEXT FROM NEXT_LOCK_ID; +DROP TABLE NEXT_LOCK_ID; +RENAME TABLE TMP_NEXT_LOCK_ID TO NEXT_LOCK_ID; + -- This needs to be the last thing done. Insert any changes above this line. UPDATE "APP".VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1; diff --git standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql index 2e0177723d..dae0ede61b 100644 --- standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql +++ standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql @@ -1091,11 +1091,9 @@ CREATE TABLE NEXT_COMPACTION_QUEUE_ID( INSERT INTO NEXT_COMPACTION_QUEUE_ID VALUES(1); CREATE TABLE NEXT_LOCK_ID( - NL_NEXT bigint NOT NULL + NL_NEXT bigint NOT NULL IDENTITY(1, 1) ); -INSERT INTO NEXT_LOCK_ID VALUES(1); - CREATE TABLE NEXT_TXN_ID( NTXN_NEXT bigint NOT NULL ); diff --git standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql index 9f3951575b..cb62396ae1 100644 --- standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql +++ standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql @@ -71,6 +71,16 @@ ALTER TABLE DBS ADD DB_MANAGED_LOCATION_URI nvarchar(4000); ALTER TABLE COMPACTION_QUEUE bigint CQ_NEXT_TXN_ID NOT NULL; DROP TABLE MIN_HISTORY_LEVEL; +-- HIVE-23236 +CREATE TABLE TMP_NEXT_LOCK_ID( + NL_NEXT bigint NOT NULL IDENTITY(1, 1) +); +SET IDENTITY_INSERT TMP_NEXT_LOCK_ID ON; +INSERT INTO TMP_NEXT_LOCK_ID (NL_NEXT) SELECT NL_NEXT FROM NEXT_LOCK_ID; +SET IDENTITY_INSERT TMP_NEXT_LOCK_ID OFF; +DROP TABLE NEXT_LOCK_ID; +EXEC sp_rename 'TMP_NEXT_LOCK_ID', 'NEXT_LOCK_ID'; + -- These lines need to be last. Insert any changes above. UPDATE VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1; SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0' AS MESSAGE; diff --git standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql index 0512a45cad..48c294e47d 100644 --- standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql +++ standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql @@ -1054,9 +1054,8 @@ CREATE TABLE HIVE_LOCKS ( CREATE INDEX HL_TXNID_IDX ON HIVE_LOCKS (HL_TXNID); CREATE TABLE NEXT_LOCK_ID ( - NL_NEXT bigint NOT NULL + NL_NEXT bigint PRIMARY KEY AUTO_INCREMENT ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -INSERT INTO NEXT_LOCK_ID VALUES(1); CREATE TABLE COMPACTION_QUEUE ( CQ_ID bigint PRIMARY KEY, diff --git standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql index 4b82e36ab4..6f7438c3fc 100644 --- standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql +++ standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql @@ -72,6 +72,14 @@ ALTER TABLE DBS ADD COLUMN DB_MANAGED_LOCATION_URI VARCHAR(4000) CHARACTER SET l ALTER TABLE COMPACTION_QUEUE ADD CQ_NEXT_TXN_ID bigint; DROP TABLE MIN_HISTORY_LEVEL; +-- HIVE-23236 +CREATE TABLE TMP_NEXT_LOCK_ID( + NL_NEXT bigint PRIMARY KEY AUTO_INCREMENT +); +INSERT INTO TMP_NEXT_LOCK_ID (NL_NEXT) SELECT NL_NEXT FROM NEXT_LOCK_ID; +DROP TABLE NEXT_LOCK_ID; +RENAME TABLE TMP_NEXT_LOCK_ID TO NEXT_LOCK_ID; + -- These lines need to be last. Insert any changes above. UPDATE VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1; SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0' AS MESSAGE; diff --git standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql index db398e5f66..9ffe9f489d 100644 --- standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql +++ standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql @@ -1035,9 +1035,8 @@ CREATE TABLE HIVE_LOCKS ( CREATE INDEX HL_TXNID_INDEX ON HIVE_LOCKS (HL_TXNID); CREATE TABLE NEXT_LOCK_ID ( - NL_NEXT NUMBER(19) NOT NULL + NL_NEXT NUMBER(19) GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY ); -INSERT INTO NEXT_LOCK_ID VALUES(1); CREATE TABLE COMPACTION_QUEUE ( CQ_ID NUMBER(19) PRIMARY KEY, diff --git standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql index 1be83fc4a9..328290f39a 100644 --- standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql +++ standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql @@ -72,6 +72,14 @@ ALTER TABLE DBS ADD DB_MANAGED_LOCATION_URI VARCHAR2(4000) NULL; ALTER TABLE COMPACTION_QUEUE ADD CQ_NEXT_TXN_ID NUMBER(19); DROP TABLE MIN_HISTORY_LEVEL; +-- HIVE-23236 +DECLARE start_lock_id NUMBER; +BEGIN + SELECT MAX(NL_NEXT) + 1 INTO start_lock_id FROM NEXT_LOCK_ID; + EXECUTE IMMEDIATE 'CREATE SEQUENCE NEXT_LOCK_ID_SEQ INCREMENT BY 1 START WITH ' || start_lock_id || ' CACHE 20'; +END; +ALTER TABLE NEXT_LOCK_ID MODIFY NL_NEXT default NEXT_LOCK_ID_SEQ.nextval; + -- These lines need to be last. Insert any changes above. UPDATE VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1; SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0' AS Status from dual; diff --git standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql index e6e30160af..00d6b2a9f3 100644 --- standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql +++ standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql @@ -1721,9 +1721,8 @@ CREATE TABLE "HIVE_LOCKS" ( CREATE INDEX HL_TXNID_INDEX ON "HIVE_LOCKS" USING hash ("HL_TXNID"); CREATE TABLE "NEXT_LOCK_ID" ( - "NL_NEXT" bigint NOT NULL + "NL_NEXT" bigserial NOT NULL ); -INSERT INTO "NEXT_LOCK_ID" VALUES(1); CREATE TABLE "COMPACTION_QUEUE" ( "CQ_ID" bigint PRIMARY KEY, diff --git standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql index b90cecb173..28c44907fe 100644 --- standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql +++ standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql @@ -203,6 +203,17 @@ ALTER TABLE "DBS" ADD "DB_MANAGED_LOCATION_URI" character varying(4000); ALTER TABLE "COMPACTION_QUEUE" ADD "CQ_NEXT_TXN_ID" bigint; DROP TABLE "MIN_HISTORY_LEVEL"; +-- HIVE-23236 +CREATE TABLE "TMP_NEXT_LOCK_ID" ( + "NL_NEXT" bigserial NOT NULL +); +INSERT INTO "TMP_NEXT_LOCK_ID" ("NL_NEXT") SELECT "NL_NEXT" FROM "NEXT_LOCK_ID"; +DROP TABLE "NEXT_LOCK_ID"; +ALTER TABLE "TMP_NEXT_LOCK_ID" RENAME TO "NEXT_LOCK_ID"; +CREATE SEQUENCE "LOCK_ID_SEQ" MINVALUE 0 OWNED BY "NEXT_LOCK_ID"."NL_NEXT"; +SELECT setval('"LOCK_ID_SEQ"', (SELECT MAX("NL_NEXT") FROM "NEXT_LOCK_ID")); +ALTER TABLE "NEXT_LOCK_ID" ALTER "NL_NEXT" SET DEFAULT nextval('"LOCK_ID_SEQ"'); + -- These lines need to be last. Insert any changes above. UPDATE "VERSION" SET "SCHEMA_VERSION"='4.0.0', "VERSION_COMMENT"='Hive release version 4.0.0' where "VER_ID"=1; SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0';