void update()

in src/afs.cc [910:954]


	void update()
	{
		pgstat_report_activity(STATE_RUNNING, (std::string(Tag) + ": updating").c_str());

		PushActiveSnapshot(GetTransactionSnapshot());

		LWLockAcquire(lock_, LW_EXCLUSIVE);
		std::string query(
			static_cast<const char*>(dsa_get_address(area_, session_->updateQuery)));
		dsa_free(area_, session_->updateQuery);
		session_->updateQuery = InvalidDsaPointer;
		SetCurrentStatementStartTimestamp();
		P("%s: %s: update: %s", Tag, tag_, query.c_str());
		auto result = SPI_execute(query.c_str(), false, 0);
		LWLockRelease(lock_);

		switch (result)
		{
			case SPI_OK_INSERT:
			case SPI_OK_DELETE:
			case SPI_OK_UPDATE:
				session_->nUpdatedRecords = SPI_processed;
				break;
			default:
				set_shared_string(session_->errorMessage,
				                  std::string(Tag) + ": " + tag_ + ": update" +
				                      ": failed to run a query: <" + query +
				                      ">: " + SPI_result_code_string(result));
				break;
		}

		PopActiveSnapshot();

		// TODO: Is this usage correct?
		CommitTransactionCommand();
		StartTransactionCommand();

		if (sharedData_->serverPID != InvalidPid)
		{
			P("%s: %s: update: kill server: %d", Tag, tag_, sharedData_->serverPID);
			kill(sharedData_->serverPID, SIGUSR1);
		}

		pgstat_report_activity(STATE_IDLE, NULL);
	}