Bug: NewAppendableFile does not record newly created FileState in file_map_

Open Beginner friendly
#1,328 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp
Domain
databases

Research direction

Start in helpers/memenv/memenv.cc at InMemoryEnv::NewAppendableFile, then inspect how file_map_ and FileState are handled by nearby methods. Verify the change with the existing memenv tests if available; done means a newly created appendable file remains associated with its filename in file_map_.

Written by the indexing model from the issue text.

Description

Issue Description

I found a potential bug in helpers/memenv/memenv.cc in the InMemoryEnv::NewAppendableFile method.

Location

helpers/memenv/memenv.cc, lines 276-287

Problem

When a new appendable file is created (i.e., the file does not exist in file_map_), a new FileState object is instantiated and referenced. However, the new FileState is never assigned back to the file_map_, breaking the association between the filename and the FileState object.

Current Code

Status NewAppendableFile(const std::string& fname,
                         WritableFile** result) override {
  MutexLock lock(&mutex_);
  FileState** sptr = &file_map_[fname];
  FileState* file = *sptr;
  if (file == nullptr) {
    file = new FileState();
    file->Ref();
    // BUG: Missing assignment back to file_map_
  }
  *result = new WritableFileImpl(file);
  return Status::OK();
}
Dominant language
C++
Stars
39.4k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/leveldb

All issues in google/leveldb

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.