github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/persist/fs/inspection.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package fs
    22  
    23  // Inspection contains the outcome of a filesystem inspection.
    24  type Inspection struct {
    25  	// SortedCommitLogFiles contains all commitlog filenames that existed
    26  	// before the node began accepting writes.
    27  	SortedCommitLogFiles []string
    28  }
    29  
    30  // CommitLogFilesSet generates a set of unique commitlog files.
    31  func (f Inspection) CommitLogFilesSet() map[string]struct{} {
    32  	set := make(map[string]struct{}, len(f.SortedCommitLogFiles))
    33  	for _, file := range f.SortedCommitLogFiles {
    34  		set[file] = struct{}{}
    35  	}
    36  
    37  	return set
    38  }
    39  
    40  // InspectFilesystem scans the filesystem and generates a Inspection
    41  // which the commitlog bootstrapper needs to avoid reading commitlog files that
    42  // were written *after* the process has already started. I.E in order to distinguish
    43  // between files that were already on disk before the process started, and those that
    44  // were written by the process itself once it started accepting writes (but before
    45  // bootstrapping had complete) we export a function which can be called during node
    46  // startup.
    47  func InspectFilesystem(fsOpts Options) (Inspection, error) {
    48  	path := CommitLogsDirPath(fsOpts.FilePathPrefix())
    49  	files, err := SortedCommitLogFiles(path)
    50  	if err != nil {
    51  		return Inspection{}, err
    52  	}
    53  
    54  	return Inspection{
    55  		SortedCommitLogFiles: files,
    56  	}, nil
    57  }