-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: add new cmdline args to enable read affinity
This commit adds new cmdline args `enable-read-affinity` and `crush-location-labels` to facilitate new feature of using crush location labels from node labels to enable read affinity using ceph's `read_from_replica=localize` feature. This feature redirect reads to the nearest OSD. This will be currently used only during rbd map cmd. Signed-off-by: Rakshith R <rar@redhat.com>
- Loading branch information
1 parent
c3d5b78
commit ad9a2aa
Showing
9 changed files
with
218 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2023 The Ceph-CSI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ceph/ceph-csi/internal/util/log" | ||
) | ||
|
||
// GetCrushLocationMap returns the crush location map, determined from | ||
// the crush location labels and their values from the CO system. | ||
// Expects crushLocationLabels in arg to be in the format "[prefix/]<name>,[prefix/]<name>,...",. | ||
// Returns map of crush location types with its array of associated values. | ||
func GetCrushLocationMap(crushLocationLabels, nodeName string) (map[string]string, error) { | ||
if crushLocationLabels == "" { | ||
return nil, nil | ||
} | ||
|
||
nodeLabels, err := k8sGetNodeLabels(nodeName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return getCrushLocationMap(crushLocationLabels, nodeLabels), nil | ||
} | ||
|
||
// getCrushLocationMap returns the crush location map, determined from | ||
// the crush location labels and node labels. | ||
func getCrushLocationMap(crushLocationLabels string, nodeLabels map[string]string) map[string]string { | ||
labelsToRead := strings.SplitN(crushLocationLabels, labelSeparator, -1) | ||
log.DefaultLog("crush location labels passed for processing: %+v", labelsToRead) | ||
|
||
labelsIn := make(map[string]bool) | ||
for _, label := range labelsToRead { | ||
labelsIn[label] = true | ||
} | ||
|
||
// Determine values for requested labels from node labels | ||
crushLocationMap := make(map[string]string) | ||
for key, value := range nodeLabels { | ||
if _, ok := labelsIn[key]; ok { | ||
// label found split name component and store value | ||
nameIdx := strings.IndexRune(key, keySeparator) | ||
crushLocationType := strings.TrimSpace(key[nameIdx+1:]) | ||
// replace "." with "-" to satisfy ceph crush map. | ||
value = strings.Replace(strings.TrimSpace(value), ".", "-", -1) | ||
crushLocationMap[crushLocationType] = value | ||
} | ||
} | ||
|
||
if len(crushLocationMap) == 0 { | ||
return nil | ||
} | ||
log.DefaultLog("list of crush location processed: %+v", crushLocationMap) | ||
|
||
return crushLocationMap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright 2023 The Ceph-CSI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getCrushLocationMap(t *testing.T) { | ||
type args struct { | ||
crushLocationLabels string | ||
nodeLabels map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "empty crushLocationLabels", | ||
args: args{ | ||
crushLocationLabels: "", | ||
nodeLabels: map[string]string{}, | ||
}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "empty nodeLabels", | ||
args: args{ | ||
crushLocationLabels: "topology.io/zone,topology.io/rack", | ||
nodeLabels: map[string]string{}, | ||
}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "matching crushlocation and node labels", | ||
args: args{ | ||
crushLocationLabels: "topology.io/zone,topology.io/rack", | ||
nodeLabels: map[string]string{ | ||
"topology.io/zone": "zone1", | ||
}, | ||
}, | ||
want: map[string]string{"zone": "zone1"}, | ||
}, | ||
{ | ||
name: "multuple matching crushlocation and node labels", | ||
args: args{ | ||
crushLocationLabels: "topology.io/zone,topology.io/rack", | ||
nodeLabels: map[string]string{ | ||
"topology.io/zone": "zone1", | ||
"topology.io/rack": "rack1", | ||
}, | ||
}, | ||
want: map[string]string{"zone": "zone1", "rack": "rack1"}, | ||
}, | ||
{ | ||
name: "no match between crushlocation and node labels", | ||
args: args{ | ||
crushLocationLabels: "topology.io/zone,topology.io/rack", | ||
nodeLabels: map[string]string{ | ||
"topology.io/region": "zone1", | ||
}, | ||
}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "check crushlocation value replacement to satify ceph requirement", | ||
args: args{ | ||
crushLocationLabels: "topology.io/zone,topology.io/rack", | ||
nodeLabels: map[string]string{ | ||
"topology.io/zone": "south.east.1", | ||
}, | ||
}, | ||
want: map[string]string{"zone": "south-east-1"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.want, getCrushLocationMap(tt.args.crushLocationLabels, tt.args.nodeLabels)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters