This is an automated email from the ASF dual-hosted git repository.
tkhurana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 75b18ffabb PHOENIX-7239: Fix issues when data and index have different
salt buckets (#1988)
75b18ffabb is described below
commit 75b18ffabbf49094e8fcceb1a26305cb01439d44
Author: Hari Krishna Dara <[email protected]>
AuthorDate: Sun Sep 29 00:09:39 2024 +0530
PHOENIX-7239: Fix issues when data and index have different salt buckets
(#1988)
@PHOENIX-7239: Fix issues when data and index have different salt buckets
---
.../java/org/apache/phoenix/index/IndexMaintainer.java | 18 +++++++++++-------
.../main/java/org/apache/phoenix/schema/PTable.java | 1 +
.../java/org/apache/phoenix/schema/PTableImpl.java | 1 -
.../src/main/protobuf/ServerCachingService.proto | 1 +
4 files changed, 13 insertions(+), 8 deletions(-)
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 c4641263ab..97a0ca785c 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
@@ -404,6 +404,7 @@ public class IndexMaintainer implements Writable,
Iterable<ColumnReference> {
private RowKeyMetaData rowKeyMetaData;
private byte[] indexTableName;
private int nIndexSaltBuckets;
+ private int nDataTableSaltBuckets;
private byte[] dataEmptyKeyValueCF;
private ImmutableBytesPtr emptyKeyValueCFPtr;
private int nDataCFs;
@@ -477,6 +478,7 @@ public class IndexMaintainer implements Writable,
Iterable<ColumnReference> {
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
@@ -545,7 +547,7 @@ public class IndexMaintainer implements Writable,
Iterable<ColumnReference> {
this.indexedColumnTypes =
Lists.<PDataType>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();
@@ -977,14 +979,11 @@ public class IndexMaintainer implements Writable,
Iterable<ColumnReference> {
trailingVariableWidthColumnNum--;
indexColumnIdx--;
}
- // 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);
@@ -1848,6 +1847,8 @@ public class IndexMaintainer implements Writable,
Iterable<ColumnReference> {
} else {
maintainer.isCDCIndex = false;
}
+ maintainer.nDataTableSaltBuckets = proto.hasDataTableSaltBuckets() ?
+ proto.getDataTableSaltBuckets() : -1;
maintainer.initCachedState();
return maintainer;
}
@@ -1992,6 +1993,9 @@ public class IndexMaintainer implements Writable,
Iterable<ColumnReference> {
}
}
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 9c487f5bd0..4ace717a06 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 d1b5ee4ceb..8caa0f72e6 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
@@ -206,7 +206,6 @@ import org.apache.phoenix.util.TrustedByteArrayOutputStream;
* @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 IndexMaintainer indexMaintainer;
diff --git a/phoenix-core-client/src/main/protobuf/ServerCachingService.proto
b/phoenix-core-client/src/main/protobuf/ServerCachingService.proto
index c28695ff7d..d8e1945527 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 {