Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,14 @@ private TableDescriptorBuilder generateTableDescriptor(byte[] physicalTableName,
if (baseTableMaxLookbackVal != null) {
tableProps.put(PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY, baseTableMaxLookbackVal);
}
// PHOENIX-6868: Inherit configured custom table descriptor properties from base table
for (String inheritableProp :
MetaDataUtil.getInheritableTableDescriptorProperties(this.config)) {
String val = baseTableDesc.getValue(inheritableProp);
if (val != null) {
tableProps.put(inheritableProp, val);
}
}
dataTableColDescForIndexTablePropSyncing = baseTableDesc.getColumnFamily(defaultFamilyBytes);
// It's possible that the table has specific column families and none of them are declared
// to be the DEFAULT_COLUMN_FAMILY, so we choose the first column family for syncing
Expand Down Expand Up @@ -3358,6 +3366,13 @@ private Map<TableDescriptor, TableDescriptor> separateAndValidateProperties(PTab
}
newMaxLookback = (Integer) propValue;
}
// PHOENIX-6868: Disallow setting inheritable properties directly on index
if (table.getType() == PTableType.INDEX
&& MetaDataUtil.isInheritableTableDescriptorProperty(this.config, propName)) {
throw new SQLExceptionInfo.Builder(
SQLExceptionCode.CANNOT_SET_OR_ALTER_PROPERTY_FOR_INDEX)
.setMessage("Property: " + propName).build().buildException();
}
tableProps.put(propName, propValue);
} else {
if (TableProperty.isPhoenixTableProperty(propName)) {
Expand Down Expand Up @@ -3691,8 +3706,10 @@ private Map<TableDescriptor, TableDescriptor> separateAndValidateProperties(PTab
// Copy properties that need to be synced from the default column family of the base table to
// the column families of each of its indexes (including indexes on this base table's views)
// and store those table descriptor mappings as well
Map<String, Object> syncedTableDescProps = getNewSyncedPropsMapForTableDescriptor(
newMaxLookback, tableProps);
setSyncedPropertiesForTableIndexes(table, tableAndIndexDescriptorMappings,
applyPropsToAllIndexColFams, getNewSyncedPropsMapForTableDescriptor(newMaxLookback));
applyPropsToAllIndexColFams, syncedTableDescProps);
return tableAndIndexDescriptorMappings;
}

Expand Down Expand Up @@ -3797,13 +3814,21 @@ private Map<String, Object> getNewSyncedPropsMap(Integer newTTL,
return newSyncedProps;
}

private Map<String, Object> getNewSyncedPropsMapForTableDescriptor(Integer newMaxLookback) {
if (newMaxLookback == null) {
return null;
}
Map<String, Object> newSyncedProps = new HashMap<>(1);
private Map<String, Object> getNewSyncedPropsMapForTableDescriptor(Integer newMaxLookback,
Map<String, Object> tableProps) {
Map<String, Object> newSyncedProps = new HashMap<>();
setPropIfNotNull(newSyncedProps, PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY, newMaxLookback);
return newSyncedProps;
// PHOENIX-6868: Include any inheritable table descriptor properties that are being modified
List<String> inheritableProps =
MetaDataUtil.getInheritableTableDescriptorProperties(this.config);
if (tableProps != null) {
for (String prop : inheritableProps) {
if (tableProps.containsKey(prop)) {
newSyncedProps.put(prop, tableProps.get(prop));
}
}
}
return newSyncedProps.isEmpty() ? null : newSyncedProps;
}

/**
Expand Down Expand Up @@ -3877,6 +3902,7 @@ private void setSyncedPropertiesForTableIndexes(PTable table,
this.getTableDescriptor(Bytes.toBytes(viewIndexName));
TableDescriptorBuilder newViewIndexDescriptorBuilder =
TableDescriptorBuilder.newBuilder(origViewIndexTableDescriptor);
modifyTableDescriptor(newViewIndexDescriptorBuilder, applyPropsToAllIndexesTd);
for (ColumnFamilyDescriptor cfd : origViewIndexTableDescriptor.getColumnFamilies()) {
ColumnFamilyDescriptorBuilder newCfd = ColumnFamilyDescriptorBuilder.newBuilder(cfd);
modifyColumnFamilyDescriptor(newCfd, applyPropsToAllIndexesDefaultCF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public interface QueryServices extends SQLCloseable {

public static final String ALLOW_LOCAL_INDEX_ATTRIB = "phoenix.index.allowLocalIndex";

// See PHOENIX-6868: Comma-separated list of custom HBase table descriptor property keys that
// should be automatically inherited by index tables from their data table.
public static final String INDEX_INHERITABLE_TABLE_DESCRIPTOR_PROPERTIES =
"phoenix.index.inheritableTableDescriptorProperties";

// Timeout config for PhoenixSyncTableTool
String SYNC_TABLE_QUERY_TIMEOUT_ATTRIB = "phoenix.sync.table.query.timeout";
String SYNC_TABLE_RPC_TIMEOUT_ATTRIB = "phoenix.sync.table.rpc.timeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,14 @@ private void populatePropertyMaps(ListMultimap<String, Pair<String, Object>> sta
SQLExceptionCode.CANNOT_SET_OR_ALTER_UPDATE_CACHE_FREQ_FOR_INDEX).build()
.buildException();
}
// PHOENIX-6868: Disallow setting inheritable table descriptor properties on indexes
if (tableType == PTableType.INDEX && !isCDCIndex
&& MetaDataUtil.isInheritableTableDescriptorProperty(
connection.getQueryServices().getConfiguration(), prop.getFirst())) {
throw new SQLExceptionInfo.Builder(
SQLExceptionCode.CANNOT_SET_OR_ALTER_PROPERTY_FOR_INDEX)
.setMessage("Property: " + prop.getFirst()).build().buildException();
}
Comment on lines +1215 to +1222
tableProps.put(prop.getFirst(), prop.getSecond());
} else { // HColumnDescriptor property
commonFamilyProps.put(prop.getFirst(), prop.getSecond());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.ConditionalTTLExpression;
Expand Down Expand Up @@ -1021,6 +1022,37 @@ public static boolean propertyNotAllowedToBeOutOfSync(String colFamProp) {
return SYNCED_DATA_TABLE_AND_INDEX_COL_FAM_PROPERTIES.contains(colFamProp);
}

/**
* Get the list of inheritable table descriptor properties from configuration.
* See PHOENIX-6868.
* @param conf the configuration
* @return list of property names that should be inherited by indexes, or empty list if none
*/
public static List<String> getInheritableTableDescriptorProperties(Configuration conf) {
String propValue =
conf.get(QueryServices.INDEX_INHERITABLE_TABLE_DESCRIPTOR_PROPERTIES);
if (propValue == null || propValue.trim().isEmpty()) {
return Collections.emptyList();
}
List<String> result = new ArrayList<>();
for (String prop : propValue.split(",")) {
String trimmed = prop.trim();
if (!trimmed.isEmpty()) {
result.add(trimmed);
}
}
return result;
}

/**
* Check if a table descriptor property is configured as inheritable from data tables to indexes.
* See PHOENIX-6868.
*/
public static boolean isInheritableTableDescriptorProperty(Configuration conf,
String propName) {
return getInheritableTableDescriptorProperties(conf).contains(propName);
}

public static Map<String, Object> getSyncedProps(ColumnFamilyDescriptor defaultCFDesc) {
Map<String, Object> syncedProps = new HashMap<>();
if (defaultCFDesc != null) {
Expand Down
Loading