Skip to content

Raft lock held while saving root CA #2241

@aaronlehmann

Description

@aaronlehmann

I noticed this code:

        updates, cancel, err := store.ViewAndWatch(
                s.store,
                func(readTx store.ReadTx) error {
                        clusters, err := store.FindClusters(readTx, store.ByName(store.DefaultClusterName))
                        if err != nil {
                                return err
                        }
                        if len(clusters) != 1 {
                                return errors.New("could not find cluster object")
                        }
                        s.UpdateRootCA(ctx, clusters[0]) // call once to ensure that the join tokens are always set
                        nodes, err = store.FindNodes(readTx, store.All)
                        return err
                },
                api.EventCreateNode{},
                api.EventUpdateNode{},
                api.EventDeleteNode{},
        )

s.UpdateRootCA does some file I/O when it saves the root CA cert. It also acquires another lock.

ViewAndWatch holds the raft lock to give a strong consistency guarantee that the caller won't receive events whose effects were already visible in the View portion, but I'm not sure this code needs this guarantee.

cc @cyli

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions