diff --git a/src/stasis/logger/filePool.c b/src/stasis/logger/filePool.c index c789470..f27c625 100644 --- a/src/stasis/logger/filePool.c +++ b/src/stasis/logger/filePool.c @@ -483,11 +483,8 @@ int stasis_log_file_pool_close(stasis_log_t * log) { pthread_join(fp->write_thread, 0); // pthread_join(fp->write_thread2, 0); - // XXX need to force log to disk here. for(int i = 0; i < fp->live_count; i++) { - if(fp->ro_fd[i] != -1) { - close(fp->ro_fd[i]); - } + close(fp->ro_fd[i]); free(fp->live_filenames[i]); } for(int i = 0; i < fp->dead_count; i++) { @@ -712,7 +709,7 @@ stasis_log_t* stasis_log_file_pool_open(const char* dirname, int filemode, int f free(namelist[i]); } - + assert(fp->live_count); free(namelist); printf("Current log segment appears to be %s. Scanning for next available LSN\n", fp->live_filenames[fp->live_count-1]); diff --git a/src/stasis/util/ringbuffer.c b/src/stasis/util/ringbuffer.c index 249c2b9..784f96f 100644 --- a/src/stasis/util/ringbuffer.c +++ b/src/stasis/util/ringbuffer.c @@ -137,7 +137,16 @@ lsn_t stasis_ringbuffer_consume_bytes(stasis_ringbuffer_t * ring, lsn_t* sz, lsn while(RING_VOLATILE == (ret = stasis_ringbuffer_nb_consume_bytes(ring, RING_NEXT, sz))) { pthread_cond_wait(&ring->write_done, &ring->mut); *sz = (ring->flush > ring->rf) ? RING_NEXT : orig_sz; - if(ring->shutdown) { *sz = RING_NEXT; } + if(ring->shutdown) { + if(ring->rt == ring->wf) { + fprintf(stderr, "Shutting down, and there are no more bytes. Signaling shutdown thread.\n"); + pthread_cond_signal(&ring->read_done); + pthread_mutex_unlock(&ring->mut); + return RING_CLOSED; + } else { + *sz = RING_NEXT; + } + } } if(handle) { *handle = ret;