diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core-client/src/main/java/org/apache/phoenix/index/IndexMaintainer.java index ec7fc73b676..b3ea9856e97 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/index/IndexMaintainer.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/index/IndexMaintainer.java @@ -397,6 +397,7 @@ public static IndexMaintainer getIndexMaintainer(List maintaine private RowKeyMetaData rowKeyMetaData; private byte[] indexTableName; private int nIndexSaltBuckets; + private int nDataTableSaltBuckets; private byte[] dataEmptyKeyValueCF; private ImmutableBytesPtr emptyKeyValueCFPtr; private int nDataCFs; @@ -470,6 +471,7 @@ private IndexMaintainer(final PTable dataTable, final PTable cdcTable, final PTa this.immutableStorageScheme = index.getImmutableStorageScheme() == null ? ImmutableStorageScheme.ONE_CELL_PER_COLUMN : index.getImmutableStorageScheme(); this.dataEncodingScheme = dataTable.getEncodingScheme() == null ? QualifierEncodingScheme.NON_ENCODED_QUALIFIERS : dataTable.getEncodingScheme(); this.dataImmutableStorageScheme = dataTable.getImmutableStorageScheme() == null ? ImmutableStorageScheme.ONE_CELL_PER_COLUMN : dataTable.getImmutableStorageScheme(); + this.nDataTableSaltBuckets = isDataTableSalted ? dataTable.getBucketNum() : PTable.NO_SALTING; byte[] indexTableName = index.getPhysicalName().getBytes(); // Use this for the nDataSaltBuckets as we need this for local indexes @@ -538,7 +540,7 @@ private IndexMaintainer(final PTable dataTable, final PTable cdcTable, final PTa this.indexedColumnTypes = Lists.newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns); this.indexedExpressions = Lists.newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns); this.coveredColumnsMap = Maps.newHashMapWithExpectedSize(nIndexColumns - nIndexPKColumns); - this.nIndexSaltBuckets = nIndexSaltBuckets == null ? 0 : nIndexSaltBuckets; + this.nIndexSaltBuckets = nIndexSaltBuckets == null ? PTable.NO_SALTING : nIndexSaltBuckets; this.dataEmptyKeyValueCF = SchemaUtil.getEmptyColumnFamily(dataTable); this.emptyKeyValueCFPtr = SchemaUtil.getEmptyColumnFamilyPtr(index); this.nDataCFs = dataTable.getColumnFamilies().size(); @@ -918,14 +920,11 @@ public byte[] buildDataRowKey(ImmutableBytesWritable indexRowKeyPtr, byte[][] vi length--; trailingVariableWidthColumnNum--; } - // TODO: need to capture nDataSaltBuckets instead of just a boolean. For now, - // we store this in nIndexSaltBuckets, as we only use this function for local indexes - // in which case nIndexSaltBuckets would never be used. Note that when we do add this - // to be serialized, we have to add it at the end and allow for the value not being - // there to maintain compatibility between an old client and a new server. if (isDataTableSalted) { // Set salt byte - byte saltByte = SaltingUtil.getSaltingByte(dataRowKey, SaltingUtil.NUM_SALTING_BYTES, length-SaltingUtil.NUM_SALTING_BYTES, nIndexSaltBuckets); + byte saltByte = SaltingUtil.getSaltingByte(dataRowKey, + SaltingUtil.NUM_SALTING_BYTES, length-SaltingUtil.NUM_SALTING_BYTES, + nDataTableSaltBuckets); dataRowKey[0] = saltByte; } return dataRowKey.length == length ? dataRowKey : Arrays.copyOf(dataRowKey, length); @@ -1789,6 +1788,8 @@ public static IndexMaintainer fromProto(ServerCachingProtos.IndexMaintainer prot } else { maintainer.isCDCIndex = false; } + maintainer.nDataTableSaltBuckets = proto.hasDataTableSaltBuckets() ? + proto.getDataTableSaltBuckets() : -1; maintainer.initCachedState(); return maintainer; } @@ -1933,6 +1934,9 @@ public static ServerCachingProtos.IndexMaintainer toProto(IndexMaintainer mainta } } builder.setIsCDCIndex(maintainer.isCDCIndex); + if (maintainer.isDataTableSalted) { + builder.setDataTableSaltBuckets(maintainer.nDataTableSaltBuckets); + } return builder.build(); } diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTable.java index d1d7d5227f4..c51292a8ae8 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTable.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTable.java @@ -63,6 +63,7 @@ public interface PTable extends PMetaDataEntity { public static final String IS_IMMUTABLE_ROWS_PROP_NAME = "IMMUTABLE_ROWS"; public static final boolean DEFAULT_DISABLE_WAL = false; public static final boolean DEFAULT_IMMUTABLE_ROWS = false; + static final Integer NO_SALTING = -1; public enum ViewType { MAPPED((byte)1), diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTableImpl.java index b056db84f97..a94b7d3d33b 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTableImpl.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTableImpl.java @@ -142,7 +142,6 @@ * @since 0.1 */ public class PTableImpl implements PTable { - private static final Integer NO_SALTING = -1; private static final int VIEW_MODIFIED_UPDATE_CACHE_FREQUENCY_BIT_SET_POS = 0; private static final int VIEW_MODIFIED_USE_STATS_FOR_PARALLELIZATION_BIT_SET_POS = 1; private static final int VIEW_MODIFIED_PHOENIX_TTL_BIT_SET_POS = 2; diff --git a/phoenix-core-client/src/main/protobuf/ServerCachingService.proto b/phoenix-core-client/src/main/protobuf/ServerCachingService.proto index c28695ff7dd..d8e19455273 100644 --- a/phoenix-core-client/src/main/protobuf/ServerCachingService.proto +++ b/phoenix-core-client/src/main/protobuf/ServerCachingService.proto @@ -72,6 +72,7 @@ message IndexMaintainer { optional bytes indexWhere = 29; repeated ColumnReference indexWhereColumns = 30; optional bool isCDCIndex = 31; + optional int32 dataTableSaltBuckets = 32; } message TransformMaintainer {