Repository navigation
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an in-memory label index to the OMAP store and a new Changes
Sequence DiagramsequenceDiagram
actor Client
participant VolumeManager
participant Store
participant Index
Note over Client,Index: Filter-before-processing flow (when label index available)
Client->>VolumeManager: ListVolumes(labelSelector)
VolumeManager->>Store: ListByLabels(labelSelector)
Store->>Index: Lookup IDs per label (set intersections)
Index-->>Store: Matching ID set
Store->>Store: Materialize objects for IDs (Get)
Store-->>VolumeManager: Filtered objects
VolumeManager-->>Client: Converted API volumes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
internal/omap/omap.go (1)
510-518: Consider continuing pastNotFounderrors for individual objects.When iterating through the intersection, if an object was deleted between index lookup and
Get, the entireListByLabelscall fails. Since this is a list operation, it may be more appropriate to log the error and continue, similar to howlistAndConvertinvolume_list.gohandles conversion errors.♻️ Proposed change to handle stale index entries gracefully
for id := range intersection { obj, err := s.Get(ctx, id) if err != nil { - s.log.Error(err, "Failed to get object from store during ListByLabels", "id", id) - return nil, err + if errors.Is(err, store.ErrNotFound) { + // Object was deleted after index lookup; skip stale entry + s.log.V(1).Info("Object removed between index lookup and Get, skipping", "id", id) + continue + } + s.log.Error(err, "Failed to get object from store during ListByLabels", "id", id) + return nil, err } objs = append(objs, obj) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 510 - 518, The loop in ListByLabels using intersection currently returns on any s.Get error causing the whole list to fail; instead replicate the resilient behavior used in listAndConvert (volume_list.go): call s.Get(ctx, id) for each id, if it returns a NotFound-style error (e.g., apierrors.IsNotFound/Is(err, fs.ErrNotExist) depending on your project error type) then log a warning via s.log (including the id) and continue to the next id, only append obj to objs when Get succeeds; for any non-NotFound error still return the error. This keeps stale index entries from failing ListByLabels while preserving real error handling.internal/volumeserver/volume_list.go (2)
108-111: Consider refactoring to avoidgoto.While functional,
gotois generally non-idiomatic in Go. This could be restructured using a helper function or by inverting the condition.♻️ Alternative approach without goto
// Fast path for LabelSelector filter (using the new index) if filter != nil && len(filter.LabelSelector) > 0 { log.V(1).Info("Filtering by Label Selector using index", "Selector", filter.LabelSelector) - listerWithLabels, ok := s.imageStore.(imageListerWithLabels[*api.Image]) - if !ok { - log.Error(fmt.Errorf("imageStore does not support ListByLabels"), "Cannot use label index optimization") - goto SlowPath - } - - cephImages, err := listerWithLabels.ListByLabels(ctx, filter.LabelSelector) - ... - return &iri.ListVolumesResponse{Volumes: volumes}, nil + if listerWithLabels, ok := s.imageStore.(imageListerWithLabels[*api.Image]); ok { + cephImages, err := listerWithLabels.ListByLabels(ctx, filter.LabelSelector) + ... + return &iri.ListVolumesResponse{Volumes: volumes}, nil + } + log.V(1).Info("imageStore does not support ListByLabels, falling back to slow path") } - - // Slow path: No specific filter or fallback -SlowPath: + // Slow path: No specific filter or fallback log.V(1).Info("Listing all volumes (no specific filter or fallback)")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/volumeserver/volume_list.go` around lines 108 - 111, The use of goto to jump to SlowPath should be removed by restructuring the flow: either invert the condition so when imageStore supports ListByLabels you run the fast path and otherwise call a clearly named helper (e.g., handleSlowPath or listImagesSlowly) that contains the SlowPath logic, or extract the entire slow-path block into a helper and call it instead of using goto; update references to imageStore and its ListByLabels check (the current if !ok { ... goto SlowPath }) to call the helper or return/continue appropriately so no goto/label is needed.
28-33: Dead code: capability check result is unused.The type assertion result at line 29 is stored in
okbut never used to alter behavior. The function proceeds identically regardless of whetherimageStoreimplementsListByLabels. This warning log provides no value since it doesn't affect theGetoperation that follows.Consider removing this check from
getIriVolumesince it's only relevant forListVolumes.♻️ Proposed removal of unused check
func (s *Server) getIriVolume(ctx context.Context, log logr.Logger, imageId string) (*iri.Volume, error) { - _, ok := s.imageStore.(imageListerWithLabels[*api.Image]) - if !ok { - log.V(0).Info("Warning: imageStore does not implement ListByLabels, falling back to Get") - // If ListByLabels is crucial, you might return an error here instead. - } - cephImage, err := s.imageStore.Get(ctx, imageId)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/volumeserver/volume_list.go` around lines 28 - 33, The type-assertion check in getIriVolume that does "_, ok := s.imageStore.(imageListerWithLabels[*api.Image])" is dead — its bool is never used and the function behavior doesn't change — so remove that assertion and the surrounding log; ensure getIriVolume no longer references imageListerWithLabels or logs the fallback, leaving the subsequent Get logic intact; if ListByLabels capability must be checked elsewhere, keep or move the check to ListVolumes where it's actually used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@go.mod`:
- Around line 126-131: Update the indirect dependency
go.opentelemetry.io/otel/sdk to v1.43.0 or newer to address GHSA-hfvc-g4fc-pqhx;
locate the go.mod entry for go.opentelemetry.io/otel/sdk and change its version
to v1.43.0+ (and run go get or tidy to update sums), and ensure any related otel
modules (e.g., go.opentelemetry.io/otel, go.opentelemetry.io/otel/trace,
otlptrace) remain compatible after the upgrade.
In `@internal/omap/omap.go`:
- Around line 80-84: Add a dedicated mutex (e.g., labelIndexMu sync.RWMutex) to
protect the shared labelIndex map and use it in the functions that access it:
acquire labelIndexMu.Lock()/Unlock() around mutations in updateLabelIndex and
removeFromLabelIndex, and use labelIndexMu.RLock()/RUnlock() in ListByLabels
when reading; keep existing idMu for per-ID locking but ensure all reads/writes
to labelIndex go through the new labelIndexMu to prevent concurrent map access.
In `@internal/volumeserver/volume_list.go`:
- Around line 104-138: The fast path uses imageListerWithLabels.ListByLabels to
apply filter.LabelSelector, but when the store lacks that interface the SlowPath
falls back to s.listVolumes and returns all volumes without applying the
selector; update the SlowPath to either return an error or (recommended) perform
in-memory label filtering after s.listVolumes by using the existing
s.listAndConvert or inspecting volume.Metadata.Labels — iterate the returned
volumes and keep only those where every key/value in filter.LabelSelector
matches (implement a small helper like matchesLabelSelector(labels, selector)
used by the SlowPath) before returning iri.ListVolumesResponse, or alternatively
return a clear unsupported feature error if you prefer not to filter in-memory.
- Around line 36-47: The error branch after imageStore.Get() is checking the
wrong sentinel (errors.Is(err, utils.ErrVolumeNotFound)) so the nested
rados.ErrNotFound check is unreachable; change the check to errors.Is(err,
store.ErrNotFound) (the store package's ErrNotFound from
github.com/ironcore-dev/provider-utils/storeutils/store) so the volume-not-found
path is detected correctly, preserve the inner errors.Is(err, rados.ErrNotFound)
logic and update imports to include the store package if needed.
---
Nitpick comments:
In `@internal/omap/omap.go`:
- Around line 510-518: The loop in ListByLabels using intersection currently
returns on any s.Get error causing the whole list to fail; instead replicate the
resilient behavior used in listAndConvert (volume_list.go): call s.Get(ctx, id)
for each id, if it returns a NotFound-style error (e.g.,
apierrors.IsNotFound/Is(err, fs.ErrNotExist) depending on your project error
type) then log a warning via s.log (including the id) and continue to the next
id, only append obj to objs when Get succeeds; for any non-NotFound error still
return the error. This keeps stale index entries from failing ListByLabels while
preserving real error handling.
In `@internal/volumeserver/volume_list.go`:
- Around line 108-111: The use of goto to jump to SlowPath should be removed by
restructuring the flow: either invert the condition so when imageStore supports
ListByLabels you run the fast path and otherwise call a clearly named helper
(e.g., handleSlowPath or listImagesSlowly) that contains the SlowPath logic, or
extract the entire slow-path block into a helper and call it instead of using
goto; update references to imageStore and its ListByLabels check (the current if
!ok { ... goto SlowPath }) to call the helper or return/continue appropriately
so no goto/label is needed.
- Around line 28-33: The type-assertion check in getIriVolume that does "_, ok
:= s.imageStore.(imageListerWithLabels[*api.Image])" is dead — its bool is never
used and the function behavior doesn't change — so remove that assertion and the
surrounding log; ensure getIriVolume no longer references imageListerWithLabels
or logs the fallback, leaving the subsequent Get logic intact; if ListByLabels
capability must be checked elsewhere, keep or move the check to ListVolumes
where it's actually used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3baea669-daa8-482b-91a1-ca766029836f
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (6)
Makefilecmd/volumeprovider/app/app.gogo.modinternal/omap/omap.gointernal/volumeserver/volume_create.gointernal/volumeserver/volume_list.go
9328d67 to
ea26aca
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/volumeserver/volume_create.go`:
- Around line 127-131: The Image metadata construction currently dereferences
volume.Metadata.Labels and can panic if volume.Metadata is nil; modify the code
that builds api.Image (the api.Image and apiutils.Metadata creation) to safely
read labels—check if volume.Metadata != nil before accessing Labels and assign
either volume.Metadata.Labels or nil/empty map accordingly (similar to the guard
used in getArchitectureFromVolume) so the image creation no longer risks a nil
pointer dereference.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 892b8c6b-06ff-429d-b77a-9f9fa5494517
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (6)
Makefilecmd/volumeprovider/app/app.gogo.modinternal/omap/omap.gointernal/volumeserver/volume_create.gointernal/volumeserver/volume_list.go
✅ Files skipped from review due to trivial changes (2)
- go.mod
- internal/omap/omap.go
🚧 Files skipped from review as they are similar to previous changes (2)
- cmd/volumeprovider/app/app.go
- Makefile
gonzolino
left a comment
There was a problem hiding this comment.
There are some changes in this PR which I believe are not directly related to the label filtering.
Let's discuss if we can separate those changes from this PR.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
internal/volumeserver/volume_list.go (2)
89-119:⚠️ Potential issue | 🟠 MajorDo not return unfiltered volumes when
ListByLabelsis unavailable.The fallback path still lists all managed volumes for a request with
filter.LabelSelector, which silently returns more volumes than requested.🐛 Proposed fix: filter in memory on fallback
- log.Error(fmt.Errorf("imageStore does not support ListByLabels"), "Cannot use label index optimization") + log.V(1).Info("Image store does not support ListByLabels; falling back to in-memory label filtering") } // Slow path: No specific filter or fallback log.V(1).Info("Listing all volumes (no specific filter or fallback)") volumes, err := s.listVolumes(ctx, log) // Lists *all* managed volumes if err != nil { // listVolumes already logs the store error return nil, utils.ConvertInternalErrorToGRPC(err) } + if filter != nil && len(filter.LabelSelector) > 0 { + filtered := make([]*iri.Volume, 0, len(volumes)) + for _, volume := range volumes { + if volumeMatchesLabelSelector(volume, filter.LabelSelector) { + filtered = append(filtered, volume) + } + } + volumes = filtered + } + return &iri.ListVolumesResponse{Volumes: volumes}, nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/volumeserver/volume_list.go` around lines 89 - 119, The code currently falls back to s.listVolumes and returns all volumes when filter.LabelSelector is set but s.imageStore doesn't implement imageListerWithLabels; instead, when ListByLabels is unavailable you must still honor filter.LabelSelector by fetching the full set via s.listVolumes and then apply an in-memory label filter before returning. Change the fallback in volume_list.go (references: s.imageStore, imageListerWithLabels[*api.Image], ListByLabels, s.listAndConvert, s.listVolumes, iri.ListVolumesResponse, filter.LabelSelector) so that after calling s.listVolumes you filter each volume's labels against filter.LabelSelector, convert only matching images via s.listAndConvert (or convert then filter consistently), and return the filtered slice; preserve existing logging and error handling and do not return the unfiltered full list.
28-33:⚠️ Potential issue | 🔴 CriticalReturn on every
imageStore.Geterror and checkstore.ErrNotFound.
imageStore.Get()wraps missing OMAP entries withstore.ErrNotFound, notutils.ErrVolumeNotFound; non-matching errors currently fall through and may pass a nilcephImageintoapi.IsObjectManagedBy.🐛 Proposed fix
cephImage, err := s.imageStore.Get(ctx, imageId) if err != nil { - if errors.Is(err, utils.ErrVolumeNotFound) { - return nil, fmt.Errorf("failed to get image %s: %w", imageId, utils.ErrVolumeNotFound) - } + if errors.Is(err, store.ErrNotFound) { + log.V(1).Info("Volume not found in store", "volumeID", imageId) + return nil, status.Errorf(codes.NotFound, "volume %s not found", imageId) + } + return nil, fmt.Errorf("failed to get image %s: %w", imageId, err) }Verify the store sentinel with:
#!/bin/bash # Description: Confirm which not-found sentinel the image store returns. rg -n 'store\.ErrNotFound|ErrVolumeNotFound' internal --type=go -B 4 -A 4 rg -n 'func \(s \*Server\) getIriVolume' internal/volumeserver/volume_list.go -A 20🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/volumeserver/volume_list.go` around lines 28 - 33, The code calling s.imageStore.Get currently only handles utils.ErrVolumeNotFound and lets other errors fall through; change it to immediately return on any err from s.imageStore.Get and specifically detect the store sentinel (store.ErrNotFound) instead of utils.ErrVolumeNotFound: when err != nil, if errors.Is(err, store.ErrNotFound) return a wrapped not-found error, otherwise return the error as-is. Update the branch around s.imageStore.Get/cephImage and ensure subsequent calls (e.g., api.IsObjectManagedBy) never receive a nil cephImage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/volumeserver/volume_list.go`:
- Around line 73-86: When using the fast path in ListVolumes (when filter.Id !=
""), ensure the filter.LabelSelector is applied: after calling
s.getIriVolume(ctx, log, filter.Id) and before returning the single volume, call
a helper like volumeMatchesLabelSelector(volume, filter.LabelSelector) and if it
returns false, return an empty iri.ListVolumesResponse instead of the volume;
add the suggested volumeMatchesLabelSelector helper (near listAndConvert) which
returns true when selector is empty, guards against nil metadata/labels, and
checks each selector key/value match.
---
Duplicate comments:
In `@internal/volumeserver/volume_list.go`:
- Around line 89-119: The code currently falls back to s.listVolumes and returns
all volumes when filter.LabelSelector is set but s.imageStore doesn't implement
imageListerWithLabels; instead, when ListByLabels is unavailable you must still
honor filter.LabelSelector by fetching the full set via s.listVolumes and then
apply an in-memory label filter before returning. Change the fallback in
volume_list.go (references: s.imageStore, imageListerWithLabels[*api.Image],
ListByLabels, s.listAndConvert, s.listVolumes, iri.ListVolumesResponse,
filter.LabelSelector) so that after calling s.listVolumes you filter each
volume's labels against filter.LabelSelector, convert only matching images via
s.listAndConvert (or convert then filter consistently), and return the filtered
slice; preserve existing logging and error handling and do not return the
unfiltered full list.
- Around line 28-33: The code calling s.imageStore.Get currently only handles
utils.ErrVolumeNotFound and lets other errors fall through; change it to
immediately return on any err from s.imageStore.Get and specifically detect the
store sentinel (store.ErrNotFound) instead of utils.ErrVolumeNotFound: when err
!= nil, if errors.Is(err, store.ErrNotFound) return a wrapped not-found error,
otherwise return the error as-is. Update the branch around
s.imageStore.Get/cephImage and ensure subsequent calls (e.g.,
api.IsObjectManagedBy) never receive a nil cephImage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 364db425-7a71-4f8b-8ff1-ca662a5c86ac
📒 Files selected for processing (2)
internal/omap/omap.gointernal/volumeserver/volume_list.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/omap/omap.go
2eb6ca8 to
29196f2
Compare
29196f2 to
e8bb8f7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/omap/omap.go (1)
240-242:⚠️ Potential issue | 🟠 MajorLabel index leaks when an object without finalizers is deleted.
On this fast path (no finalizers),
s.deleteremoves the object from OMAP butremoveFromLabelIndexis never called, so the object's labels remain inlabelIndexpointing at a now-deleted ID.Consequences:
labelIndexgrows unbounded over the lifetime of the process for every finalizer-less delete.ListByLabelswill then Get these stale IDs and rely onstore.ErrNotFoundskipping (line 494) to hide them, which is wasted work on every query and masks the underlying leak.The finalizer path at line 256 already calls
removeFromLabelIndex; the same needs to happen here.🛠️ Proposed fix
if len(obj.GetFinalizers()) == 0 { - return s.delete(ioCtx, id) + if err := s.delete(ioCtx, id); err != nil { + return err + } + s.removeFromLabelIndex(id, obj.GetLabels()) + return nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 240 - 242, The fast-path deleting branch skips cleaning up labelIndex and leaks entries; update the branch that checks obj.GetFinalizers() == 0 to call removeFromLabelIndex with the same context/ID used elsewhere (matching the call in the finalizer path) and handle any error before returning from s.delete(ioCtx, id); in short, invoke removeFromLabelIndex(ioCtx, id) (propagate or wrap errors consistently) in that no-finalizers branch so labels are removed from labelIndex just like in the finalizer flow (references: s.delete, removeFromLabelIndex, obj.GetFinalizers, labelIndex, ListByLabels).
🧹 Nitpick comments (3)
internal/omap/omap.go (2)
490-501: Per-IDs.Getopens a freshIOContextfor every match — consider batching.Each iteration calls
s.Get(ctx, id), which opens a newrados.IOContext(line 276) just to read one key. For selectors that match many objects this becomes O(N) IOContext open/close plus O(N)GetAllOmapValuesround-trips.Consider opening a single
IOContextonce inListByLabelsand either calling the lower-levels.get(ioCtx, id)in the loop, or fetching all needed keys with a boundedGetAllOmapValuesscan and filtering byintersection. This is a pure performance refactor; correctness-wise the current code is fine.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 490 - 501, ListByLabels currently calls s.Get(ctx, id) inside a loop which opens a new rados.IOContext per call (expensive); refactor to open a single IOContext once and use the internal lower-level accessor to avoid repeated open/close: obtain ioCtx once at the start of ListByLabels, then inside the loop call s.get(ioCtx, id) (or perform a bounded GetAllOmapValues scan and filter by the existing intersection) so that IOContext creation and GetAllOmapValues round-trips are batched rather than executed per id.
464-483: Minor: simplify first-iteration detection.The
isFirstLabelflag can be replaced with the loop index, which keeps the intent obvious and removes the mutable state outside the loop.♻️ Proposed cleanup
- var isFirstLabel = true - - // 3. Iterate over the sorted slice (labelsForSort) to compute the intersection. - for _, info := range labelSelect { - ids := info.ids - if isFirstLabel { - // Use the smallest set to initialize the intersection (copy to avoid modifying the index set). - intersection = ids.Clone() - isFirstLabel = false - } else { - // Intersect the current result with the next smallest set. - intersection = intersection.Intersection(ids) - } - - if intersection.Len() == 0 { - return []E{}, nil - } - } + // 3. Iterate over the sorted slice to compute the intersection. + for i, info := range labelSelect { + if i == 0 { + intersection = info.ids.Clone() + } else { + intersection = intersection.Intersection(info.ids) + } + if intersection.Len() == 0 { + return []E{}, nil + } + }Note: if the "clone inside lock" fix above is adopted,
info.idsis already a clone and the.Clone()on line 1 of the loop can be dropped.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 464 - 483, Replace the mutable isFirstLabel flag with an index-based check in the loop over labelSelect: change the loop to use for i, info := range labelSelect and treat i == 0 as the first iteration to initialize intersection (intersection = info.ids.Clone()) and otherwise call intersection = intersection.Intersection(info.ids); remove the isFirstLabel variable declaration and its assignments; if you have already ensured info.ids is a clone elsewhere, you can additionally drop the .Clone() call on the initialization.internal/volumeserver/volume_list.go (1)
67-71: Redundant shadowing offilter.Line 67 binds
filter := req.Filter, and line 71 immediately re-binds the same expression in theifinit statement (if filter := req.Filter; ...). Either drop the outer declaration and keep theif-scoped binding, or reuse the outerfilterso readers don't have to track two variables with identical values.♻️ Proposed cleanup
- filter := req.Filter - log.V(2).Info("Listing volumes") - - // Fast path for ID filter - if filter := req.Filter; filter != nil && filter.Id != "" { + filter := req.Filter + log.V(2).Info("Listing volumes") + + // Fast path for ID filter + if filter != nil && filter.Id != "" {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/volumeserver/volume_list.go` around lines 67 - 71, The code redundantly shadows the variable filter (outer "filter := req.Filter" and inner "if filter := req.Filter; ..."); remove the outer declaration and use the if-scoped binding, or keep the outer and change the if to "if filter != nil && filter.Id != \"\" {", so only one filter variable is used consistently—update the occurrences in the function that reference filter (the outer binding or the if-check) accordingly (look for the variable named "filter" and the "if filter := req.Filter" init in this function).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/omap/omap.go`:
- Around line 440-488: In ListByLabels, you must avoid leaking the read lock and
prevent races on labelIndex entries: after s.labelIndexMu.RLock() acquire the
lock use defer s.labelIndexMu.RUnlock() (or ensure every early return unlocks)
and while still holding the lock clone each referenced set (the ids stored into
sizedLabel) instead of storing direct references to s.labelIndex[label]; then
release the lock and perform ids.Clone()/intersection.Intersection(ids) on those
cloned sets so updateLabelIndex/removeFromLabelIndex cannot mutate the
underlying maps concurrently.
---
Outside diff comments:
In `@internal/omap/omap.go`:
- Around line 240-242: The fast-path deleting branch skips cleaning up
labelIndex and leaks entries; update the branch that checks obj.GetFinalizers()
== 0 to call removeFromLabelIndex with the same context/ID used elsewhere
(matching the call in the finalizer path) and handle any error before returning
from s.delete(ioCtx, id); in short, invoke removeFromLabelIndex(ioCtx, id)
(propagate or wrap errors consistently) in that no-finalizers branch so labels
are removed from labelIndex just like in the finalizer flow (references:
s.delete, removeFromLabelIndex, obj.GetFinalizers, labelIndex, ListByLabels).
---
Nitpick comments:
In `@internal/omap/omap.go`:
- Around line 490-501: ListByLabels currently calls s.Get(ctx, id) inside a loop
which opens a new rados.IOContext per call (expensive); refactor to open a
single IOContext once and use the internal lower-level accessor to avoid
repeated open/close: obtain ioCtx once at the start of ListByLabels, then inside
the loop call s.get(ioCtx, id) (or perform a bounded GetAllOmapValues scan and
filter by the existing intersection) so that IOContext creation and
GetAllOmapValues round-trips are batched rather than executed per id.
- Around line 464-483: Replace the mutable isFirstLabel flag with an index-based
check in the loop over labelSelect: change the loop to use for i, info := range
labelSelect and treat i == 0 as the first iteration to initialize intersection
(intersection = info.ids.Clone()) and otherwise call intersection =
intersection.Intersection(info.ids); remove the isFirstLabel variable
declaration and its assignments; if you have already ensured info.ids is a clone
elsewhere, you can additionally drop the .Clone() call on the initialization.
In `@internal/volumeserver/volume_list.go`:
- Around line 67-71: The code redundantly shadows the variable filter (outer
"filter := req.Filter" and inner "if filter := req.Filter; ..."); remove the
outer declaration and use the if-scoped binding, or keep the outer and change
the if to "if filter != nil && filter.Id != \"\" {", so only one filter variable
is used consistently—update the occurrences in the function that reference
filter (the outer binding or the if-check) accordingly (look for the variable
named "filter" and the "if filter := req.Filter" init in this function).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 81ae43dd-4fee-4ccc-b244-22a05a3717b6
📒 Files selected for processing (3)
internal/omap/omap.gointernal/volumeserver/volume_create.gointernal/volumeserver/volume_list.go
✅ Files skipped from review due to trivial changes (1)
- internal/volumeserver/volume_create.go
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/omap/omap.go (1)
240-242:⚠️ Potential issue | 🔴 CriticalLabel index leak on the hard-delete path in
Delete.When
objhas no finalizers,s.delete(ioCtx, id)removes the OMAP entry but the object's labels are never removed fromlabelIndex. The soft-delete branch below (line 256) correctly callsremoveFromLabelIndex; this path does not. Consequences:
labelIndexgrows unboundedly, retainingobjIDreferences for deleted objects.- Subsequent
ListByLabelscalls perform wastedGetlookups for stale IDs (currently tolerated via thestore.ErrNotFoundskip at line 495, but still a CPU/IOContext cost).- If any object is later created with a reused ID that happens to match a stale label, it could briefly match before the index is rewritten.
🛠 Proposed fix
if len(obj.GetFinalizers()) == 0 { - return s.delete(ioCtx, id) + if err := s.delete(ioCtx, id); err != nil { + return err + } + s.removeFromLabelIndex(id, obj.GetLabels()) + return nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 240 - 242, The hard-delete path in Delete is leaking label index entries because when len(obj.GetFinalizers()) == 0 the code calls s.delete(ioCtx, id) but never removes the object's labels from labelIndex; update the Delete implementation so that before (or immediately after) calling s.delete(ioCtx, id) you call s.removeFromLabelIndex(ioCtx, id, obj) (or the appropriate overload) to remove all labelIndex entries for this objID; ensure you reference the existing functions/fields: Delete, s.delete, removeFromLabelIndex, labelIndex and use the same ioCtx and id variables passed into Delete to avoid duplicating lookups.
♻️ Duplicate comments (1)
internal/omap/omap.go (1)
449-484:⚠️ Potential issue | 🔴 CriticalData race on indexed sets after
RUnlockis still present.The earlier lock-leak (early return with
RLockheld) has been fixed, but the companion issue flagged previously is not:labelSelect[i].idsstores a direct reference tos.labelIndex[label]. Afters.labelIndexMu.RUnlock()on line 464, those referenced sets are still accessed at line 479 (ids.Clone()) and line 483 (intersection.Intersection(ids)). ConcurrentupdateLabelIndex/removeFromLabelIndexwriters may mutate those maps at the same time — sincesets.Set[string]is a map under the hood, this is an unsynchronized concurrent map read/write that-racewill flag and that can panic or corrupt results under real workloads.Clone each referenced set while the read lock is still held, so nothing outside the critical section touches the shared index.
🔒 Proposed fix
s.labelIndexMu.RLock() // 1 .Gather label set sizes and check for immediate non-matches. for key, value := range labelSelector { label := formatLabel(key, value) ids, found := s.labelIndex[label] if !found { s.labelIndexMu.RUnlock() return []E{}, nil } labelSelect = append(labelSelect, sizedLabel{ - ids: ids, + ids: ids.Clone(), size: ids.Len(), }) } s.labelIndexMu.RUnlock()With cloned sets, the later
ids.Clone()on line 479 can also be dropped (assignintersection = idsdirectly).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 449 - 484, The code currently stores direct references to s.labelIndex[label] into labelSelect while only holding labelIndexMu.RLock(), then unlocks and later reads those sets (ids.Clone()/intersection.Intersection(ids)) which is a data race; fix by cloning each referenced set while still under the read lock (replace storing ids with ids.Clone() when building sizedLabel inside the RLock block) so the sets in labelSelect are independent copies, and then after RUnlock use those clones directly (you can drop the redundant ids.Clone() at the first-intersection step and assign intersection = ids) ; keep references to formatLabel, labelIndexMu, labelIndex, sizedLabel, labelSelect, ids, and updateLabelIndex/removeFromLabelIndex in mind to ensure writers mutate only the original index.
🧹 Nitpick comments (1)
internal/omap/omap.go (1)
491-502: Opening a new IOContext per matched ID is wasteful.Each
s.Get(ctx, id)call opens and destroys its ownrados.IOContext. For a selector matching many objects this results in N context open/close cycles on the hot listing path — exactly the path this PR is meant to make cheaper. Consider opening oneIOContextup front and using an internal helper (analogous to the existings.get(ioCtx, id)) for each lookup. If the underlying Ceph API supports multi-key OMAP reads (omap_get_vals_by_keysor similar), a single batched fetch would be even better.♻️ Sketch
- objs := make([]E, 0, intersection.Len()) - for id := range intersection { - obj, err := s.Get(ctx, id) - if err != nil { - if errors.Is(err, store.ErrNotFound) { - // Object was deleted after index lookup; skip stale entry - continue - } - return nil, err - } - objs = append(objs, obj) - } + ioCtx, err := s.conn.OpenIOContext(s.pool) + if err != nil { + return nil, fmt.Errorf("unable to get io context: %w", err) + } + defer ioCtx.Destroy() + + objs := make([]E, 0, intersection.Len()) + for id := range intersection { + obj, err := s.get(ioCtx, id) + if err != nil { + if errors.Is(err, store.ErrNotFound) { + // Object was deleted after index lookup; skip stale entry + continue + } + return nil, err + } + objs = append(objs, obj) + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/omap/omap.go` around lines 491 - 502, The loop currently calls s.Get(ctx, id) for each id which opens/closes an rados.IOContext per call; refactor to acquire a single IOContext once before the loop and call the internal helper that accepts an IOContext (e.g., use the existing s.get(ioCtx, id) pattern) to fetch each object, releasing the IOContext after the loop; additionally, if the Ceph API supports multi-key OMAP reads, replace the per-id fetches with a batched omap_get_vals_by_keys call to retrieve all matched ids in one request.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/omap/omap.go`:
- Around line 85-87: formatLabel currently concatenates key and value with "="
which is ambiguous if either contains "="; update formatLabel to use a separator
that cannot appear in arbitrary label strings (e.g., use the NUL character
"\x00") or apply a tuple-safe encoding (e.g., base64 or URL-encoding) to key and
value before joining so serialized labels are unambiguous; change the
implementation of formatLabel to use the chosen safe separator/encoding and
update any lookups or consumers that expect the current "="-joined form
accordingly.
---
Outside diff comments:
In `@internal/omap/omap.go`:
- Around line 240-242: The hard-delete path in Delete is leaking label index
entries because when len(obj.GetFinalizers()) == 0 the code calls
s.delete(ioCtx, id) but never removes the object's labels from labelIndex;
update the Delete implementation so that before (or immediately after) calling
s.delete(ioCtx, id) you call s.removeFromLabelIndex(ioCtx, id, obj) (or the
appropriate overload) to remove all labelIndex entries for this objID; ensure
you reference the existing functions/fields: Delete, s.delete,
removeFromLabelIndex, labelIndex and use the same ioCtx and id variables passed
into Delete to avoid duplicating lookups.
---
Duplicate comments:
In `@internal/omap/omap.go`:
- Around line 449-484: The code currently stores direct references to
s.labelIndex[label] into labelSelect while only holding labelIndexMu.RLock(),
then unlocks and later reads those sets
(ids.Clone()/intersection.Intersection(ids)) which is a data race; fix by
cloning each referenced set while still under the read lock (replace storing ids
with ids.Clone() when building sizedLabel inside the RLock block) so the sets in
labelSelect are independent copies, and then after RUnlock use those clones
directly (you can drop the redundant ids.Clone() at the first-intersection step
and assign intersection = ids) ; keep references to formatLabel, labelIndexMu,
labelIndex, sizedLabel, labelSelect, ids, and
updateLabelIndex/removeFromLabelIndex in mind to ensure writers mutate only the
original index.
---
Nitpick comments:
In `@internal/omap/omap.go`:
- Around line 491-502: The loop currently calls s.Get(ctx, id) for each id which
opens/closes an rados.IOContext per call; refactor to acquire a single IOContext
once before the loop and call the internal helper that accepts an IOContext
(e.g., use the existing s.get(ioCtx, id) pattern) to fetch each object,
releasing the IOContext after the loop; additionally, if the Ceph API supports
multi-key OMAP reads, replace the per-id fetches with a batched
omap_get_vals_by_keys call to retrieve all matched ids in one request.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 24f679f9-af76-4367-ac40-c87565098806
📒 Files selected for processing (1)
internal/omap/omap.go
cf88820 to
c0dad2e
Compare
| ) | ||
|
|
||
| // imageListerWithLabels type parameter E is constrained to be a providerapi.Object. | ||
| type imageListerWithLabels[E providerapi.Object] interface { |
There was a problem hiding this comment.
I wonder if it would be better to extend the List(ctx) function in the store.Store interface at https://github.com/ironcore-dev/provider-utils/blob/main/storeutils/store/store.go#L50 to support some kind of filter parameter.
I think this would significantly reduce the amount of code needed for this change, and it might be useful to other store implementations / use-cases.
Let's discuss this on the next Community Call.
There was a problem hiding this comment.
I agree, it makes sense to extend the List functionality in the provider-utils package.
There was a problem hiding this comment.
I have a PR ready to extend List in provider-utils: ironcore-dev/provider-utils#56
There was a problem hiding this comment.
Updated PR to support List with labels and field indexes using modified provider-utils List()
c0dad2e to
80c388e
Compare
7d6810a to
7cde086
Compare
gonzolino
left a comment
There was a problem hiding this comment.
Still reviewing, but here are some comments already.
| return formatIndexKey(key, value) | ||
| } | ||
|
|
||
| // updateLabelIndex updates the index for a single object based on its labels. |
There was a problem hiding this comment.
Comment does not match the function name
| return fmt.Errorf("failed to get all omap values for %s index initialization: %w", indexName, err) | ||
| } | ||
|
|
||
| for key := range index { |
There was a problem hiding this comment.
During initialization, shouldn't the index always be empty? I don't think we need to "clean it up" here.
| } | ||
|
|
||
| // --- Internal Index Helpers --- | ||
| func formatIndexKey(key, value string) string { |
There was a problem hiding this comment.
How will index keys in this format work with HasLabel queries? Such queries use an Exists operator on the key, without caring for the value. This index key format expects all index keys to consist of a key + value combination.
| defer ioCtx.Destroy() | ||
|
|
||
| omapValues, err := ioCtx.GetAllOmapValues(s.omapName, "", "", s.iteratorSize) | ||
| if err != nil && !errors.Is(err, rados.ErrNotFound) { |
There was a problem hiding this comment.
| if err != nil && !errors.Is(err, rados.ErrNotFound) { | |
| if err != nil { |
82cb3ec to
73201cc
Compare
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
Signed-off-by: kajol.asabe@t-systems.com <kajol.asabe@t-systems.com>
73201cc to
ea85f54
Compare
Proposed Changes
IRIVolumelabels toImageduring volume creationListByLabelsfunction to listomapstore images using label selectorfilterVolumesfunction to enhance volume list processingFixes #851
Summary by CodeRabbit
New Features
Bug Fixes