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

fixed race condition on new partition #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fixed race condition on new partition #2

wants to merge 1 commit into from

Conversation

chobostar
Copy link

@chobostar chobostar commented Apr 9, 2018

Исправление гонки при создании новой партиции.

Как проявлялась ошибка:

  1. Создаем таблицу и готовим ее партицировать:
CREATE TABLE news (
	  id bigserial,
	  category_id INT,
	  title TEXT,
	  data TEXT
);

SELECT public._2gis_partition_magic('news', 'category_id')
  1. Открываем первую транзакцию:
BEGIN
insert into news(category_id) values(1);
  1. Открываем вторую транзакцию:
BEGIN
insert into news(category_id) values(1);
  1. Коммитим первую транзакцию:
COMMIT
  1. При попытке закоммитать вторую транзакцию:
ERROR:  relation "news_1" already exists
КОНТЕКСТ:  SQL statement "CREATE TABLE news_1 (CONSTRAINT news_1_category_id_check CHECK (category_id = 1)) INHERITS (news);"
PL/pgSQL function _2gis_partition_magic(text,text,integer,text,text,boolean) line 77 at EXECUTE
PL/pgSQL function _2gis_partition_magic_before_insert_trigger() line 21 at assignment
SQL statement "insert into news(category_id) values(1)"

@chobostar
Copy link
Author

В зависимости от workload-а lock можно вешать по хешу таблицы куда идет вставка, а не использовать один хэш для всех спартицированных через утилиту таблиц.

scream4ik added a commit to scream4ik/partition_magic that referenced this pull request Mar 8, 2022
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

Successfully merging this pull request may close these issues.

1 participant