github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/manager/state/store/doc.go (about) 1 // Package store provides interfaces to work with swarm cluster state. 2 // 3 // The primary interface is MemoryStore, which abstracts storage of this cluster 4 // state. MemoryStore exposes a transactional interface for both reads and writes. 5 // To perform a read transaction, View accepts a callback function that it 6 // will invoke with a ReadTx object that gives it a consistent view of the 7 // state. Similarly, Update accepts a callback function that it will invoke with 8 // a Tx object that allows reads and writes to happen without interference from 9 // other transactions. 10 // 11 // This is an example of making an update to a MemoryStore: 12 // 13 // err := store.Update(func(tx store.Tx) { 14 // if err := tx.Nodes().Update(newNode); err != nil { 15 // return err 16 // } 17 // return nil 18 // }) 19 // if err != nil { 20 // return fmt.Errorf("transaction failed: %v", err) 21 // } 22 // 23 // MemoryStore exposes watch functionality. 24 // It exposes a publish/subscribe queue where code can subscribe to 25 // changes of interest. This can be combined with the ViewAndWatch function to 26 // "fork" a store, by making a snapshot and then applying future changes 27 // to keep the copy in sync. This approach lets consumers of the data 28 // use their own data structures and implement their own concurrency 29 // strategies. It can lead to more efficient code because data consumers 30 // don't necessarily have to lock the main data store if they are 31 // maintaining their own copies of the state. 32 package store