storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/storage-datatypes.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package cmd
    18  
    19  import (
    20  	"time"
    21  )
    22  
    23  //go:generate msgp -file=$GOFILE
    24  
    25  // DiskInfo is an extended type which returns current
    26  // disk usage per path.
    27  //msgp:tuple DiskInfo
    28  // The above means that any added/deleted fields are incompatible.
    29  type DiskInfo struct {
    30  	Total      uint64
    31  	Free       uint64
    32  	Used       uint64
    33  	UsedInodes uint64
    34  	FSType     string
    35  	RootDisk   bool
    36  	Healing    bool
    37  	Endpoint   string
    38  	MountPath  string
    39  	ID         string
    40  	Metrics    DiskMetrics
    41  	Error      string // carries the error over the network
    42  }
    43  
    44  // DiskMetrics has the information about XL Storage APIs
    45  // the number of calls of each API and the moving average of
    46  // the duration of each API.
    47  type DiskMetrics struct {
    48  	APILatencies map[string]string `json:"apiLatencies,omitempty"`
    49  	APICalls     map[string]uint64 `json:"apiCalls,omitempty"`
    50  }
    51  
    52  // VolsInfo is a collection of volume(bucket) information
    53  type VolsInfo []VolInfo
    54  
    55  // VolInfo - represents volume stat information.
    56  //msgp:tuple VolInfo
    57  // The above means that any added/deleted fields are incompatible.
    58  type VolInfo struct {
    59  	// Name of the volume.
    60  	Name string
    61  
    62  	// Date and time when the volume was created.
    63  	Created time.Time
    64  }
    65  
    66  // FilesInfo represent a list of files, additionally
    67  // indicates if the list is last.
    68  type FilesInfo struct {
    69  	Files       []FileInfo
    70  	IsTruncated bool
    71  }
    72  
    73  // FilesInfoVersions represents a list of file versions,
    74  // additionally indicates if the list is last.
    75  type FilesInfoVersions struct {
    76  	FilesVersions []FileInfoVersions
    77  	IsTruncated   bool
    78  }
    79  
    80  // FileInfoVersions represent a list of versions for a given file.
    81  type FileInfoVersions struct {
    82  	// Name of the volume.
    83  	Volume string
    84  
    85  	// Name of the file.
    86  	Name string
    87  
    88  	IsEmptyDir bool
    89  
    90  	// Represents the latest mod time of the
    91  	// latest version.
    92  	LatestModTime time.Time
    93  
    94  	Versions []FileInfo
    95  }
    96  
    97  // findVersionIndex will return the version index where the version
    98  // was found. Returns -1 if not found.
    99  func (f *FileInfoVersions) findVersionIndex(v string) int {
   100  	if f == nil || v == "" {
   101  		return -1
   102  	}
   103  	for i, ver := range f.Versions {
   104  		if ver.VersionID == v {
   105  			return i
   106  		}
   107  	}
   108  	return -1
   109  }
   110  
   111  // FileInfo - represents file stat information.
   112  //msgp:tuple FileInfo
   113  // The above means that any added/deleted fields are incompatible.
   114  type FileInfo struct {
   115  	// Name of the volume.
   116  	Volume string
   117  
   118  	// Name of the file.
   119  	Name string
   120  
   121  	// Version of the file.
   122  	VersionID string
   123  
   124  	// Indicates if the version is the latest
   125  	IsLatest bool
   126  
   127  	// Deleted is set when this FileInfo represents
   128  	// a deleted marker for a versioned bucket.
   129  	Deleted bool
   130  
   131  	// TransitionStatus is set to Pending/Complete for transitioned
   132  	// entries based on state of transition
   133  	TransitionStatus string
   134  
   135  	// DataDir of the file
   136  	DataDir string
   137  
   138  	// Indicates if this object is still in V1 format.
   139  	XLV1 bool
   140  
   141  	// Date and time when the file was last modified, if Deleted
   142  	// is 'true' this value represents when while was deleted.
   143  	ModTime time.Time
   144  
   145  	// Total file size.
   146  	Size int64
   147  
   148  	// File mode bits.
   149  	Mode uint32
   150  
   151  	// File metadata
   152  	Metadata map[string]string
   153  
   154  	// All the parts per object.
   155  	Parts []ObjectPartInfo
   156  
   157  	// Erasure info for all objects.
   158  	Erasure ErasureInfo
   159  
   160  	// DeleteMarkerReplicationStatus is set when this FileInfo represents
   161  	// replication on a DeleteMarker
   162  	MarkDeleted                   bool // mark this version as deleted
   163  	DeleteMarkerReplicationStatus string
   164  	VersionPurgeStatus            VersionPurgeStatusType
   165  
   166  	Data []byte // optionally carries object data
   167  
   168  	NumVersions      int
   169  	SuccessorModTime time.Time
   170  }
   171  
   172  // VersionPurgeStatusKey denotes purge status in metadata
   173  const VersionPurgeStatusKey = "purgestatus"
   174  
   175  // VersionPurgeStatusType represents status of a versioned delete or permanent delete w.r.t bucket replication
   176  type VersionPurgeStatusType string
   177  
   178  const (
   179  	// Pending - versioned delete replication is pending.
   180  	Pending VersionPurgeStatusType = "PENDING"
   181  
   182  	// Complete - versioned delete replication is now complete, erase version on disk.
   183  	Complete VersionPurgeStatusType = "COMPLETE"
   184  
   185  	// Failed - versioned delete replication failed.
   186  	Failed VersionPurgeStatusType = "FAILED"
   187  )
   188  
   189  // Empty returns true if purge status was not set.
   190  func (v VersionPurgeStatusType) Empty() bool {
   191  	return string(v) == ""
   192  }
   193  
   194  // Pending returns true if the version is pending purge.
   195  func (v VersionPurgeStatusType) Pending() bool {
   196  	return v == Pending || v == Failed
   197  }
   198  
   199  // newFileInfo - initializes new FileInfo, allocates a fresh erasure info.
   200  func newFileInfo(object string, dataBlocks, parityBlocks int) (fi FileInfo) {
   201  	fi.Erasure = ErasureInfo{
   202  		Algorithm:    erasureAlgorithm,
   203  		DataBlocks:   dataBlocks,
   204  		ParityBlocks: parityBlocks,
   205  		BlockSize:    blockSizeV2,
   206  		Distribution: hashOrder(object, dataBlocks+parityBlocks),
   207  	}
   208  	return fi
   209  }