Exemplo n.º 1
0
static const StoreEntry *
heap_walkNext(RemovalPolicyWalker * walker)
{
    HeapWalkData *heap_walk = walker->_data;
    RemovalPolicy *policy = walker->_policy;
    HeapPolicyData *heap = policy->_data;
    StoreEntry *entry;
    if (heap_walk->current >= heap_nodes(heap->heap))
	return NULL;		/* done */
    entry = (StoreEntry *) heap_peep(heap->heap, heap_walk->current++);
    return entry;
}
Exemplo n.º 2
0
int
storeDirWriteCleanLogs(int reopen)
{
    StoreEntry *e = NULL;
    int n = 0;
    struct timeval start;
    double dt;
    SwapDir *sd;
    int dirn;
    int N = Config.cacheSwap.n_configured;
#if HEAP_REPLACEMENT
    int node;
#else
    dlink_node *m;
#endif
    if (store_dirs_rebuilding) {
	debug(20, 1) ("Not currently OK to rewrite swap log.\n");
	debug(20, 1) ("storeDirWriteCleanLogs: Operation aborted.\n");
	return 0;
    }
    debug(20, 1) ("storeDirWriteCleanLogs: Starting...\n");
    getCurrentTime();
    start = current_time;
    for (dirn = 0; dirn < Config.cacheSwap.n_configured; dirn++) {
	sd = &Config.cacheSwap.swapDirs[dirn];
	if (sd->log.clean.open(sd) < 0) {
	    debug(20, 1) ("log.clean.open() failed for dir #%d\n", sd->index);
	    continue;
	}
    }
#if HEAP_REPLACEMENT
    if (NULL == store_heap)
	return 0;
    for (node = 0; node < heap_nodes(store_heap); node++)
#else
    for (m = store_list.tail; m; m = m->prev)
#endif
    {
#if HEAP_REPLACEMENT
	e = (StoreEntry *) heap_peep(store_heap, node);
#else
	e = m->data;
#endif
	if (e->swap_file_number < 0)
	    continue;
	if (e->swap_status != SWAPOUT_DONE)
	    continue;
	if (e->swap_file_sz <= 0)
	    continue;
	if (EBIT_TEST(e->flags, RELEASE_REQUEST))
	    continue;
	if (EBIT_TEST(e->flags, KEY_PRIVATE))
	    continue;
	if (EBIT_TEST(e->flags, ENTRY_SPECIAL))
	    continue;
	dirn = storeDirNumber(e->swap_file_number);
	sd = &Config.cacheSwap.swapDirs[dirn];
	if (NULL == sd->log.clean.write)
	    continue;
	sd->log.clean.write(e, sd);
	if ((++n & 0xFFFF) == 0) {
	    getCurrentTime();
	    debug(20, 1) ("  %7d entries written so far.\n", n);
	}
    }
    /* flush */
    for (dirn = 0; dirn < N; dirn++) {
	sd = &Config.cacheSwap.swapDirs[dirn];
	if (NULL == sd->log.clean.write)
	    continue;
	sd->log.clean.write(NULL, sd);
    }
    if (reopen)
	storeDirOpenSwapLogs();
    getCurrentTime();
    dt = tvSubDsec(start, current_time);
    debug(20, 1) ("  Finished.  Wrote %d entries.\n", n);
    debug(20, 1) ("  Took %3.1f seconds (%6.1f entries/sec).\n",
	dt, (double) n / (dt > 0.0 ? dt : 1.0));
    return n;
}