Github user paul-guo- commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1243#discussion_r117423393
  
    --- Diff: src/backend/executor/nodeShareInputScan.c ---
    @@ -793,15 +887,70 @@ shareinput_reader_waitready(int share_id, 
PlanGenerator planGen)
                }
                else if(n==0)
                {
    -                   elog(DEBUG1, "SISC READER (shareid=%d, slice=%d): Wait 
ready time out once",
    -                                   share_id, currentSliceId);
    +                   file_exists = access(writer_tmp_file, F_OK);    
    +                   if(file_exists != 0)
    +                   {
    +                           elog(DEBUG3, "time out count is %d", 
timeout_count);
    +                           timeout_count--;
    +                           if(timeout_count == 0 || flag == true) //If tmp 
file never exists or disappeared, reader will no longer waiting for writer
    +                           {
    +                                   elog(LOG, "SISC READER (shareid=%d, 
slice=%d): Wait ready time out and break",
    +                                           share_id, currentSliceId);
    +                                   pfree(writer_tmp_file);
    +                                   break;
    +                           }
    +                   }
    +                   else
    +                   {
    +                           elog(LOG, "writer tmp file of 
shareinput_reader_waitready() is %s", writer_tmp_file);
    +                           flag = true;
    +                           fd_tmp = open(writer_tmp_file, O_RDONLY);
    +                           if(fd_tmp < 0)
    +                           {
    +                                   elog(DEBUG3, "Open writer's tmp file %s 
failed!, error number is %d", writer_tmp_file, errno);
    +                           }
    +                           lock = flock(fd_tmp, LOCK_EX | LOCK_NB);
    +                           if(lock == -1)
    +                           {
    +                                   elog(DEBUG3, "Lock writer's tmp file %s 
failed!, error number is %d", writer_tmp_file, errno);
    +                           }
    +                           else if(lock == 0)
    +                           {
    +                                   /*
    +                                    * There is one situation to consider 
about.
    +                                    * Writer need a time interval to lock 
the tmp file after the tmp file has been created.
    +                                    * So, if reader lock the tmp file 
ahead of writer, we should unlock it.
    +                                    * If reader lock the tmp file after 
writer, it means that writer process has abort.
    +                                    * We should break the loop to make 
sure reader no longer wait for writer.
    +                                    */  
    +                                   if(lock_count == 0)  
    +                                   {
    +                                           lock = flock(fd_tmp, LOCK_UN); 
    +                                           lock_count++;
    +                                           elog(DEBUG3, "Lock writer's tmp 
file %s first time successfully!", writer_tmp_file);
    +                                           continue;
    +                                   }
    +                                   else
    +                                   {
    +                                           elog(LOG, "Lock writer's tmp 
file %s successfully!", writer_tmp_file);
    +                                           close(fd_tmp);
    +                                           pfree(writer_tmp_file);
    +                                           break; 
    +                                   }
    +                           
    --- End diff --
    
    No need of blank lines here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to