Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharding error when inserting data into ShardingSphere-Proxy with AlloyDB #34725

Open
TheMasterRoot opened this issue Feb 19, 2025 · 0 comments

Comments

@TheMasterRoot
Copy link

Sharding error when inserting data into ShardingSphere-Proxy with AlloyDB

I am using ShardingSphere-Proxy with AlloyDB and I am facing an error when trying to insert data into the ni_contribuinte table.

Error when executing an INSERT:

rtc_db_des_aa=> INSERT INTO identifier(identifier) VALUES ('1a2b3c4d5e');
ERROR: Inline sharding algorithms expression 'shard_${(abs(identifier.hashCode())) % 5}' and sharding column 'identifier' do not match.

My table schema is as follows:

Table "identifier" {
"identifier" "character varying(14)" [pk, not null]
}

And my ShardingSphere configuration is as follows:

databaseName: rtc_db_des_aa
dataSources:
shard_0:
url: jdbc:postgresql://10.0.0.2:5432/rtc_db_des_aa
username: postgres
password: "pass"
shard_1:
url: jdbc:postgresql://10.0.0.7:5432/rtc_db_des_aa
username: postgres
password: "pass"
shard_2:
url: jdbc:postgresql://10.0.0.8:5432/rtc_db_des_aa
 username: postgres
 password: "pass"
 shard_3:
 url: jdbc:postgresql://10.0.0.9:5432/rtc_db_des_aa
 username: postgres
 password: "pass"
 shard_4:
 url: jdbc:postgresql://10.0.0.10:5432/rtc_db_des_aa
 username: postgres
 password: "pass"

rules:
 - !SHARDING
 tables:
 identifier:
 actualDataNodes: shard_${0..4}.identifier
 tableStrategy:
 standard:
 shardingColumn: identifier
 shardingAlgorithmName: hash_inline

 shardingAlgorithms:
hash_inline:
type: INLINE
props:
sharding-count: 5
algorithm-expression: shard_${(abs(identifier.hashCode())) % 5}

From the error, it seems that the sharding expression is not being applied correctly to the identifier column. What could be causing this?

I have already tried:

  • Making sure that the identifier column is correctly set to character varying(14).
  • Testing other sharding expressions, but I still get the same error.

Could someone help me understand what the problem might be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant