| 330 | } |
| 331 | |
| 332 | void * compactor_thread(void *voidargs) |
| 333 | { |
| 334 | char vfilename[MAX_FNAMELEN]; |
| 335 | char new_filename[MAX_FNAMELEN]; |
| 336 | fdb_file_handle *fhandle; |
| 337 | fdb_status fs; |
| 338 | struct avl_node *a; |
| 339 | struct openfiles_elem *elem; |
| 340 | struct openfiles_elem query; |
| 341 | |
| 342 | // Sleep for 10 secs by default to allow applications to warm up their data. |
| 343 | // TODO: Need to implement more flexible way of scheduling the compaction |
| 344 | // daemon (e.g., public APIs to start / stop the compaction daemon). |
| 345 | mutex_lock(&sync_mutex); |
| 346 | thread_cond_timedwait(&sync_cond, &sync_mutex, sleep_duration * 1000); |
| 347 | mutex_unlock(&sync_mutex); |
| 348 | |
| 349 | while (1) { |
| 350 | |
| 351 | mutex_lock(&cpt_lock); |
| 352 | a = avl_first(&openfiles); |
| 353 | while(a) { |
| 354 | elem = _get_entry(a, struct openfiles_elem, avl); |
| 355 | if (!elem->file) { |
| 356 | a = avl_next(a); |
| 357 | avl_remove(&openfiles, &elem->avl); |
| 358 | free(elem); |
| 359 | continue; |
| 360 | } |
| 361 | |
| 362 | if (_compactor_is_threshold_satisfied(elem)) { |
| 363 | |
| 364 | elem->daemon_compact_in_progress = true; |
| 365 | // set compaction flag |
| 366 | elem->compaction_flag = true; |
| 367 | mutex_unlock(&cpt_lock); |
| 368 | // Once 'daemon_compact_in_progress' is set to true, then it is safe to |
| 369 | // read the variables of 'elem' until the compaction is completed. |
| 370 | _compactor_get_vfilename(elem->filename, vfilename); |
| 371 | |
| 372 | // Get the list of custom compare functions. |
| 373 | struct list cmp_func_list; |
| 374 | list_init(&cmp_func_list); |
| 375 | fdb_cmp_func_list_from_filemgr(elem->file, &cmp_func_list); |
| 376 | fs = fdb_open_for_compactor(&fhandle, vfilename, &elem->config, |
| 377 | &cmp_func_list); |
| 378 | fdb_free_cmp_func_list(&cmp_func_list); |
| 379 | |
| 380 | if (fs == FDB_RESULT_SUCCESS) { |
| 381 | compactor_get_next_filename(elem->filename, new_filename); |
| 382 | fdb_compact_file(fhandle, new_filename, false, (bid_t) -1, |
| 383 | false, NULL); |
| 384 | fdb_close(fhandle); |
| 385 | |
| 386 | strcpy(query.filename, new_filename); |
| 387 | mutex_lock(&cpt_lock); |
| 388 | // Search the next file for compaction. |
| 389 | a = avl_search_greater(&openfiles, &query.avl, _compactor_cmp); |
nothing calls this directly
no test coverage detected