简体   繁体   English

Galera 集群问题

[英]Galera Cluster concerns

I want to use Galera cluster in our production environment, but i have some concerns;我想在我们的生产环境中使用 Galera 集群,但我有一些顾虑;

  1. Each table must have at least one explicit primary key defined.每个表必须至少定义一个显式主键。

  2. Each table must run under InnoDB or XtraDB storage engine.每个表都必须在 InnoDB 或 XtraDB 存储引擎下运行。

  3. Chunk up your big transaction in batches.分批拆分您的大笔交易。 For example, rather than having one transaction insert 100,000 rows, break it up into smaller chunks of eg, insert 1000 rows per transaction.例如,与其让一个事务插入 100,000 行,不如将其分解成更小的块,例如,每个事务插入 1000 行。

  4. Your application can tolerate non-sequential auto-increment values.您的应用程序可以容忍非连续的自动递增值。

  5. Schema changes are handled differently.架构更改的处理方式不同。

  6. Handle hotspots/Galera deadlocks by sending writes to a single node.通过向单个节点发送写入来处理热点/Galera 死锁。

I will like some clarification for all aforementioned points.Also we have over 600 databases in production, can galera work in this Environment??我想对上述所有要点进行一些澄清。此外,我们有 600 多个生产数据库,galera 可以在这种环境中工作吗??

Thanks谢谢

That is a LOT to handle in one shot.一次性处理很多 There are two issues, table creation (invloves Schema , see point 5) and applications that use those tables.有两个问题,表创建(invloves Schema ,参见第 5 点)和使用这些表的应用程序。 I'll try:我会尽力:

1)Each table must have at least one explicit primary key defined. 1)每张表必须至少定义一个显式主键。

When you are creating a table, you can't have any table that DOES NOT have a primary key.创建表时,不能有任何没有主键的表。 Tables are created with fields and INDEXES.表是用字段和索引创建的。 One of those indexes must be declared as PRIMARY KEY.这些索引之一必须声明为 PRIMARY KEY。

2)Each table must run under InnoDB or XtraDB storage engine. 2)每张表必须运行在InnoDB或XtraDB存储引擎下。

When tables are created, the must have ENGINE=InnoDB or ENGINE=XtraDB .创建表时,必须有ENGINE=InnoDBENGINE=XtraDB Galera does not handle the default MyISAM type tables Galera 不处理默认的 MyISAM 类型表

3)Chunk up your big transaction in batches. 3)分批整理你的大交易。 For example, rather than having one transaction insert 100,000 rows, break it up into smaller chunks of eg, insert 1000 rows per transaction.例如,与其让一个事务插入 100,000 行,不如将其分解成更小的块,例如,每个事务插入 1000 行。

This is not related to your schema, but your application.这与您的架构无关,而是与您的应用程序有关。 Try not to have an application that INSERT sa lot of data in one transaction .尽量不要在一个transactionINSERT大量数据的应用程序。 Note that this will work, but is risky.请注意,这会起作用,但有风险。 This is NOT a requirement, but a suggestion.不是要求,而是建议。

4)Your application can tolerate non-sequential auto-increment values. 4) 您的应用程序可以容忍非连续的自动递增值。

With a cluster, you can have multiple servers being updated.使用集群,您可以更新多个服务器。 If a field is auto-incremented, each cluster member could be trying to increment the same field.如果某个字段是自动递增的,则每个集群成员可能会尝试递增相同的字段。 Your application should NEVER EVER assume that the next ID is related to the previous ID.您的应用程序永远不应该假设下一个 ID 与前一个 ID 相关。 For auto-increment fields, do not IMPOSE a value, let the DB handle it.对于自增字段,不要强加一个值,让 DB 处理它。

5)Schema changes are handled differently. 5)架构更改的处理方式不同。

The Schema is the description of the tables and indexes and not the transactions that add, delete or retrieve information. Schema是表和索引的描述,而不是添加、删除或检索信息的事务。 You have multiple servers, so a Schema change has to be handled with care, so that all servers do catch up.您有多个服务器,因此必须小心处理架构更改,以便所有服务器都能赶上。

6)Handle hotspots/Galera deadlocks by sending writes to a single node. 6) 通过向单个节点发送写入来处理热点/Galera 死锁。

This is both application and DB related.这与应用程序和数据库相关。 A deadlock is a condition where 2 different parts of an app try to get a value (ValueA), as the DB to lock it so it can be changed, and then try to get another value (ValueB) for the same use.死锁是一种情况,应用程序的 2 个不同部分尝试获取一个值 (ValueA),作为锁定它的数据库,以便可以更改它,然后尝试获取另一个值 (ValueB) 用于相同的用途。 If another part tries to First Lock ValueB , then ValueA, we have a deadlock, Because each app has locked the next value of the other app.如果另一部分尝试先锁定 ValueB ,然后是 ValueA ,我们就会陷入死锁,因为每个应用程序都锁定了另一个应用程序的下一个值。 To avoid this, it's best tp write to only one server in the cluster and use the other servers for reading.为了避免这种情况,最好只写入集群中的一台服务器,并使用其他服务器进行读取。 Do note that you can still have deadlocks in your applications.请注意,您的应用程序中仍然可能存在死锁。 But you can avoid Galera creating the situation.但是你可以避免 Galera 制造这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM