Skip to content

Instantly share code, notes, and snippets.

@soubhik-c
Created November 7, 2019 16:12
Show Gist options
  • Save soubhik-c/b430ca4fefd5ce252b3bffb4bcc10a57 to your computer and use it in GitHub Desktop.
Save soubhik-c/b430ca4fefd5ce252b3bffb4bcc10a57 to your computer and use it in GitHub Desktop.
aerospike device overload error
int
cf_queue_pop(cf_queue *q, void *buf, int ms_wait)
{
struct timespec tp;
if (ms_wait > 0) {
cf_set_wait_timespec(ms_wait, &tp);
}
cf_queue_lock(q);
if (q->threadsafe) {
// Note that we have to use a while() loop. The pthread_cond_signal()
// documentation says that AT LEAST ONE waiting thread will be awakened.
// If more than one are awakened, the first will get the popped element,
// others will find the queue empty and go back to waiting.
while (CF_Q_EMPTY(q)) {
if (CF_QUEUE_FOREVER == ms_wait) {
pthread_cond_wait(&q->CV, &q->LOCK);
}
else if (CF_QUEUE_NOWAIT == ms_wait) {
pthread_mutex_unlock(&q->LOCK);
return CF_QUEUE_EMPTY;
}
else {
pthread_cond_timedwait(&q->CV, &q->LOCK, &tp);
if (CF_Q_EMPTY(q)) {
pthread_mutex_unlock(&q->LOCK);
return CF_QUEUE_EMPTY;
}
}
}
}
else if (CF_Q_EMPTY(q)) {
return CF_QUEUE_EMPTY;
}
memcpy(buf, CF_Q_ELEM_PTR(q, q->read_offset), q->element_sz);
q->read_offset++;
// This probably keeps the cache fresher because the queue is fully empty.
if (q->read_offset == q->write_offset) {
q->read_offset = q->write_offset = 0;
}
cf_queue_unlock(q);
return CF_QUEUE_OK;
}
// Thread "run" function that flushes write buffers to device.
void *
run_write(void *arg)
{
drv_ssd *ssd = (drv_ssd*)arg;
while (ssd->running) {
ssd_write_buf *swb;
if (CF_QUEUE_OK != cf_queue_pop(ssd->swb_write_q, &swb, 100)) {
continue;
}
// Sanity checks (optional).
ssd_write_sanity_checks(ssd, swb);
// Flush to the device.
ssd_flush_swb(ssd, swb);
if (ssd->shadow_name) {
// Queue for shadow device write.
cf_queue_push(ssd->swb_shadow_q, &swb);
}
else {
// If this swb was a defrag destination, release the sources.
swb_release_all_vacated_wblocks(swb);
// Transfer to post-write queue, or release swb, as appropriate.
ssd_post_write(ssd, swb);
}
} // infinite event loop waiting for block to write
return NULL;
}
void
ssd_flush_swb(drv_ssd *ssd, ssd_write_buf *swb)
{
// Wait for all writers to finish.
while (cf_atomic32_get(swb->n_writers) != 0) {
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment