BAM file caching bug

This is with release 1.8.0.

We do some of our own caching, where we explicitly write out bam file (and reload it on subsequent runs). It appears that when loading a bam file, panda immediately writes out a copy to its cache directory.

I haven’t fully debugged it yet, but it appears that Loader::try_load_file is calling cache->store incorrectly under some circumstances.

Before I dig too much deeper into panda’s loading/caching behavior, does any of this ring any bells with anyone?

PT(PandaNode) Loader::
try_load_file(const Filename &pathname, const LoaderOptions &options,
              LoaderFileType *requested_type) const {
  BamCache *cache = BamCache::get_global_ptr();

  bool cache_only = (options.get_flags() & LoaderOptions::LF_cache_only) != 0;

  if (requested_type->get_allow_ram_cache(options)) {
    // If we're allowing a RAM cache, use the ModelPool to load the
    // file.
    if (!cache_only || ModelPool::has_model(pathname)) {
      PT(PandaNode) node = ModelPool::load_model(pathname, options);
      if (node != (PandaNode *)NULL &&
          (options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
        // But return a deep copy of the shared model.
        node = node->copy_subgraph();
      }
      return node;
    }
  }

  bool report_errors = (options.get_flags() & LoaderOptions::LF_report_errors) != 0;

  PT(BamCacheRecord) record;
  if (cache->get_cache_models() && requested_type->get_allow_disk_cache(options)) {
    // See if the model can be found in the on-disk cache, if it is
    // active.
    record = cache->lookup(pathname, "bam");
    if (record != (BamCacheRecord *)NULL) {
      if (record->has_data()) {
        if (report_errors) {
          loader_cat.info()
            << "Model " << pathname << " found in disk cache.\n";
        }
        PT(PandaNode) result = DCAST(PandaNode, record->get_data());
        if (premunge_data) {
          SceneGraphReducer sgr;
          sgr.premunge(result, RenderState::make_empty());
        }
        return result;
      }
    }
  }
  
  if (!cache_only) {
    PT(PandaNode) result = requested_type->load_file(pathname, options, record);
    if (result != (PandaNode *)NULL){ 
      if (record != (BamCacheRecord *)NULL) {
        record->set_data(result, result);
        cache->store(record);
      }
      
      if (premunge_data) {
        SceneGraphReducer sgr;
        sgr.premunge(result, RenderState::make_empty());
      }
      return result;
    }
  }

It sounds like the intended behavior so far. The cache directory is intended to be a local cache of bam files (which might have been loaded from some slower media than the local cache directory).

It would be a bug if the cache file it is writing out is incorrect. Is that the case?

David

OK, turns out the explanation for the behavior I was seeing is that I was overflowing the 1GB default cache size, causing it to rewrite the cache on every run.