예제 #1
0
void *writer(void *unused) {
  jlog_ctx *ctx;
  int i;
  char foo[72];
  ctx = jlog_new(LOGNAME);
  memset(foo, 'X', sizeof(foo)-1);
  foo[sizeof(foo)-1] = '\0';
  if(jlog_ctx_open_writer(ctx) != 0) {
    fprintf(stderr, "jlog_ctx_open_writer failed: %d %s\n", jlog_ctx_err(ctx), jlog_ctx_err_string(ctx));
    croak();
  }

#ifdef TEST_UNIT_LIMIT
  newsize = 1024*1024 + (((intptr_t)unused) % (1024 * 1024));
  fprintf(stderr, "writer setting new unit_limit to %d\n", (int)newsize);
  jlog_ctx_alter_journal_size(ctx, newsize);
#endif
  for(i=0;i<10000;i++) {
    int rv;
    rv = jlog_ctx_write(ctx, foo, strlen(foo));
    if(rv != 0) {
      fprintf(stderr, "jlog_ctx_write_message failed: %d %s\n", jlog_ctx_err(ctx), jlog_ctx_err_string(ctx));
      /* abort(); */
    }
    usleep(100);
  }
  fprintf(stderr, "writer thinks unit_limit is %d\n", ctx->meta->unit_limit);
  jlog_ctx_close(ctx);
  writer_done = 1;
  return 0;
}
예제 #2
0
static void queue_jlog_enqueue(fqd_queue_impl_data f, fq_msg *m) {
  struct queue_jlog *d = (struct queue_jlog *)f;
  size_t wlen;
  wlen = offsetof(fq_msg, payload) + m->payload_len;
  if(jlog_ctx_write(d->writer, m, wlen) != 0) {
    ck_pr_inc_uint(&d->errors);
  }
  ck_pr_inc_uint(&d->nenqueued);
}
예제 #3
0
int jlog_logio_asynch_write(asynch_log_ctx *actx, asynch_log_line *line) {
  int rv;
  jlog_ctx *log = actx->userdata;
  rv = jlog_ctx_write(log, line->buf_dynamic ?
                             line->buf_dynamic :
                             line->buf_static,
                      line->len);
  if(rv == -1) {
    noitL(noit_error, "jlog_ctx_write failed(%d): %s\n",
          jlog_ctx_errno(log), jlog_ctx_err_string(log));
  }
  return rv;
}
예제 #4
0
static void *
jlog_logio_asynch_writer(void *vls) {
  noit_log_stream_t ls = vls;
  jlog_asynch_ctx *actx = ls->op_ctx;
  jlog_line *iter = NULL;
  int gen;
  gen = noit_atomic_inc32(&actx->gen);
  noitL(noit_error, "starting asynchronous jlog writer[%d/%p]\n",
        (int)getpid(), (void *)pthread_self());
  while(gen == actx->gen) {
    pthread_rwlock_t *lock;
    int fast = 0, max = 1000;
    jlog_line *line;
    lock = ls->lock;
    if(lock) pthread_rwlock_rdlock(lock);
    while(max > 0 && NULL != (line = jlog_asynch_pop(actx, &iter))) {
      if(jlog_ctx_write(actx->log, line->buf_dynamic ?
                                     line->buf_dynamic :
                                     line->buf_static,
                        line->len) == -1) {
        noitL(noit_error, "jlog_ctx_write failed(%d): %s\n",
              jlog_ctx_errno(actx->log), jlog_ctx_err_string(actx->log));
        abort();
      }
      if(line->buf_dynamic != NULL) free(line->buf_dynamic);
      free(line);
      fast = 1;
      max--;
    }
    if(lock) pthread_rwlock_unlock(lock);
    if(max > 0) {
      /* we didn't hit our limit... so we ran the queue dry */
      /* 200ms if there was nothing, 10ms otherwise */
      usleep(fast ? 10000 : 200000);
    }
  }
  noitL(noit_error, "stopping asynchronous jlog writer[%d/%p]\n",
        (int)getpid(), (void *)pthread_self());
  pthread_exit((void *)0);
}