Skip to content

Fix bug related with queries to dead backends #10

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

Merged
merged 2 commits into from
Nov 1, 2018

Conversation

CherkashinSergey
Copy link
Collaborator

Исправлен баг: во время слоных запросов pg_query_state иногда пытался опрашивать процессы, которые уже завершили свою работу.

@codecov-io
Copy link

codecov-io commented Oct 31, 2018

Codecov Report

Merging #10 into master will decrease coverage by 1.09%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #10     +/-   ##
=========================================
- Coverage   76.78%   75.69%   -1.1%     
=========================================
  Files           5        5             
  Lines         461      469      +8     
=========================================
+ Hits          354      355      +1     
- Misses        107      114      +7
Impacted Files Coverage Δ
pg_query_state.c 71.94% <9.09%> (-1.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7d5f98...91e3196. Read the comment docs.

@ildus ildus changed the title Fix bug Fix bug related with queries to dead backends Oct 31, 2018
pg_query_state.c Outdated
@@ -971,7 +982,7 @@ GetRemoteBackendQueryStates(PGPROC *leader,
foreach(iter, pworkers)
{
PGPROC *proc = (PGPROC *) lfirst(iter);

Assert (proc && proc->pid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот здесь тоже надо через continue, бекенд может помереть и в этом месте

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, Assert тут правильнее - мы предполагаем, что proc никогда не будет нулевым. А вот условие !proc->pid лишнее.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А с чего ты взял что он не может быть нулевым?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У вас тут условие есть в GetRemoteBackendWorkers()

if (!proc || !proc->pid)
   continue;

Поэтому видимо не может быть нулевым.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут в смысле proc нулевым не будет в любом случае, но процесс мог умереть (или завершиться) и проверка на pid все равно нужна. По хорошему вообще SHARED лок надо ставить на procArray

@ildus ildus merged commit 1cb4967 into postgrespro:master Nov 1, 2018
@maksm90
Copy link
Collaborator

maksm90 commented Nov 1, 2018

@ildus зачем смёржил свой вариант!?

@ildus
Copy link
Collaborator

ildus commented Nov 1, 2018

@maksm90 ответь на вопрос, всегда успеем отменить если нужно.

@maksm90
Copy link
Collaborator

maksm90 commented Nov 1, 2018

На какой? Выше вроде на всё ответил. Список pworkers как входной аргумент GetRemoteBackendQueryStates должен состоять из ненулевых proc - это предусловие. Обеспечиваем это условие на уровне выше в GetRemoteBackendWorkers - это будет постусловием для этой функции. Это обеспечивается вставкой continue в цикл:

for (i = 0; i < msg->number; i++)
{
	pid_t 	 pid = msg->pids[i];
	PGPROC	*proc = BackendPidGetProc(pid);

	result = lcons(proc, result);
}

@ildus
Copy link
Collaborator

ildus commented Nov 1, 2018

Это указатели на структуры в shared memory, откуда предположение что pid у них будет валидным всегда?

@maksm90
Copy link
Collaborator

maksm90 commented Nov 1, 2018

Тут соглашусь, гонки с аллокатором ProcArray могут быть. Тогда имеет смысл работать с pid'ами, а не со структурами PGPROC. Валидность pid'а мы сможем определить, отправляя сигнал (вызов SendProcSignal) или выполняя резолв на PGPROC. Пока мы остановимся на предположении, что гонки допустимы, но маловероятны. Для их полного разрешения надо переписывать всю логику взаимодействия, уменьшая кол-во RPC между процессами. Но это уже будет задача для следующей стадии.

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.

5 participants