Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introducing Map.Drain API for traversing maps while removing entries #1349

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Sep 5, 2024

  1. introducing Map.Drain API to traverse a map while also deleting entries

    This commit introduces the `Map.Drain` API to traverse the map while also
    removing its entries. It leverages the same `MapIterator` structure, with
    the introduction of a new unexported method to handle the map draining.
    The tests make sure that the behavior is as expected, and that this API
    returns an error while invoked on the wrong map, such as arrays, for which
    `Map.Iterate` should be used instead.
    The `LookupAndDelete` system call support has been introduced in:
    
    1. 5.14 for BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH, BPF_MAP_TYPE_LRU_HASH and BPF_MAP_TYPE_LRU_PERCPU_HASH.
    2. 4.20 for BPF_MAP_TYPE_QUEUE, BPF_MAP_TYPE_STACK
    
    Do not expect the `Map.Drain` API to work on prior versions, according
    to the target map type. From the user perspective, the usage should
    be similar to `Map.Iterate`, as shown as follows:
    
    ```go
    m, err := NewMap(&MapSpec{
    	Type:       Hash,
    	KeySize:    4,
    	ValueSize:  8,
    	MaxEntries: 10,
    })
    // populate here the map and defer close
    it := m.Drain()
    for it.Next(keyPtr, &value) {
        // here the entry doesn't exist anymore in the underlying map.
        ...
    }
    ```
    
    Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
    smagnani96 committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    d6678a8 View commit details
    Browse the repository at this point in the history