Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions phoenix-core-client/src/main/antlr3/PhoenixSQL.g
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ tokens
REGIONS = 'regions';
NOVERIFY = 'noverify';
RETURNING = 'returning';
REOPEN_REGIONS = 'reopen_regions';
}


Expand Down Expand Up @@ -699,8 +700,8 @@ drop_cdc_node returns [DropCDCStatement ret]
// Parse a alter index statement
alter_index_node returns [AlterIndexStatement ret]
: ALTER INDEX (IF ex=EXISTS)? i=index_name ON t=from_table_name
((s=(USABLE | UNUSABLE | REBUILD (isRebuildAll=ALL)? | DISABLE | ACTIVE)) (async=ASYNC)? ((SET?)p=fam_properties)?)
{ret = factory.alterIndex(factory.namedTable(null, TableName.create(t.getSchemaName(), i.getName())), t.getTableName(), ex!=null, PIndexState.valueOf(SchemaUtil.normalizeIdentifier(s.getText())), isRebuildAll!=null, async!=null, p); }
((s=(USABLE | UNUSABLE | REBUILD (isRebuildAll=ALL)? | DISABLE | ACTIVE)) (async=ASYNC)? ((SET?)p=fam_properties)? (REOPEN_REGIONS EQ reopen=literal)?)
{Boolean reopenRegions = reopen != null ? (Boolean)reopen.getValue() : null; ret = factory.alterIndex(factory.namedTable(null, TableName.create(t.getSchemaName(), i.getName())), t.getTableName(), ex!=null, PIndexState.valueOf(SchemaUtil.normalizeIdentifier(s.getText())), isRebuildAll!=null, async!=null, p, reopenRegions); }
;

// Parse a trace statement.
Expand Down Expand Up @@ -749,8 +750,8 @@ alter_session_node returns [AlterSessionStatement ret]
// Parse an alter table statement.
alter_table_node returns [AlterTableStatement ret]
: ALTER (TABLE | v=VIEW) t=from_table_name
( (DROP COLUMN (IF ex=EXISTS)? c=column_names) | (ADD (IF NOT ex=EXISTS)? (d=column_defs) (p=fam_properties)?) (cas=CASCADE INDEX (list=indexes | all=ALL))? | (SET (p=fam_properties)) )
{ PTableType tt = v==null ? (QueryConstants.SYSTEM_SCHEMA_NAME.equals(t.getSchemaName()) ? PTableType.SYSTEM : PTableType.TABLE) : PTableType.VIEW; ret = ( c == null ? factory.addColumn(factory.namedTable(null,t), tt, d, ex!=null, p, cas!=null, (all == null ? list : null)) : factory.dropColumn(factory.namedTable(null,t), tt, c, ex!=null) ); }
( (DROP COLUMN (IF ex=EXISTS)? c=column_names) | (ADD (IF NOT ex=EXISTS)? (d=column_defs) (p=fam_properties)?) (cas=CASCADE INDEX (list=indexes | all=ALL))? | (SET (p=fam_properties) (REOPEN_REGIONS EQ reopen=literal)?) )
{ PTableType tt = v==null ? (QueryConstants.SYSTEM_SCHEMA_NAME.equals(t.getSchemaName()) ? PTableType.SYSTEM : PTableType.TABLE) : PTableType.VIEW; Boolean reopenRegions = reopen != null ? (Boolean)reopen.getValue() : null; ret = ( c == null ? factory.addColumn(factory.namedTable(null,t), tt, d, ex!=null, p, cas!=null, (all == null ? list : null), reopenRegions) : factory.dropColumn(factory.namedTable(null,t), tt, c, ex!=null) ); }
;

update_statistics_node returns [UpdateStatisticsStatement ret]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1858,8 +1858,9 @@ private static class ExecutableAlterIndexStatement extends AlterIndexStatement

public ExecutableAlterIndexStatement(NamedTableNode indexTableNode, String dataTableName,
boolean ifExists, PIndexState state, boolean isRebuildAll, boolean async,
ListMultimap<String, Pair<String, Object>> props) {
super(indexTableNode, dataTableName, ifExists, state, isRebuildAll, async, props);
ListMultimap<String, Pair<String, Object>> props, Boolean reopenRegions) {
super(indexTableNode, dataTableName, ifExists, state, isRebuildAll, async, props,
reopenRegions);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -2054,8 +2055,9 @@ private static class ExecutableAddColumnStatement extends AddColumnStatement

ExecutableAddColumnStatement(NamedTableNode table, PTableType tableType,
List<ColumnDef> columnDefs, boolean ifNotExists,
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes) {
super(table, tableType, columnDefs, ifNotExists, props, cascade, indexes);
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes,
Boolean reopenRegions) {
super(table, tableType, columnDefs, ifNotExists, props, cascade, indexes, reopenRegions);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -2253,9 +2255,10 @@ public CreateIndexStatement createIndex(NamedNode indexName, NamedTableNode data
@Override
public AddColumnStatement addColumn(NamedTableNode table, PTableType tableType,
List<ColumnDef> columnDefs, boolean ifNotExists,
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes) {
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes,
Boolean reopenRegions) {
return new ExecutableAddColumnStatement(table, tableType, columnDefs, ifNotExists, props,
cascade, indexes);
cascade, indexes, reopenRegions);
}

@Override
Expand Down Expand Up @@ -2299,9 +2302,9 @@ public DropCDCStatement dropCDC(NamedNode cdcObjName, TableName tableName, boole
@Override
public AlterIndexStatement alterIndex(NamedTableNode indexTableNode, String dataTableName,
boolean ifExists, PIndexState state, boolean isRebuildAll, boolean async,
ListMultimap<String, Pair<String, Object>> props) {
ListMultimap<String, Pair<String, Object>> props, Boolean reopenRegions) {
return new ExecutableAlterIndexStatement(indexTableNode, dataTableName, ifExists, state,
isRebuildAll, async, props);
isRebuildAll, async, props, reopenRegions);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ public class AddColumnStatement extends AlterTableStatement {
private final ListMultimap<String, Pair<String, Object>> props;
private final boolean cascade;
private final List<NamedNode> indexes;
// boolean indicating whether to reopen regions after this alter statement is executed.
private final boolean reopenRegions;

protected AddColumnStatement(NamedTableNode table, PTableType tableType,
List<ColumnDef> columnDefs, boolean ifNotExists,
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes) {
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes,
Boolean reopenRegions) {
super(table, tableType);
this.columnDefs = columnDefs;
this.props = props == null ? ImmutableListMultimap.<String, Pair<String, Object>> of() : props;
this.ifNotExists = ifNotExists;
this.cascade = cascade;
this.indexes = indexes;
this.reopenRegions = reopenRegions != null ? reopenRegions : true;
}

protected AddColumnStatement(NamedTableNode table, PTableType tableType,
List<ColumnDef> columnDefs, boolean ifNotExists,
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes) {
this(table, tableType, columnDefs, ifNotExists, props, cascade, indexes, true);
}

public List<ColumnDef> getColumnDefs() {
Expand All @@ -61,4 +71,8 @@ public boolean isCascade() {
public List<NamedNode> getIndexes() {
return indexes;
}

public boolean getReopenRegions() {
return reopenRegions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class AlterIndexStatement extends SingleTableStatement {
private boolean isRebuildAll;
private ListMultimap<String, Pair<String, Object>> props;
private static final PTableType tableType = PTableType.INDEX;
// boolean indicating whether to reopen regions after this alter statement is executed.
private final boolean reopenRegions;

public AlterIndexStatement(NamedTableNode indexTableNode, String dataTableName, boolean ifExists,
PIndexState indexState, boolean isRebuildAll, boolean async) {
Expand All @@ -41,13 +43,20 @@ public AlterIndexStatement(NamedTableNode indexTableNode, String dataTableName,
public AlterIndexStatement(NamedTableNode indexTableNode, String dataTableName, boolean ifExists,
PIndexState indexState, boolean isRebuildAll, boolean async,
ListMultimap<String, Pair<String, Object>> props) {
this(indexTableNode, dataTableName, ifExists, indexState, isRebuildAll, async, props, true);
}

public AlterIndexStatement(NamedTableNode indexTableNode, String dataTableName, boolean ifExists,
PIndexState indexState, boolean isRebuildAll, boolean async,
ListMultimap<String, Pair<String, Object>> props, Boolean reopenRegions) {
super(indexTableNode, 0);
this.dataTableName = dataTableName;
this.ifExists = ifExists;
this.indexState = indexState;
this.async = async;
this.isRebuildAll = isRebuildAll;
this.props = props == null ? ImmutableListMultimap.<String, Pair<String, Object>> of() : props;
this.reopenRegions = reopenRegions != null ? reopenRegions : true;
}

public String getTableName() {
Expand Down Expand Up @@ -82,4 +91,8 @@ public ListMultimap<String, Pair<String, Object>> getProps() {
public PTableType getTableType() {
return tableType;
}

public boolean getReopenRegions() {
return reopenRegions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,10 @@ public SequenceValueParseNode nextValueFor(TableName tableName, ParseNode numToA

public AddColumnStatement addColumn(NamedTableNode table, PTableType tableType,
List<ColumnDef> columnDefs, boolean ifNotExists,
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes) {
ListMultimap<String, Pair<String, Object>> props, boolean cascade, List<NamedNode> indexes,
Boolean reopenRegions) {
return new AddColumnStatement(table, tableType, columnDefs, ifNotExists, props, cascade,
indexes);
indexes, reopenRegions);
}

public DropColumnStatement dropColumn(NamedTableNode table, PTableType tableType,
Expand All @@ -465,9 +466,9 @@ public DropCDCStatement dropCDC(NamedNode cdcObjName, TableName tableName, boole

public AlterIndexStatement alterIndex(NamedTableNode indexTableNode, String dataTableName,
boolean ifExists, PIndexState state, boolean isRebuildAll, boolean async,
ListMultimap<String, Pair<String, Object>> props) {
ListMultimap<String, Pair<String, Object>> props, Boolean reopenRegions) {
return new AlterIndexStatement(indexTableNode, dataTableName, ifExists, state, isRebuildAll,
async, props);
async, props, reopenRegions);
}

public AlterIndexStatement alterIndex(NamedTableNode indexTableNode, String dataTableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public MetaDataMutationResult dropFunction(List<Mutation> tableMetadata, boolean
public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table,
PTable parentTable, PTable transformingNewTable,
Map<String, List<Pair<String, Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded,
List<PColumn> columns) throws SQLException;
List<PColumn> columns, boolean reopenRegions) throws SQLException;

public MetaDataMutationResult dropColumn(List<Mutation> tableMetadata, PTableType tableType,
PTable parentTable) throws SQLException;
Expand All @@ -183,8 +183,8 @@ public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata,
String parentTableName) throws SQLException;

public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata,
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table)
throws SQLException;
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table,
boolean reopenRegions) throws SQLException;

public MutationState updateData(MutationPlan plan) throws SQLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ private TableDescriptor ensureTableCreated(byte[] physicalTableName,

// Do not call modifyTable for SYSTEM tables
if (tableType != PTableType.SYSTEM) {
modifyTable(physicalTableName, newDesc.build(), true);
modifyTable(physicalTableName, newDesc.build(), true, true);
}
return result;
}
Expand Down Expand Up @@ -2128,16 +2128,17 @@ private static boolean equalTxCoprocessor(TransactionFactory.Provider provider,
&& newDesc.hasCoprocessor(coprocessorClassName));
}

private void modifyTable(byte[] tableName, TableDescriptor newDesc, boolean shouldPoll)
private void modifyTable(byte[] tableName, TableDescriptor newDesc, boolean shouldPoll,
boolean reopenRegions)
throws IOException, InterruptedException, TimeoutException, SQLException {
TableName tn = TableName.valueOf(tableName);
try (Admin admin = getAdmin()) {
if (!allowOnlineTableSchemaUpdate()) {
disableTable(admin, tn);
admin.modifyTable(newDesc); // TODO: Update to TableDescriptor
admin.modifyTable(newDesc, reopenRegions); // TODO: Update to TableDescriptor
admin.enableTable(tn);
} else {
admin.modifyTable(newDesc); // TODO: Update to TableDescriptor
admin.modifyTable(newDesc, reopenRegions); // TODO: Update to TableDescriptor
if (shouldPoll) {
pollForUpdatedTableDescriptor(admin, newDesc, tableName);
}
Expand Down Expand Up @@ -2936,7 +2937,8 @@ private void ensureViewIndexTableCreated(PTable table, long timestamp, boolean i
public MetaDataMutationResult addColumn(final List<Mutation> tableMetaData, PTable table,
final PTable parentTable, final PTable transformingNewTable,
Map<String, List<Pair<String, Object>>> stmtProperties,
Set<String> colFamiliesForPColumnsToBeAdded, List<PColumn> columns) throws SQLException {
Set<String> colFamiliesForPColumnsToBeAdded, List<PColumn> columns, boolean reopenRegions)
throws SQLException {
List<Pair<byte[], Map<String, Object>>> families = new ArrayList<>(stmtProperties.size());
Map<String, Object> tableProps = new HashMap<>();
Set<TableDescriptor> tableDescriptors = Collections.emptySet();
Expand Down Expand Up @@ -2998,7 +3000,7 @@ public MetaDataMutationResult addColumn(final List<Mutation> tableMetaData, PTab
(tableMetaData.isEmpty()) || (tableMetaData.size() == 1 && tableMetaData.get(0).isEmpty())
) {
if (modifyHTable) {
sendHBaseMetaData(tableDescriptors, pollingNeeded);
sendHBaseMetaData(tableDescriptors, pollingNeeded, reopenRegions);
}
return new MetaDataMutationResult(MutationCode.NO_OP,
EnvironmentEdgeManager.currentTimeMillis(), table);
Expand Down Expand Up @@ -3076,7 +3078,7 @@ public MetaDataResponse call(MetaDataService instance) throws IOException {
}

if (modifyHTable && result.getMutationCode() != MutationCode.UNALLOWED_TABLE_MUTATION) {
sendHBaseMetaData(tableDescriptors, pollingNeeded);
sendHBaseMetaData(tableDescriptors, pollingNeeded, reopenRegions);
}
} finally {
// If we weren't successful with our metadata update
Expand All @@ -3086,7 +3088,7 @@ public MetaDataResponse call(MetaDataService instance) throws IOException {
// no longer function correctly.
// Note that if this fails, we're in a corrupt state.
if (!success && metaDataUpdated && nonTxToTx) {
sendHBaseMetaData(origTableDescriptors, pollingNeeded);
sendHBaseMetaData(origTableDescriptors, pollingNeeded, reopenRegions);
}
}
return result;
Expand Down Expand Up @@ -3234,12 +3236,12 @@ private void setSharedIndexMaxVersion(PTable table, TableDescriptor tableDescrip
}
}

private void sendHBaseMetaData(Set<TableDescriptor> tableDescriptors, boolean pollingNeeded)
throws SQLException {
private void sendHBaseMetaData(Set<TableDescriptor> tableDescriptors, boolean pollingNeeded,
boolean reopenRegions) throws SQLException {
SQLException sqlE = null;
for (TableDescriptor descriptor : tableDescriptors) {
try {
modifyTable(descriptor.getTableName().getName(), descriptor, pollingNeeded);
modifyTable(descriptor.getTableName().getName(), descriptor, pollingNeeded, reopenRegions);
} catch (IOException e) {
sqlE = ClientUtil.parseServerException(e);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -5391,7 +5393,7 @@ private PhoenixConnection addColumnQualifierColumn(PhoenixConnection oldMetaConn
metaConnection.rollback();
metaConnection.getQueryServices().addColumn(tableMetadata, sysCatalogPTable, null, null,
Collections.<String, List<Pair<String, Object>>> emptyMap(), Collections.<String> emptySet(),
Lists.newArrayList(column));
Lists.newArrayList(column), true);
metaConnection.removeTable(null, SYSTEM_CATALOG_NAME, null, timestamp);
ConnectionQueryServicesImpl.this.removeTable(null, SYSTEM_CATALOG_NAME, null, timestamp);
clearCache();
Expand Down Expand Up @@ -5920,8 +5922,8 @@ public MetaDataResponse call(MetaDataService instance) throws IOException {

@Override
public MetaDataMutationResult updateIndexState(final List<Mutation> tableMetaData,
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table)
throws SQLException {
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table,
boolean reopenRegions) throws SQLException {
if (stmtProperties == null) {
return updateIndexState(tableMetaData, parentTableName);
}
Expand All @@ -5936,7 +5938,7 @@ public MetaDataMutationResult updateIndexState(final List<Mutation> tableMetaDat
modifiedTableDescriptors = Sets.newHashSetWithExpectedSize(3 + table.getIndexes().size());
modifiedTableDescriptors.add(newTableDescriptor);
}
sendHBaseMetaData(modifiedTableDescriptors, true);
sendHBaseMetaData(modifiedTableDescriptors, true, reopenRegions);
return updateIndexState(tableMetaData, parentTableName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public MetaDataMutationResult dropTable(List<Mutation> tableMetadata, PTableType
public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table,
PTable parentTable, PTable transformingNewTable,
Map<String, List<Pair<String, Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded,
List<PColumn> columnsToBeAdded) throws SQLException {
List<PColumn> columnsToBeAdded, boolean reopenRegion) throws SQLException {
List<PColumn> columns = Lists.newArrayList(table.getColumns());
columns.addAll(columnsToBeAdded);
return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0,
Expand Down Expand Up @@ -573,8 +573,8 @@ public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata,

@Override
public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata,
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table)
throws SQLException {
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table,
boolean reopenRegions) throws SQLException {
return updateIndexState(tableMetadata, parentTableName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ public MetaDataMutationResult dropTable(List<Mutation> tabeMetaData, PTableType
public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table,
PTable parentTable, PTable transformingNewTable,
Map<String, List<Pair<String, Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded,
List<PColumn> columns) throws SQLException {
List<PColumn> columns, boolean reopenRegions) throws SQLException {
return getDelegate().addColumn(tableMetaData, table, parentTable, transformingNewTable,
properties, colFamiliesForPColumnsToBeAdded, columns);
properties, colFamiliesForPColumnsToBeAdded, columns, reopenRegions);
}

@Override
Expand All @@ -193,9 +193,10 @@ public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata,

@Override
public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata,
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table)
throws SQLException {
return getDelegate().updateIndexState(tableMetadata, parentTableName, stmtProperties, table);
String parentTableName, Map<String, List<Pair<String, Object>>> stmtProperties, PTable table,
boolean reopenRegions) throws SQLException {
return getDelegate().updateIndexState(tableMetadata, parentTableName, stmtProperties, table,
reopenRegions);
}

@Override
Expand Down
Loading