MCPcopy Create free account
hub / github.com/couchbase/forestdb / _fname_create

Function _fname_create

src/blockcache.cc:752–811  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

750}
751
752static struct fnamedic_item * _fname_create(struct filemgr *file) {
753 // TODO: we MUST NOT directly read file sturcture
754
755 struct fnamedic_item *fname_new;
756 // Before we create a new filename entry, garbage collect zombies
757 _garbage_collect_zombie_fnames();
758 fname_new = (struct fnamedic_item *)malloc(sizeof(struct fnamedic_item));
759
760 fname_new->filename_len = strlen(file->filename);
761 fname_new->filename = (char *)malloc(fname_new->filename_len + 1);
762 memcpy(fname_new->filename, file->filename, fname_new->filename_len);
763 fname_new->filename[fname_new->filename_len] = 0;
764
765 // calculate hash value
766 fname_new->hash = get_checksum(reinterpret_cast<const uint8_t*>(fname_new->filename),
767 fname_new->filename_len,
768 file->crc_mode);
769 fname_new->curfile = file;
770 atomic_init_uint64_t(&fname_new->nvictim, 0);
771 atomic_init_uint64_t(&fname_new->nitems, 0);
772 atomic_init_uint64_t(&fname_new->nimmutable, 0);
773 atomic_init_uint32_t(&fname_new->ref_count, 0);
774 atomic_init_uint64_t(&fname_new->access_timestamp, 0);
775 if (file->config->num_bcache_shards) {
776 fname_new->num_shards = file->config->num_bcache_shards;
777 } else {
778 fname_new->num_shards = DEFAULT_NUM_BCACHE_PARTITIONS;
779 }
780 // For random eviction among shards
781 randomize();
782
783 fname_new->shards = (bcache_shard *)
784 malloc(sizeof(struct bcache_shard) * fname_new->num_shards);
785 size_t i = 0;
786 for (; i < fname_new->num_shards; ++i) {
787 // initialize tree
788 avl_init(&fname_new->shards[i].tree, NULL);
789 avl_init(&fname_new->shards[i].tree_idx, NULL);
790 // initialize clean list
791 list_init(&fname_new->shards[i].cleanlist);
792 // initialize hash table
793 hash_init(&fname_new->shards[i].hashtable, BCACHE_NBUCKET,
794 _bcache_hash, _bcache_cmp);
795 spin_init(&fname_new->shards[i].lock);
796 }
797
798 // insert into fname dictionary
799 hash_insert(&fnamedic, &fname_new->hash_elem);
800 file->bcache = fname_new;
801
802 rw_spin_write_lock(&filelist_lock);
803 if (num_files == file_array_capacity) {
804 file_array_capacity *= 2;
805 file_list = (struct fnamedic_item **) realloc(file_list, file_array_capacity);
806 }
807 file_list[num_files++] = fname_new;
808 rw_spin_write_unlock(&filelist_lock);
809

Callers 2

bcache_writeFunction · 0.85
bcache_write_partialFunction · 0.85

Calls 10

atomic_init_uint64_tFunction · 0.85
atomic_init_uint32_tFunction · 0.85
avl_initFunction · 0.85
hash_initFunction · 0.85
hash_insertFunction · 0.85
rw_spin_write_lockFunction · 0.85
rw_spin_write_unlockFunction · 0.85
get_checksumFunction · 0.70
list_initFunction · 0.70

Tested by

no test coverage detected