/ Check-in [58a0aab8]
Login

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

Overview
Comment:Merge tserver fixes with this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | server-process-edition
Files: files | file ages | folders
SHA3-256:58a0aab8fd5f5dcbec867468b7f4c1b67c3e16bbe3aeea6bd21ae6b04c2b93f1
User & Date: dan 2017-06-28 20:21:15
Context
2017-07-07
16:12
Have this branch maintain an in-memory hash-table of old pages for read-only MVCC clients. There is no way to access it yet. check-in: a3a9a2e1 user: dan tags: server-process-edition
2017-06-28
20:21
Merge tserver fixes with this branch. check-in: 58a0aab8 user: dan tags: server-process-edition
20:12
Fix bugs in test program tserver.c. Leaf check-in: 093b9108 user: dan tags: server-edition
2017-06-27
20:23
Support clients within a single process only. check-in: dfa9a4d5 user: dan tags: server-process-edition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tool/tserver.c.

150
151
152
153
154
155
156








157
158
159
160
161
162
163
...
184
185
186
187
188
189
190

191
192
193
194
195
196
197
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
}

static sqlite3_int64 get_timer(void){
  struct timeval t;
  gettimeofday(&t, 0);
  return ((sqlite3_int64)t.tv_usec / 1000) + ((sqlite3_int64)t.tv_sec * 1000);
}









static int handle_dot_command(ClientCtx *p, const char *zCmd, int nCmd){
  assert( zCmd[0]=='.' );
  int n;
  int rc = 0;
  const char *z = &zCmd[1];
  const char *zArg;
................................................................................
  else if( n>=1 && n<=4 && 0==strncmp(z, "quit", n) ){
    rc = 1;
  }

  else if( n>=2 && n<=7 && 0==strncmp(z, "repeats", n) ){
    if( nArg ){
      p->nRepeat = strtol(zArg, 0, 0);

    }
    rc = send_message(p, "ok (repeat=%d)\n", p->nRepeat);
  }

  else if( n>=2 && n<=3 && 0==strncmp(z, "run", n) ){
    int i, j;
    int nBusy = 0;
................................................................................
        rc = send_message(
            p, "(%d done @ %d per second, %d busy)\n", 
            nDone, (1000*nDone + nMs/2) / nMs, nBusy - nTBusy1
        );
        t1 = t2;
        nT1 = j+1 - nBusy;
        nTBusy1 = nBusy;
        if( p->nSecond>=0 && (p->nSecond*1000)<=t1-t0 ) break;
      }
    }

    if( rc==SQLITE_OK ){
      send_message(p, "ok (%d/%d SQLITE_BUSY)\n", nBusy, j);
    }

  }

  else if( n>=1 && n<=7 && 0==strncmp(z, "seconds", n) ){
    if( nArg ){
      p->nSecond = strtol(zArg, 0, 0);
      if( p->nSecond>0 ) p->nRepeat = 0;
    }
................................................................................
    return 0;
  }

  while( rc==SQLITE_OK ){
    int i;
    int iStart;
    int nConsume;
    int bQuote = 0;
    res = read(ctx.fd, &zCmd[nCmd], sizeof(zCmd)-nCmd-1);
    if( res<=0 ) break;
    nCmd += res;
    if( nCmd>=sizeof(zCmd)-1 ){
      fprintf(stderr, "oversized (>32KiB) message\n");
      res = 0;
      break;
................................................................................
        }
      }
    }while( rc==SQLITE_OK && nConsume>0 );
  }

  fprintf(stdout, "Client %d disconnects\n", ctx.fd);
  close(ctx.fd);
  for(j=0; j<ctx.nPrepare; j++){
    sqlite3_finalize(ctx.apPrepare[j]);
  }
  sqlite3_free(ctx.apPrepare);
  sqlite3_close(ctx.db);
  return 0;
} 

int main(int argc, char *argv[]) {
  sqlite3 *db;
  int sfd;
  int rc;
  int yes = 1;
  struct sockaddr_in server;
  struct sockaddr_in client;

  /* Ignore SIGPIPE. Otherwise the server exits if a client disconnects
  ** abruptly.  */
  signal(SIGPIPE, SIG_IGN);

  if( argc!=2 ){
    fprintf(stderr, "Usage: %s DATABASE\n", argv[0]);







>
>
>
>
>
>
>
>







 







>







 







|






>







 







<







 







|
<
<











<







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
291
292
293
294
295
296
297

298
299
300
301
302
303
304
...
352
353
354
355
356
357
358
359


360
361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
}

static sqlite3_int64 get_timer(void){
  struct timeval t;
  gettimeofday(&t, 0);
  return ((sqlite3_int64)t.tv_usec / 1000) + ((sqlite3_int64)t.tv_sec * 1000);
}

static void clear_sql(ClientCtx *p){
  int j;
  for(j=0; j<p->nPrepare; j++){
    sqlite3_finalize(p->apPrepare[j]);
  }
  p->nPrepare = 0;
}

static int handle_dot_command(ClientCtx *p, const char *zCmd, int nCmd){
  assert( zCmd[0]=='.' );
  int n;
  int rc = 0;
  const char *z = &zCmd[1];
  const char *zArg;
................................................................................
  else if( n>=1 && n<=4 && 0==strncmp(z, "quit", n) ){
    rc = 1;
  }

  else if( n>=2 && n<=7 && 0==strncmp(z, "repeats", n) ){
    if( nArg ){
      p->nRepeat = strtol(zArg, 0, 0);
      if( p->nRepeat>0 ) p->nSecond = 0;
    }
    rc = send_message(p, "ok (repeat=%d)\n", p->nRepeat);
  }

  else if( n>=2 && n<=3 && 0==strncmp(z, "run", n) ){
    int i, j;
    int nBusy = 0;
................................................................................
        rc = send_message(
            p, "(%d done @ %d per second, %d busy)\n", 
            nDone, (1000*nDone + nMs/2) / nMs, nBusy - nTBusy1
        );
        t1 = t2;
        nT1 = j+1 - nBusy;
        nTBusy1 = nBusy;
        if( p->nSecond>0 && (p->nSecond*1000)<=t1-t0 ) break;
      }
    }

    if( rc==SQLITE_OK ){
      send_message(p, "ok (%d/%d SQLITE_BUSY)\n", nBusy, j);
    }
    clear_sql(p);
  }

  else if( n>=1 && n<=7 && 0==strncmp(z, "seconds", n) ){
    if( nArg ){
      p->nSecond = strtol(zArg, 0, 0);
      if( p->nSecond>0 ) p->nRepeat = 0;
    }
................................................................................
    return 0;
  }

  while( rc==SQLITE_OK ){
    int i;
    int iStart;
    int nConsume;

    res = read(ctx.fd, &zCmd[nCmd], sizeof(zCmd)-nCmd-1);
    if( res<=0 ) break;
    nCmd += res;
    if( nCmd>=sizeof(zCmd)-1 ){
      fprintf(stderr, "oversized (>32KiB) message\n");
      res = 0;
      break;
................................................................................
        }
      }
    }while( rc==SQLITE_OK && nConsume>0 );
  }

  fprintf(stdout, "Client %d disconnects\n", ctx.fd);
  close(ctx.fd);
  clear_sql(&ctx);


  sqlite3_free(ctx.apPrepare);
  sqlite3_close(ctx.db);
  return 0;
} 

int main(int argc, char *argv[]) {
  sqlite3 *db;
  int sfd;
  int rc;
  int yes = 1;
  struct sockaddr_in server;


  /* Ignore SIGPIPE. Otherwise the server exits if a client disconnects
  ** abruptly.  */
  signal(SIGPIPE, SIG_IGN);

  if( argc!=2 ){
    fprintf(stderr, "Usage: %s DATABASE\n", argv[0]);