Fossil

Check-in [0fe9da81]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make the backoffice module tracing behave more consistently on Win32.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:0fe9da816feba1bc9455cce2b3d8a120718e727462011a70a67b9c1154f2cf2f
User & Date: mistachkin 2018-08-07 23:48:10
Context
2018-08-08
00:01
Add the test-backoffice-lease command for testing the backoffice. check-in: f26ef806 user: drh tags: trunk
2018-08-07
23:48
Make the backoffice module tracing behave more consistently on Win32. check-in: 0fe9da81 user: mistachkin tags: trunk
23:22
Merge changes from the previous two check-ins. check-in: 30068260 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/backoffice.c.

   115    115   ** backoffice_run_if_needed() will consult this variable to see if it
   116    116   ** should be a no-op.
   117    117   */
   118    118   static char *backofficeDb = 0;
   119    119   
   120    120   /* End of state variables
   121    121   ****************************************************************************/
          122  +
          123  +/*
          124  +** This function emits a diagnostic message related to the processing in
          125  +** this module.
          126  +*/
          127  +#if defined(_WIN32)
          128  +# define BKOFCE_ALWAYS_TRACE   (1)
          129  +#else
          130  +# define BKOFCE_ALWAYS_TRACE   (0)
          131  +#endif
          132  +static void backofficeTrace(const char *zFormat, ...){
          133  +  char *zMsg = 0;
          134  +  if( BKOFCE_ALWAYS_TRACE || g.fAnyTrace ){
          135  +    va_list ap;
          136  +    va_start(ap, zFormat);
          137  +    zMsg = sqlite3_vmprintf(zFormat, ap);
          138  +    va_end(ap);
          139  +#if defined(_WIN32)
          140  +    sqlite3_win32_write_debug(zMsg, -1);
          141  +#endif
          142  +  }
          143  +  if( g.fAnyTrace ) fprintf(stderr, "%s", zMsg);
          144  +  if( zMsg ) sqlite3_free(zMsg);
          145  +}
   122    146   
   123    147   /*
   124    148   ** Do not allow backoffice processes to sleep waiting on a timeslot.
   125    149   ** They must either do their work immediately or exit.
   126    150   **
   127    151   ** In a perfect world, this interface would not exist, as there would
   128    152   ** never be a problem with waiting backoffice threads.  But in some cases
................................................................................
   444    468         /* This process can start doing backoffice work immediately */
   445    469         x.idCurrent = idSelf;
   446    470         x.tmCurrent = tmNow + BKOFCE_LEASE_TIME;
   447    471         x.idNext = 0;
   448    472         x.tmNext = 0;
   449    473         backofficeWriteLease(&x);
   450    474         db_end_transaction(0);
   451         -      if( g.fAnyTrace ){
   452         -        fprintf(stderr, "/***** Begin Backoffice Processing %d *****/\n",
   453         -                        GETPID());
   454         -      }
          475  +      backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
          476  +                      GETPID());
   455    477         backoffice_work();
   456    478         break;
   457    479       }
   458    480       if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
   459    481         /* If the no-delay flag is set, exit immediately rather than queuing
   460    482         ** up.  Assume that some future request will come along and handle any
   461    483         ** necessary backoffice work. */
................................................................................
   464    486       }
   465    487       /* This process needs to queue up and wait for the current lease
   466    488       ** to expire before continuing. */
   467    489       x.idNext = idSelf;
   468    490       x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
   469    491       backofficeWriteLease(&x);
   470    492       db_end_transaction(0);
   471         -    if( g.fAnyTrace ){
   472         -      fprintf(stderr, "/***** Backoffice On-deck %d *****/\n",  GETPID());
   473         -    }
          493  +    backofficeTrace("/***** Backoffice On-deck %d *****/\n",  GETPID());
   474    494       if( x.tmCurrent >= tmNow ){
   475    495         if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){
   476    496           /* The sleep was interrupted by a signal from another thread. */
   477         -        if( g.fAnyTrace ){
   478         -          fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", GETPID());
   479         -        }
          497  +        backofficeTrace("/***** Backoffice Interrupt %d *****/\n", GETPID());
   480    498           db_end_transaction(0);
   481    499           break;
   482    500         }
   483    501       }else{
   484    502         if( lastWarning+warningDelay < tmNow ){
   485    503           fossil_warning(
   486    504              "backoffice process %lld still running after %d seconds",
   487    505              x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent));
   488    506           lastWarning = tmNow;
   489    507           warningDelay *= 2;
   490    508         }
   491    509         if( backofficeSleep(1000) ){
   492    510           /* The sleep was interrupted by a signal from another thread. */
   493         -        if( g.fAnyTrace ){
   494         -          fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", GETPID());
   495         -        }
          511  +        backofficeTrace("/***** Backoffice Interrupt %d *****/\n", GETPID());
   496    512           db_end_transaction(0);
   497    513           break;
   498    514         }
   499    515       }
   500    516     }
   501    517   #if defined(_WIN32)
   502    518     backofficeWin32ThreadCleanup(1);
................................................................................
   561    577       argv[1] = "backoffice";
   562    578       argv[2] = "-R";
   563    579       argv[3] = backofficeDb;
   564    580       ax[4] = 0;
   565    581       for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
   566    582       x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax);
   567    583       for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);
   568         -    if( g.fAnyTrace ){
   569         -      fprintf(stderr, 
   570         -        "/***** Subprocess %d creates backoffice child %d *****/\n",
   571         -        GETPID(), (int)x);
   572         -    }
          584  +    backofficeTrace(
          585  +      "/***** Subprocess %d creates backoffice child %d *****/\n",
          586  +      GETPID(), (int)x);
   573    587       if( x>=0 ) return;
   574    588     }
   575    589   #else /* unix */
   576    590     {
   577    591       pid_t pid = fork();
   578    592       if( pid>0 ){
   579    593         /* This is the parent in a successful fork().  Return immediately. */
   580         -      if( g.fAnyTrace ){
   581         -        fprintf(stderr, 
   582         -          "/***** Subprocess %d creates backoffice child %d *****/\n",
   583         -          GETPID(), (int)pid);
   584         -      }
          594  +      backofficeTrace(
          595  +        "/***** Subprocess %d creates backoffice child %d *****/\n",
          596  +        GETPID(), (int)pid);
   585    597         return;
   586    598       }
   587    599       if( pid==0 ){
   588    600         /* This is the child of a successful fork().  Run backoffice. */
   589    601         setsid();
   590    602         db_open_repository(backofficeDb);
   591    603         backofficeDb = "x";
   592    604         backoffice_thread();
   593    605         db_close(1);
   594         -      if( g.fAnyTrace ){
   595         -        fprintf(stderr, "/***** Backoffice Child %d exits *****/\n", GETPID());
   596         -      }
          606  +      backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
   597    607         exit(0);
   598    608       }
   599    609     }
   600    610   #endif
   601    611     /* Fork() failed or is unavailable.  Run backoffice in this process, but
   602    612     ** do so with the no-delay setting.
   603    613     */
   604    614     backofficeNoDelay = 1;
   605    615     db_open_repository(backofficeDb);
   606    616     backofficeDb = "x";
   607    617     backoffice_thread();
   608    618     db_close(1);
   609    619   }