Skip to content

Commit ade95b3

Browse files
authored
Merge pull request #1719 from Sneha-at/data-cache
Add separate flags for node and controller and hash nodeId
2 parents cb563a1 + 787e817 commit ade95b3

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ SHELL ["/bin/bash", "-c"]
148148
RUN /bin/sed -i -e "s/.*allow_mixed_block_sizes = 0.*/ allow_mixed_block_sizes = 1/" /etc/lvm/lvm.conf
149149
RUN /bin/sed -i -e "s/.*udev_sync = 1.*/ udev_sync = 0/" /etc/lvm/lvm.conf
150150
RUN /bin/sed -i -e "s/.*udev_rules = 1.*/ udev_rules = 0/" /etc/lvm/lvm.conf
151+
RUN /bin/sed -i -e "s/.*locking_dir = .*/ locking_dir = \"\/tmp\"/" /etc/lvm/lvm.conf
152+
151153

152154
# Build stage used for validation of the output-image
153155
# See validate-container-linux-* targets in Makefile

cmd/gce-pd-csi-driver/main.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ var (
6767
maxConcurrentFormat = flag.Int("max-concurrent-format", 1, "The maximum number of concurrent format exec calls")
6868
concurrentFormatTimeout = flag.Duration("concurrent-format-timeout", 1*time.Minute, "The maximum duration of a format operation before its concurrency token is released")
6969

70-
maxConcurrentFormatAndMount = flag.Int("max-concurrent-format-and-mount", 1, "If set then format and mount operations are serialized on each node. This is stronger than max-concurrent-format as it includes fsck and other mount operations")
71-
formatAndMountTimeout = flag.Duration("format-and-mount-timeout", 1*time.Minute, "The maximum duration of a format and mount operation before another such operation will be started. Used only if --serialize-format-and-mount")
72-
fallbackRequisiteZonesFlag = flag.String("fallback-requisite-zones", "", "Comma separated list of requisite zones that will be used if there are not sufficient zones present in requisite topologies when provisioning a disk")
73-
enableStoragePoolsFlag = flag.Bool("enable-storage-pools", false, "If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools")
74-
enableDataCacheFlag = flag.Bool("enable-data-cache", false, "If set to true, the CSI Driver will allow volumes to be provisioned with data cache configuration")
70+
maxConcurrentFormatAndMount = flag.Int("max-concurrent-format-and-mount", 1, "If set then format and mount operations are serialized on each node. This is stronger than max-concurrent-format as it includes fsck and other mount operations")
71+
formatAndMountTimeout = flag.Duration("format-and-mount-timeout", 1*time.Minute, "The maximum duration of a format and mount operation before another such operation will be started. Used only if --serialize-format-and-mount")
72+
fallbackRequisiteZonesFlag = flag.String("fallback-requisite-zones", "", "Comma separated list of requisite zones that will be used if there are not sufficient zones present in requisite topologies when provisioning a disk")
73+
enableStoragePoolsFlag = flag.Bool("enable-storage-pools", false, "If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools")
74+
enableControllerDataCacheFlag = flag.Bool("enable-controller-data-cache", false, "If set to true, the CSI Driver will allow volumes to be provisioned with data cache configuration")
75+
enableNodeDataCacheFlag = flag.Bool("enable-node-data-cache", false, "If set to true, the CSI Driver will allow volumes to be provisioned with data cache configuration")
7576

7677
multiZoneVolumeHandleDiskTypesFlag = flag.String("multi-zone-volume-handle-disk-types", "", "Comma separated list of allowed disk types that can use the multi-zone volumeHandle. Used only if --multi-zone-volume-handle-enable")
7778
multiZoneVolumeHandleEnableFlag = flag.Bool("multi-zone-volume-handle-enable", false, "If set to true, the multi-zone volumeHandle feature will be enabled")
@@ -209,7 +210,7 @@ func handle() {
209210
}
210211
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
211212
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
212-
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, *enableDataCacheFlag, multiZoneVolumeHandleConfig, listVolumesConfig)
213+
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, *enableControllerDataCacheFlag, multiZoneVolumeHandleConfig, listVolumesConfig)
213214
} else if *cloudConfigFilePath != "" {
214215
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
215216
}
@@ -227,13 +228,13 @@ func handle() {
227228
if err != nil {
228229
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
229230
}
230-
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, *enableDataCacheFlag)
231+
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, *enableNodeDataCacheFlag)
231232
if *maxConcurrentFormatAndMount > 0 {
232233
nodeServer = nodeServer.WithSerializedFormatAndMount(*formatAndMountTimeout, *maxConcurrentFormatAndMount)
233234
}
234235
}
235236

236-
if *enableDataCacheFlag {
237+
if *enableNodeDataCacheFlag {
237238
klog.V(2).Info("Raiding local ssds to setup data cache")
238239
err := driver.RaidLocalSsds()
239240
if err != nil {

pkg/common/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"hash/fnv"
2324
"net/http"
2425
"regexp"
2526
"strings"
@@ -72,6 +73,7 @@ const (
7273
// Full or partial URL of the machine type resource, in the format:
7374
// zones/zone/machineTypes/machine-type
7475
machineTypePattern = "zones/[^/]+/machineTypes/([^/]+)$"
76+
alphanums = "bcdfghjklmnpqrstvwxz2456789"
7577
)
7678

7779
var (
@@ -617,3 +619,16 @@ func NewLimiter(limit, burst int, emptyBucket bool) *rate.Limiter {
617619

618620
return limiter
619621
}
622+
623+
// shortString is inspired by k8s.io/apimachinery/pkg/util/rand.SafeEncodeString, but takes data from a hash.
624+
func ShortString(s string) string {
625+
hasher := fnv.New128a()
626+
hasher.Write([]byte(s))
627+
sum := hasher.Sum([]byte{})
628+
const sz = 8
629+
short := make([]byte, sz)
630+
for i := 0; i < sz; i++ {
631+
short[i] = alphanums[int(sum[i])%len(alphanums)]
632+
}
633+
return string(short)
634+
}

pkg/gce-pd-csi-driver/cache.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ func cleanupCache(volumeId string, nodeId string) error {
241241
func getVolumeGroupName(nodePath string) string {
242242
nodeSlice := strings.Split(nodePath, "/")
243243
nodeId := nodeSlice[len(nodeSlice)-1]
244-
return fmt.Sprintf("csi-vg-%s", nodeId)
244+
nodeHash := common.ShortString(nodeId)
245+
return fmt.Sprintf("csi-vg-%s", nodeHash)
245246
}
246247

247248
func getLvName(suffix string, volumeId string) string {
@@ -257,12 +258,14 @@ func createVg(volumeGroupName string, devicePath string, raidedLocalSsds string)
257258
"y",
258259
volumeGroupName,
259260
raidedLocalSsds,
261+
"-v",
260262
}
261263
info, err := common.RunCommand("" /* pipedCmd */, "" /* pipedCmdArg */, "vgcreate", args...)
262264
if err != nil {
263265
klog.Errorf("vgcreate error %v: %s", err, info)
264266
return fmt.Errorf("vgcreate error %w: %s", err, info)
265267
}
268+
klog.Infof("Volume group creation succeeded for %v", volumeGroupName)
266269

267270
klog.V(2).Infof("============================== vgscan after vgcreate ==============================")
268271
args = []string{}
@@ -298,19 +301,27 @@ func RaidLocalSsds() error {
298301
klog.V(2).Infof("============================== Local SSDs are already RAIDed ==============================")
299302
return nil
300303
}
301-
info, err := common.RunCommand("grep" /* pipedCmd */, "DevicePath" /* pipeCmdArg */, "nvme", []string{"list", "-o", "json"}...)
304+
info, err := common.RunCommand("" /* pipedCmd */, "" /* pipeCmdArg */, "nvme", []string{"list", "-o", "json"}...)
302305
if err != nil {
303306
return fmt.Errorf("errored while scanning available NVME disks info: %v; err:%v", info, err)
304307
}
305-
infoString := strings.ReplaceAll(string(info), "\"", "")
306-
infoString = strings.TrimSpace(strings.ReplaceAll(infoString, ",", " "))
307-
infoSlice := strings.Split(infoString, "\n")
308-
klog.V(2).Infof("============================== NVME list %v ==============================", infoSlice)
308+
infoString := strings.TrimSpace(strings.ReplaceAll(string(info), "\n", " "))
309+
klog.V(2).Infof("============================== NVME list %v ==============================", infoString)
310+
infoString = strings.ReplaceAll(infoString, "\"", "")
311+
infoString = strings.ReplaceAll(infoString, " :", ":")
312+
infoString = strings.ReplaceAll(infoString, ": ", ":")
313+
infoString = strings.ReplaceAll(infoString, ",", " ")
314+
infoSlice := strings.Split(infoString, " ")
315+
309316
diskList := []string{}
310317
for _, diskInfo := range infoSlice {
311318
diskName := strings.TrimSpace(diskInfo)
312-
diskName = strings.TrimSpace(strings.Split(diskName, ":")[1])
313-
diskList = append(diskList, diskName)
319+
320+
if strings.Contains(diskName, "DevicePath") {
321+
diskName := strings.TrimSpace(strings.Split(diskName, ":")[1])
322+
323+
diskList = append(diskList, diskName)
324+
}
314325
}
315326
nvmeDiskCount := len(diskList)
316327
nvmeDiskList := strings.Join(diskList, " ")

test/e2e/utils/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func GCEClientAndDriverSetup(instance *remote.InstanceInfo, computeEndpoint stri
6060
"--multi-zone-volume-handle-disk-types=pd-standard",
6161
"--use-instance-api-to-poll-attachment-disk-types=pd-ssd",
6262
"--use-instance-api-to-list-volumes-published-nodes",
63-
"--enable-data-cache",
63+
"--enable-controller-data-cache",
64+
"--enable-node-data-cache",
6465
}
6566
extra_flags = append(extra_flags, fmt.Sprintf("--compute-endpoint=%s", computeEndpoint))
6667

test/run-e2e-local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ if hostname | grep -q c.googlers.com ; then
1616
CLOUDTOP_HOST=--cloudtop-host
1717
fi
1818

19-
ginkgo --v --focus "Should create->attach->setup caching->write->detach->attach to different node->mount->read" "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" "${CLOUDTOP_HOST}" --v=6 --logtostderr
19+
ginkgo --v "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" "${CLOUDTOP_HOST}" --v=6 --logtostderr

0 commit comments

Comments
 (0)