Skip to content

Commit

Permalink
Track file trailer only in debug builds
Browse files Browse the repository at this point in the history
The commit 96574a7 changes the handling of the file_trailer_received
flag. It is now only used in asserts and not in any other kind of logic.
This patch encapsulates the file_trailer_received in a
USE_ASSERT_CHECKING macro.
  • Loading branch information
jnidzwetzki committed Mar 10, 2023
1 parent 7b8177a commit 1f0f3db
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tsl/src/remote/copy_fetcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ typedef struct CopyFetcher
/* Data for virtual tuples of the current retrieved batch. */
Datum *batch_values;
bool *batch_nulls;
bool file_trailer_received;
AsyncRequest *req;
#ifdef USE_ASSERT_CHECKING
bool file_trailer_received;
#endif
} CopyFetcher;

static void copy_fetcher_send_fetch_request(DataFetcher *df);
Expand Down Expand Up @@ -61,7 +63,10 @@ static void
copy_fetcher_reset(CopyFetcher *fetcher)
{
fetcher->state.open = false;

#ifdef USE_ASSERT_CHECKING
fetcher->file_trailer_received = false;
#endif

if (fetcher->req != NULL)
{
Expand Down Expand Up @@ -449,17 +454,21 @@ copy_fetcher_complete(CopyFetcher *fetcher)
* nor the expected number of columns. This provides an extra
* check against somehow getting out of sync with the data.
*/
#ifdef USE_ASSERT_CHECKING
fetcher->file_trailer_received = true;
#endif

/* Next PQgetCopyData() should return -1, indicating EOF and
* that the remote side ended the copy. The final result
* (PGRES_COMMAND_OK) should then be read with
* PQgetResult().
*
* Perform a PQgetCopyData directly in this branch because
* if row = state.fetch_size - 1 (i.e., file_trailer is the last
* tuple of the batch), the for loop will not executed
* and PQgetCopyData will never be called.
* Execute PQgetCopyData() (invoked in copy_fetcher_read_data)
* directly here, because if row = state.fetch_size - 1
* (i.e., file_trailer is the last tuple of the batch), the
* for loop will not be executed again and PQgetCopyData()
* will never be called. If it is not called, the EOF state
* is not updated and a new batch would be requested.
*/
tuple_read = copy_fetcher_read_data(fetcher, conn, &dataptr, &copy_data);
Assert(tuple_read == false);
Expand Down

0 comments on commit 1f0f3db

Please sign in to comment.