Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register


1
(click on this box to dismiss)

multiple shards configuration

Hi,

I have a master/slaves architecture and would like to use a x*master/slaves architecture with x the number of shards.

I want to send writes only to masters (based on the shards it hosts) and the reads to slaves (using a VIP). I think I'll use something like that :

[%shard_key]

0        20     0

21      40     1

100  120    2

121 140     3

with shard 0 = master 1, shard 1 = master 2, shard 2 = vip to slaves of master 1, shard 3 = vip to slaves of master 2
Do you think it's the right way to do it ?
I have a question concerning the name used to describe shard_key "[%shard_key]" , If I use the following query SELECT * FROM t WHERE id = /*+ shard_val(1) */ ?'
 will it work ? or must I use a [%id] section ? is the section [%shard_key] used when the [%column_name] section is not found ?
thanks 

link comment (0) accepted answer
asked last year
cscetbon
15
1 Answer
0

No, it's not the right way to do master-slave sharding in CUBRID.

  1. First of all the shard_key.txt configuration file is wrong. You must cover all ranges. In your case, the range 41-99 is missing as well as 141-255 in case you're using the default configurations.
    In CUBRID SHARD the default value of "SHARD_KEY_MODULAR" parameter in shard.conf file is 256. Which means that SHARD Broker will try to divide your shard_key value by 256. Since you shard_key.txt file doesn't define rules for values between 41-99 and 141-255, "Unable to get shard id. Invalid hint key range." error is displayed. So, for CUBRID SHARD to work properly, there are two solutions:
    1. You need to cover all ranges for the keys, i.e. from 0 to 255 in default case.
    2. Or set "SHARD_KEY_MODULAR" parameter in shard.conf file properly but still make sure you cover all ranges.
with shard 0 = master 1, shard 1 = master 2, shard 2 = vip to slaves of master 1, shard 3 = vip to slaves of master 2
Do you think it's the right way to do it ?

The above will occasionally work but highly likely generate many errors on INSERT because what happens if I try to insert a record with shard key = 100? It will try to insert into shard 2, but since shard 2 is slave, it doesn't accept WRITE operations. So your INSERT will fail.

If you want to distribute READ operations, the proper way to do this is through multiple Brokers. In sharding case, it's SHARD Brokers.

  1. Install two SHARD Brokers on two different machines/VMs.
  2. Configure ACCESS_MODE of one of them in RW (Read-Write) mode, the other in RO (Read-Only) mode.
  3. In RW SHARD Broker machine, define shard_id in shard_connection.txt file to point to Master nodes of your CUBRID databases.
  4. In RO SHARD Broker machine, define shard_id in shard_connection.txt file to point to Slave nodes of your CUBRID databases. Make sure slaves machines correctly related with master nodes of same shard_id in RW SHARD Broker machine.
  5. Then create same shard_key.txt file, cover all shard_key ranges, and point to all shards you want, i.e. shard 0..4.
  6. The shard.conf configuration file on both Broker machines should be almost identical except for ACCESS_MODE parameter.
  7. Now, once you correctly configured your Broker machines as RW and RO, you need to change your application to send queries to these two brokers separately. In your code where you want to distribute READ operations, you need to establish the connection with RO SHARD Broker. In your code where you need to INSERT records, you must connect to RW SHARD Broker.

If you follow these instructions, you can distribute READ operations to RO SHARD Brokers. Later, when your service grows big, you can easily add more RO SHARD Brokers, or increase the number of Proxy processes per Broker, and configure your application to use API-level load balancing, thus handle more load.

I have a question concerning the name used to describe shard_key "[%shard_key]" , If I use the following query SELECT * FROM t WHERE id = /*+ shard_val(1) */ ?' will it work ?
Yes, it will. You can even try to do so. It will work.
or must I use a [%id] section ? is the section [%shard_key] used when the [%column_name] section is not found ?

Yes, that's how it will work. But if your database has more than one sharded tables with different shard keys, you need to specify those shard keys explicitely, i.e. replace [%shard_key] to [%post_id] or [%user_id] as you wish.

link comment (2)
answered last year
admin
86
tagged




You are either using a very old browser or a browser that is not supported.
In order to browse cubrid.org you need to have one of the following browsers:



Internet Explorer: Mozilla Firefox: Google Chrome: