sumitagrawl commented on code in PR #7517: URL: https://github.com/apache/ozone/pull/7517#discussion_r1900530755
########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/ReconTaskStatusTableUpgradeAction.java: ########## @@ -0,0 +1,74 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.ozone.recon.upgrade; + +import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade; +import org.jooq.DSLContext; +import org.jooq.exception.DataAccessException; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.hadoop.ozone.recon.codegen.SqlDbUtils.TABLE_EXISTS_CHECK; +import static org.hadoop.ozone.recon.schema.ReconTaskSchemaDefinition.RECON_TASK_STATUS_TABLE_NAME; + + +/** + * Upgrade action for TASK_STATUS_STATISTICS feature layout change, which adds + * <code>last_task_run_status</code> and <code>current_task_run_status</code> columns to + * {@link org.hadoop.ozone.recon.schema.ReconTaskSchemaDefinition} in case it is missing . + */ +@UpgradeActionRecon(feature = ReconLayoutFeature.TASK_STATUS_STATISTICS, + type = ReconUpgradeAction.UpgradeActionType.FINALIZE) +public class ReconTaskStatusTableUpgradeAction implements ReconUpgradeAction { + + public static final Logger LOG = LoggerFactory.getLogger(ReconTaskStatusTableUpgradeAction.class); + + @Override + public void execute(ReconStorageContainerManagerFacade scmFacade) throws DataAccessException { + DataSource dataSource = scmFacade.getDataSource(); + try (Connection conn = dataSource.getConnection()) { + if (!TABLE_EXISTS_CHECK.test(conn, RECON_TASK_STATUS_TABLE_NAME)) { + return; + } + + DSLContext dslContext = DSL.using(conn); + // JOOQ doesn't support Derby DB officially, there is no way to run 'ADD COLUMN' command in single call + // for multiple columns. Hence, we run it as two separate steps. + LOG.info("Adding 'last_task_run_status' column to task status table"); + dslContext.alterTable(RECON_TASK_STATUS_TABLE_NAME) + .addColumn("last_task_run_status", SQLDataType.INTEGER).execute(); + LOG.info("Adding 'current_task_run_status' column to task status table"); Review Comment: what is default value in alterTable adding column ? ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/ReconTaskStatusTableUpgradeAction.java: ########## @@ -0,0 +1,74 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.ozone.recon.upgrade; + +import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade; +import org.jooq.DSLContext; +import org.jooq.exception.DataAccessException; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.hadoop.ozone.recon.codegen.SqlDbUtils.TABLE_EXISTS_CHECK; +import static org.hadoop.ozone.recon.schema.ReconTaskSchemaDefinition.RECON_TASK_STATUS_TABLE_NAME; + + +/** + * Upgrade action for TASK_STATUS_STATISTICS feature layout change, which adds + * <code>last_task_run_status</code> and <code>current_task_run_status</code> columns to + * {@link org.hadoop.ozone.recon.schema.ReconTaskSchemaDefinition} in case it is missing . + */ +@UpgradeActionRecon(feature = ReconLayoutFeature.TASK_STATUS_STATISTICS, + type = ReconUpgradeAction.UpgradeActionType.FINALIZE) +public class ReconTaskStatusTableUpgradeAction implements ReconUpgradeAction { + + public static final Logger LOG = LoggerFactory.getLogger(ReconTaskStatusTableUpgradeAction.class); + + @Override + public void execute(ReconStorageContainerManagerFacade scmFacade) throws DataAccessException { + DataSource dataSource = scmFacade.getDataSource(); + try (Connection conn = dataSource.getConnection()) { + if (!TABLE_EXISTS_CHECK.test(conn, RECON_TASK_STATUS_TABLE_NAME)) { + return; + } + + DSLContext dslContext = DSL.using(conn); + // JOOQ doesn't support Derby DB officially, there is no way to run 'ADD COLUMN' command in single call + // for multiple columns. Hence, we run it as two separate steps. + LOG.info("Adding 'last_task_run_status' column to task status table"); + dslContext.alterTable(RECON_TASK_STATUS_TABLE_NAME) + .addColumn("last_task_run_status", SQLDataType.INTEGER).execute(); + LOG.info("Adding 'current_task_run_status' column to task status table"); + dslContext.alterTable(RECON_TASK_STATUS_TABLE_NAME) Review Comment: same column added twice, 2 colume added, but here copy-paste mistake, .column("last_task_run_status", SQLDataType.INTEGER) .column("is_current_task_running", SQLDataType.INTEGER) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
