static void cacheStore(Cache * cache, storeSwapLogData * s, int update_digest) { CacheEntry *olde = (CacheEntry *) hash_lookup(cache->hash, s->key); if (olde) { cache->bad_add_count++; } else { CacheEntry *e = cacheEntryCreate(s); hash_join(cache->hash, &e->hash); cache->count++; if (update_digest) cacheDigestAdd(cache->digest, e->key); } }
static int cacheIndexScan(CacheIndex * idx, const char *fname, FILE * file) { int count = 0; storeSwapLogData s; fprintf(stderr, "%s scanning\n", fname); while (fread(&s, sizeof(s), 1, file) == 1) { count++; idx->scanned_count++; /* if (s.op <= SWAP_LOG_NOP || s.op >= SWAP_LOG_MAX) * continue; */ if (s.op == SWAP_LOG_ADD) { CacheEntry *olde = (CacheEntry *) hash_lookup(idx->hash, s.key); if (olde) { idx->bad_add_count++; } else { CacheEntry *e = cacheEntryCreate(&s); hash_join(idx->hash, (hash_link *) e); idx->count++; } } else if (s.op == SWAP_LOG_DEL) { CacheEntry *olde = (CacheEntry *) hash_lookup(idx->hash, s.key); if (!olde) idx->bad_del_count++; else { assert(idx->count); hash_remove_link(idx->hash, (hash_link *) olde); cacheEntryDestroy(olde); idx->count--; } } else { fprintf(stderr, "%s:%d: unknown swap log action\n", fname, count); exit(-3); } } fprintf(stderr, "%s:%d: scanned (size: %d bytes)\n", fname, count, (int) (count * sizeof(CacheEntry))); return count; }