gpfdist_init
do_accept # Callback when the listen socket is ready to accept connections
do_read_request
tid:pathsend_eof or send_errmsg (which only happened in read path)request_t->ferroreach completed write contains at least three requests, with different X-GP-SEQ and X-GP-DONE
For the first request, X-GP-SEQ should be 1. X-GP-DONE should not exist. For the second request to nth request, X-GP-SEQ should be 2 - N. X-GP-DONE should not exist. For the last final request, X-GP-DONE should be 1. And X-GP-SEQ should be N.
Multiple segments can send requests at the same time. If the tid and path are same, they should be attached to the same session. However, if one or more of the segments are hanged, the requests from those segments may not be received by the gpfdist server in time. Gpfdist server can deallocate the session, and create another session for the same tid:path again for the same write from segments not sending first requests in time.
If the subprocess failed not quick enough and writing is short, even the subprocess shall fail, the writing will be success due to the apr_file_write mechanism. The root cause is that we set out in apr_procattr_io_set as APR_NO_PIPE. So the error file won't be written in time. However, after the session is freed, and the fstream is closed, we must have done the apr_proc_wait. So that we can get error message from error file for sure. If we find an error exists, we should send the error message back to client in request_end. Also, we should clean up the error files.
If writing is long enough, we can also get error message during write. After wrote is failed, we will check the error file and send the error file to client in header if error exists. The client won‘t send DONE requests anymore since the error has already happened. So the server won’t have a chance to clean the session. However, that will not be an issue, because we will finally do the session clean up job by sessions_cleanup if we find that the session is idled for a while.
You will find that the cleaning up of an error file will only be done in session_free. So in most cases, we will only get error message in the final request in one of the segments. Other cases are writing failures happened. However, we still clean up the error file in session_free in those cases.