github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/lsmkv/strategies.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package lsmkv
    13  
    14  import (
    15  	"fmt"
    16  
    17  	"github.com/weaviate/weaviate/adapters/repos/db/lsmkv/segmentindex"
    18  )
    19  
    20  const (
    21  	// StrategyReplace allows for idem-potent PUT where the latest takes presence
    22  	StrategyReplace       = "replace"
    23  	StrategySetCollection = "setcollection"
    24  	StrategyMapCollection = "mapcollection"
    25  	StrategyRoaringSet    = "roaringset"
    26  )
    27  
    28  func SegmentStrategyFromString(in string) segmentindex.Strategy {
    29  	switch in {
    30  	case StrategyReplace:
    31  		return segmentindex.StrategyReplace
    32  	case StrategySetCollection:
    33  		return segmentindex.StrategySetCollection
    34  	case StrategyMapCollection:
    35  		return segmentindex.StrategyMapCollection
    36  	case StrategyRoaringSet:
    37  		return segmentindex.StrategyRoaringSet
    38  	default:
    39  		panic("unsupported strategy")
    40  	}
    41  }
    42  
    43  func IsExpectedStrategy(strategy string, expectedStrategies ...string) bool {
    44  	if len(expectedStrategies) == 0 {
    45  		expectedStrategies = []string{StrategyReplace, StrategySetCollection, StrategyMapCollection, StrategyRoaringSet}
    46  	}
    47  
    48  	for _, s := range expectedStrategies {
    49  		if s == strategy {
    50  			return true
    51  		}
    52  	}
    53  	return false
    54  }
    55  
    56  func CheckExpectedStrategy(strategy string, expectedStrategies ...string) {
    57  	if !IsExpectedStrategy(strategy, expectedStrategies...) {
    58  		panic(fmt.Sprintf("one of strategies %v expected, strategy '%s' found", expectedStrategies, strategy))
    59  	}
    60  }