Beispiel #1
0
static void
terminate_group(ContQueryProcGroup *grp)
{
	bool found;
	int i;

	grp->active = true;

	for (i = 0; i < TOTAL_SLOTS; i++)
	{
		ContQueryProc *proc = &grp->procs[i];

		/* Wake up processes, so they can see the terminate flag. */
		SetLatch(proc->latch);

		/* Let workers crash now as well in case we force terminate them. */
		ChangeBackgroundWorkerRestartState(&proc->handle, true, 0);
	}

	/* Wait for a bit and then force terminate any processes that are still alive. */
	pg_usleep(Max(ContQuerySchedulerShmem->params.max_wait, MIN_WAIT_TERMINATE_MS) * 1000);

	for (i = 0; i < TOTAL_SLOTS; i++)
	{
		ContQueryProc *proc = &grp->procs[i];
		TerminateBackgroundWorker(&proc->handle);
	}

	hash_search(ContQuerySchedulerShmem->proc_table, &grp->db_oid, HASH_REMOVE, &found);

	Assert(found);

	TupleBufferDrain(WorkerTupleBuffer, grp->db_oid);
	TupleBufferDrain(CombinerTupleBuffer, grp->db_oid);
}
Beispiel #2
0
static void
cleanup_background_workers(dsm_segment *seg, Datum arg)
{
	worker_state *wstate = (worker_state *) DatumGetPointer(arg);

	while (wstate->nworkers > 0)
	{
		--wstate->nworkers;
		TerminateBackgroundWorker(wstate->handle[wstate->nworkers]);
	}
}
Beispiel #3
0
Datum
kafka_consume_end_tr(PG_FUNCTION_ARGS)
{
	text *topic;
	text *qualified;
	Relation consumers;
	Oid id;
	bool found;
	HASH_SEQ_STATUS iter;
	KafkaConsumerProc *proc;

	if (PG_ARGISNULL(0))
		elog(ERROR, "topic cannot be null");
	if (PG_ARGISNULL(1))
		elog(ERROR, "relation cannot be null");

	topic = PG_GETARG_TEXT_P(0);
	qualified = PG_GETARG_TEXT_P(1);
	consumers = open_pipeline_kafka_consumers();

	id = get_consumer_id(consumers, qualified, topic);
	if (!OidIsValid(id))
		elog(ERROR, "there are no consumers for that topic and relation");

	hash_search(consumer_groups, &id, HASH_REMOVE, &found);
	if (!found)
		elog(ERROR, "no consumer processes are running for that topic and relation");

	hash_seq_init(&iter, consumer_procs);
	while ((proc = (KafkaConsumerProc *) hash_seq_search(&iter)) != NULL)
	{
		if (proc->consumer_id != id)
			continue;

		TerminateBackgroundWorker(&proc->worker);
		hash_search(consumer_procs, &id, HASH_REMOVE, NULL);
	}

	heap_close(consumers, NoLock);
	RETURN_SUCCESS();
}
Beispiel #4
0
Datum
kafka_consume_end_all(PG_FUNCTION_ARGS)
{
	HASH_SEQ_STATUS iter;
	KafkaConsumerProc *proc;
	List *ids = NIL;
	ListCell *lc;

	hash_seq_init(&iter, consumer_procs);
	while ((proc = (KafkaConsumerProc *) hash_seq_search(&iter)) != NULL)
	{
		TerminateBackgroundWorker(&proc->worker);
		hash_search(consumer_groups, &proc->consumer_id, HASH_REMOVE, NULL);
		ids = lappend_oid(ids, proc->id);
	}

	foreach(lc, ids)
	{
		Oid id = lfirst_oid(lc);
		hash_search(consumer_procs, &id, HASH_REMOVE, NULL);
	}