github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/api/apc/write_policy.go (about)

     1  // Package apc: API control messages and constants
     2  /*
     3   * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package apc
     6  
     7  import "fmt"
     8  
     9  // write policy (enum and accessors)
    10  // applies to both AIS metadata and data; bucket-configurable with global defaults via cluster config
    11  type WritePolicy string
    12  
    13  const (
    14  	WriteImmediate = WritePolicy("immediate") // immediate write (default)
    15  	WriteDelayed   = WritePolicy("delayed")   // cache and flush when not accessed for a while (lom_cache_hk.go)
    16  	WriteNever     = WritePolicy("never")     // transient - in-memory only
    17  
    18  	WriteDefault = WritePolicy("") // same as `WriteImmediate` - see IsImmediate() below
    19  )
    20  
    21  var SupportedWritePolicy = []string{string(WriteImmediate), string(WriteDelayed), string(WriteNever)}
    22  
    23  func (wp WritePolicy) IsImmediate() bool { return wp == WriteDefault || wp == WriteImmediate }
    24  
    25  func (wp WritePolicy) Validate() (err error) {
    26  	if wp.IsImmediate() || wp == WriteDelayed || wp == WriteNever {
    27  		return
    28  	}
    29  	return fmt.Errorf("invalid write policy %q (expecting one of %v)", wp, SupportedWritePolicy)
    30  }