On SQLITE_BUSY, wait a random amount of time
If all contending processes wait a fixed amount of time (100 ms), there is a good probability that they'll just collide again.
This commit is contained in:
		
							parent
							
								
									e087bfef5f
								
							
						
					
					
						commit
						772778c0ec
					
				
					 2 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
					@ -10,6 +10,7 @@
 | 
				
			||||||
#include <cctype>
 | 
					#include <cctype>
 | 
				
			||||||
#include <exception>
 | 
					#include <exception>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/time.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,6 +136,11 @@ static void initAndRun(int argc, char * * argv)
 | 
				
			||||||
       everybody. */
 | 
					       everybody. */
 | 
				
			||||||
    umask(0022);
 | 
					    umask(0022);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Initialise the PRNG. */
 | 
				
			||||||
 | 
					    struct timeval tv;
 | 
				
			||||||
 | 
					    gettimeofday(&tv, 0);
 | 
				
			||||||
 | 
					    srandom(tv.tv_usec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Process the NIX_LOG_TYPE environment variable. */
 | 
					    /* Process the NIX_LOG_TYPE environment variable. */
 | 
				
			||||||
    string lt = getEnv("NIX_LOG_TYPE");
 | 
					    string lt = getEnv("NIX_LOG_TYPE");
 | 
				
			||||||
    if (lt != "") setLogType(lt);
 | 
					    if (lt != "") setLogType(lt);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ static void throwSQLiteError(sqlite3 * db, const format & f)
 | 
				
			||||||
#if HAVE_NANOSLEEP
 | 
					#if HAVE_NANOSLEEP
 | 
				
			||||||
        struct timespec t;
 | 
					        struct timespec t;
 | 
				
			||||||
        t.tv_sec = 0;
 | 
					        t.tv_sec = 0;
 | 
				
			||||||
        t.tv_nsec = 100 * 1000 * 1000; /* 0.1s */
 | 
					        t.tv_nsec = (random() % 100) * 1000 * 1000; /* <= 0.1s */
 | 
				
			||||||
        nanosleep(&t, 0);
 | 
					        nanosleep(&t, 0);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
        sleep(1);
 | 
					        sleep(1);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue