Skip to content

Commit

Permalink
fix: workaround sizeBytes unit suffix (#359)
Browse files Browse the repository at this point in the history
Signed-off-by: Aylei <[email protected]>
  • Loading branch information
aylei authored May 18, 2023
1 parent 95346a4 commit ef0e13b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
16 changes: 13 additions & 3 deletions pkg/controllers/common/fileservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/matrixorigin/controller-runtime/pkg/util"
"github.com/matrixorigin/matrixone-operator/api/core/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"strings"
)

Expand All @@ -39,6 +40,8 @@ const (
awsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
awsRegion = "AWS_REGION"
defaultAWSRegion = "us-west-2"

byteSuffix = "B"
)

// SetStorageProviderConfig set inject configuration of storage provider to Pods
Expand Down Expand Up @@ -73,7 +76,7 @@ func FileServiceConfig(localPath string, sp v1alpha1.SharedStorageProvider, v *v
}
if v != nil && v.MemoryCacheSize != nil {
localFS["cache"] = map[string]string{
"memory-capacity": v.MemoryCacheSize.String(),
"memory-capacity": asSizeBytes(*v.MemoryCacheSize),
}
}
// MO Operator currently unifies the storage DB data and ETL data to a single shared storage
Expand Down Expand Up @@ -131,10 +134,10 @@ func sharedFileServiceConfig(sp v1alpha1.SharedStorageProvider, cache *v1alpha1.
if cache != nil {
c := map[string]string{}
if cache.MemoryCacheSize != nil {
c["memory-capacity"] = cache.MemoryCacheSize.String()
c["memory-capacity"] = asSizeBytes(*cache.MemoryCacheSize)
}
if cache.DiskCacheSize != nil {
c["disk-capacity"] = cache.DiskCacheSize.String()
c["disk-capacity"] = asSizeBytes(*cache.DiskCacheSize)
switch name {
case s3FileServiceName:
c["disk-path"] = fmt.Sprintf("%s/%s", DataPath, S3CacheDir)
Expand All @@ -149,3 +152,10 @@ func sharedFileServiceConfig(sp v1alpha1.SharedStorageProvider, cache *v1alpha1.

return m
}

// asSizeBytes convert a Quantity to a size byte string
func asSizeBytes(q resource.Quantity) string {
// workaround https://github.com/matrixorigin/matrixone/issues/9507,
// will still keep this after the issue get fixed for better compatibility
return q.String() + byteSuffix
}
18 changes: 9 additions & 9 deletions pkg/controllers/common/fileservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestFileServiceConfig(t *testing.T) {
v *v1alpha1.Volume
c *v1alpha1.SharedStorageCache
}
quantity1Gi := resource.MustParse("1Gi")
quantity1GiB := resource.MustParse("1Gi")
tests := []struct {
name string
args args
Expand Down Expand Up @@ -86,11 +86,11 @@ func TestFileServiceConfig(t *testing.T) {
},
},
v: &v1alpha1.Volume{
MemoryCacheSize: &quantity1Gi,
MemoryCacheSize: &quantity1GiB,
},
c: &v1alpha1.SharedStorageCache{
MemoryCacheSize: &quantity1Gi,
DiskCacheSize: &quantity1Gi,
MemoryCacheSize: &quantity1GiB,
DiskCacheSize: &quantity1GiB,
},
},
want: map[string]interface{}{
Expand All @@ -100,7 +100,7 @@ func TestFileServiceConfig(t *testing.T) {
"data-dir": "/test",
"backend": "DISK",
"cache": map[string]string{
"memory-capacity": "1Gi",
"memory-capacity": "1GiB",
},
}, {
"name": "S3",
Expand All @@ -111,9 +111,9 @@ func TestFileServiceConfig(t *testing.T) {
"bucket": "bucket",
},
"cache": map[string]string{
"memory-capacity": "1Gi",
"memory-capacity": "1GiB",
"disk-path": "/var/lib/matrixone/disk-cache",
"disk-capacity": "1Gi",
"disk-capacity": "1GiB",
},
}, {
"name": "ETL",
Expand All @@ -124,9 +124,9 @@ func TestFileServiceConfig(t *testing.T) {
"bucket": "bucket",
},
"cache": map[string]string{
"memory-capacity": "1Gi",
"memory-capacity": "1GiB",
"disk-path": "/var/lib/matrixone/etl-cache",
"disk-capacity": "1Gi",
"disk-capacity": "1GiB",
},
}},
},
Expand Down

0 comments on commit ef0e13b

Please sign in to comment.