From e55a8c9a69e8ba0d5f376d57ab67eadb44718211 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 21 May 2020 16:36:50 -0400 Subject: [PATCH] journal: change omap set func to handle multiple key-value pairs For any function that sets more than one key on a single oid setting them as a batch will be more efficient. Signed-off-by: John Mulligan --- internal/journal/omap.go | 19 ++++++++-------- internal/journal/voljournal.go | 41 ++++++++++++---------------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/internal/journal/omap.go b/internal/journal/omap.go index f01ed2421b7b..caf0858d26d4 100644 --- a/internal/journal/omap.go +++ b/internal/journal/omap.go @@ -89,10 +89,10 @@ func removeMapKeys( return err } -func setOneOMapKey( +func setOMapKeys( ctx context.Context, conn *Connection, - poolName, namespace, oMapName, oMapKey, keyValue string) error { + poolName, namespace, oid string, pairs map[string]string) error { // fetch and configure the rados ioctx ioctx, err := conn.conn.GetIoctx(poolName) if err != nil { @@ -104,18 +104,19 @@ func setOneOMapKey( ioctx.SetNamespace(namespace) } - pairs := map[string][]byte{ - oMapKey: []byte(keyValue), + bpairs := make(map[string][]byte, len(pairs)) + for k, v := range pairs { + bpairs[k] = []byte(v) } - err = ioctx.SetOmap(oMapName, pairs) + err = ioctx.SetOmap(oid, bpairs) if err != nil { klog.Errorf( - util.Log(ctx, "failed setting omap key (pool=%q, namespace=%q, name=%q, key=%q, value=%q): %v"), - poolName, namespace, oMapName, oMapKey, keyValue, err) + util.Log(ctx, "failed setting omap key (pool=%q, namespace=%q, name=%q, pairs=%#v): %v"), + poolName, namespace, oid, pairs, err) } else { klog.Infof( - util.Log(ctx, "XXX set omap key (pool=%q, namespace=%q, name=%q, key=%q, value=%q): %v"), - poolName, namespace, oMapName, oMapKey, keyValue, err) + util.Log(ctx, "XXX set omap key (pool=%q, namespace=%q, name=%q, pairs=%%#v): %v"), + poolName, namespace, oid, pairs, err) } return err } diff --git a/internal/journal/voljournal.go b/internal/journal/voljournal.go index 4fc77b069ef4..f56e680aafed 100644 --- a/internal/journal/voljournal.go +++ b/internal/journal/voljournal.go @@ -517,8 +517,8 @@ func (conn *Connection) ReserveName(ctx context.Context, nameKeyVal = volUUID } - err = setOneOMapKey(ctx, conn, journalPool, cj.namespace, cj.csiDirectory, - cj.csiNameKeyPrefix+reqName, nameKeyVal) + err = setOMapKeys(ctx, conn, journalPool, cj.namespace, cj.csiDirectory, + map[string]string{cj.csiNameKeyPrefix + reqName: nameKeyVal}) if err != nil { return "", "", err } @@ -532,30 +532,21 @@ func (conn *Connection) ReserveName(ctx context.Context, } }() + oid := cj.cephUUIDDirectoryPrefix + volUUID + omapValues := map[string]string{} + // NOTE: UUID directory is stored on the same pool as the image, helps determine image attributes // and also CSI journal pool, when only the VolumeID is passed in (e.g DeleteVolume/DeleteSnapshot, // VolID during CreateSnapshot). // Update UUID directory to store CSI request name - err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, - cj.csiNameKey, reqName) - if err != nil { - return "", "", err - } + omapValues[cj.csiNameKey] = reqName // Update UUID directory to store image name - err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, - cj.csiImageKey, imageName) - if err != nil { - return "", "", err - } + omapValues[cj.csiImageKey] = imageName // Update UUID directory to store encryption values if kmsConf != "" { - err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, - cj.encryptKMSKey, kmsConf) - if err != nil { - return "", "", err - } + omapValues[cj.encryptKMSKey] = kmsConf } if journalPool != imagePool && journalPoolID != util.InvalidPoolID { @@ -564,22 +555,18 @@ func (conn *Connection) ReserveName(ctx context.Context, journalPoolIDStr := hex.EncodeToString(buf64) // Update UUID directory to store CSI journal pool name (prefer ID instead of name to be pool rename proof) - err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, - cj.csiJournalPool, journalPoolIDStr) - if err != nil { - return "", "", err - } + omapValues[cj.csiJournalPool] = journalPoolIDStr } if snapSource { // Update UUID directory to store source volume UUID in case of snapshots - err = setOneOMapKey(ctx, conn, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, - cj.cephSnapSourceKey, parentName) - if err != nil { - return "", "", err - } + omapValues[cj.cephSnapSourceKey] = parentName } + err = setOMapKeys(ctx, conn, journalPool, cj.namespace, oid, omapValues) + if err != nil { + return "", "", err + } return volUUID, imageName, nil }