use of org.apache.phoenix.schema.ConcurrentTableMutationException in project phoenix by apache.
the class PhoenixRecordUpdater method close.
/* (non-Javadoc)
* @see org.apache.hadoop.hive.ql.io.RecordUpdater#close(boolean)
*/
@Override
public void close(boolean abort) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("abort : " + abort);
}
try {
conn.commit();
if (LOG.isInfoEnabled()) {
LOG.info("Written row : " + numRecords);
}
} catch (SQLException e) {
LOG.error("SQLException while performing the commit for the task.");
throw new IOException(e);
} finally {
try {
if (restoreWalMode && PhoenixUtil.isDisabledWal(metaDataClient, tableName)) {
try {
PhoenixUtil.alterTableForWalDisable(conn, tableName, false);
} catch (ConcurrentTableMutationException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Concurrent modification of disableWAL");
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(tableName + "s wal enabled.");
}
}
// flush when [table-name].auto.flush is true.
String autoFlushConfigName = tableName.toLowerCase() + PhoenixStorageHandlerConstants.AUTO_FLUSH;
boolean autoFlush = config.getBoolean(autoFlushConfigName, false);
if (autoFlush) {
if (LOG.isDebugEnabled()) {
LOG.debug("autoFlush is " + autoFlush);
}
PhoenixUtil.flush(conn, tableName);
}
PhoenixUtil.closeResource(pstmt);
PhoenixUtil.closeResource(pstmtForDelete);
PhoenixUtil.closeResource(conn);
} catch (SQLException ex) {
LOG.error("SQLException while closing the connection for the task.");
throw new IOException(ex);
}
}
}
use of org.apache.phoenix.schema.ConcurrentTableMutationException in project phoenix by apache.
the class PhoenixRecordWriter method close.
@Override
public void close(Reporter reporter) throws IOException {
try {
conn.commit();
if (LOG.isInfoEnabled()) {
LOG.info("Wrote row : " + numRecords);
}
} catch (SQLException e) {
LOG.error("SQLException while performing the commit for the task.");
throw new IOException(e);
} finally {
try {
if (restoreWalMode && PhoenixUtil.isDisabledWal(metaDataClient, tableName)) {
try {
PhoenixUtil.alterTableForWalDisable(conn, tableName, false);
} catch (ConcurrentTableMutationException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Another mapper or task processing wal enable");
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(tableName + "s wal enabled.");
}
}
// flush if [table-name].auto.flush is true.
String autoFlushConfigName = tableName.toLowerCase() + PhoenixStorageHandlerConstants.AUTO_FLUSH;
boolean autoFlush = config.getBoolean(autoFlushConfigName, false);
if (autoFlush) {
if (LOG.isDebugEnabled()) {
LOG.debug("autoFlush is true.");
}
PhoenixUtil.flush(conn, tableName);
}
PhoenixUtil.closeResource(pstmt);
PhoenixUtil.closeResource(pstmtForDelete);
PhoenixUtil.closeResource(conn);
} catch (SQLException ex) {
LOG.error("SQLException while closing the connection for the task.");
throw new IOException(ex);
}
}
}
use of org.apache.phoenix.schema.ConcurrentTableMutationException in project phoenix by apache.
the class PhoenixRecordWriter method initialize.
private void initialize(Configuration config, Properties properties) throws SQLException {
this.config = config;
tableName = config.get(PhoenixStorageHandlerConstants.PHOENIX_TABLE_NAME);
// Disable WAL
String walConfigName = tableName.toLowerCase() + PhoenixStorageHandlerConstants.DISABLE_WAL;
boolean disableWal = config.getBoolean(walConfigName, false);
if (disableWal) {
if (LOG.isDebugEnabled()) {
LOG.debug("Property " + walConfigName + " is true. batch.mode will be set true. ");
}
properties.setProperty(PhoenixStorageHandlerConstants.BATCH_MODE, "true");
}
this.conn = PhoenixConnectionUtil.getInputConnection(config, properties);
if (disableWal) {
metaDataClient = new MetaDataClient((PhoenixConnection) conn);
if (!PhoenixUtil.isDisabledWal(metaDataClient, tableName)) {
// execute alter tablel statement if disable_wal is not true.
try {
PhoenixUtil.alterTableForWalDisable(conn, tableName, true);
} catch (ConcurrentTableMutationException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Another mapper or task processing wal disable");
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(tableName + "s wal disabled.");
}
// restore original value of disable_wal at the end.
restoreWalMode = true;
}
}
this.batchSize = PhoenixConfigurationUtil.getBatchSize(config);
if (LOG.isDebugEnabled()) {
LOG.debug("Batch-size : " + batchSize);
}
String upsertQuery = QueryUtil.constructUpsertStatement(tableName, PhoenixUtil.getColumnInfoList(conn, tableName));
if (LOG.isDebugEnabled()) {
LOG.debug("Upsert-query : " + upsertQuery);
}
this.pstmt = this.conn.prepareStatement(upsertQuery);
}
Aggregations