go.temporal.io/server@v1.23.0/common/persistence/size_util.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package persistence
    26  
    27  import (
    28  	commonpb "go.temporal.io/api/common/v1"
    29  )
    30  
    31  func sizeOfBlob(
    32  	blob *commonpb.DataBlob,
    33  ) int {
    34  	return blob.Size()
    35  }
    36  
    37  func sizeOfInt64Set(
    38  	int64Set map[int64]struct{},
    39  ) int {
    40  	// 8 == 64 bit / 8 bit per byte
    41  	return 8 * len(int64Set)
    42  }
    43  
    44  func sizeOfStringSet(
    45  	stringSet map[string]struct{},
    46  ) int {
    47  	size := 0
    48  	for requestID := range stringSet {
    49  		size += len(requestID)
    50  	}
    51  	return size
    52  }
    53  
    54  func sizeOfInt64BlobMap(
    55  	kvBlob map[int64]*commonpb.DataBlob,
    56  ) int {
    57  	// 8 == 64 bit / 8 bit per byte
    58  	size := 8 * len(kvBlob)
    59  	for _, blob := range kvBlob {
    60  		size += blob.Size()
    61  	}
    62  	return size
    63  }
    64  
    65  func sizeOfStringBlobMap(
    66  	kvBlob map[string]*commonpb.DataBlob,
    67  ) int {
    68  	size := 0
    69  	for id, blob := range kvBlob {
    70  		// 8 == 64 bit / 8 bit per byte
    71  		size += len(id) + blob.Size()
    72  	}
    73  	return size
    74  }
    75  
    76  func sizeOfStringSlice(
    77  	stringSlice []string,
    78  ) int {
    79  	size := 0
    80  	for _, str := range stringSlice {
    81  		size += len(str)
    82  	}
    83  	return size
    84  }
    85  
    86  func sizeOfBlobSlice(
    87  	blobSlice []*commonpb.DataBlob,
    88  ) int {
    89  	size := 0
    90  	for _, blob := range blobSlice {
    91  		size += blob.Size()
    92  	}
    93  	return size
    94  }