MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / SetNode

Method SetNode

cmd/cqld/adapter.go:69–110  ·  view source on GitHub ↗

SetNode handles dht storage node update.

(node *proto.Node)

Source from the content-addressed store, hash-verified

67
68// SetNode handles dht storage node update.
69func (s *LocalStorage) SetNode(node *proto.Node) (err error) {
70 query := "INSERT OR REPLACE INTO `dht` (`id`, `node`) VALUES (?, ?);"
71 log.Debugf("sql: %#v", query)
72
73 nodeBuf, err := utils.EncodeMsgPack(node)
74 if err != nil {
75 err = errors.Wrap(err, "encode node failed")
76 return
77 }
78
79 err = route.SetNodeAddrCache(node.ID.ToRawNodeID(), node.Addr)
80 if err != nil {
81 log.WithFields(log.Fields{
82 "id": node.ID,
83 "addr": node.Addr,
84 }).WithError(err).Error("set node addr cache failed")
85 }
86 err = kms.SetNode(node)
87 if err != nil {
88 log.WithField("node", node).WithError(err).Error("kms set node failed")
89 }
90
91 // if s.consistent == nil, it is called during Init. and AddCache will be called by consistent.InitConsistent
92 if s.consistent != nil {
93 s.consistent.AddCache(*node)
94 }
95
96 // execute query
97 if _, err = s.Storage.Exec(context.Background(), []storage.Query{
98 {
99 Pattern: query,
100 Args: []sql.NamedArg{
101 sql.Named("", node.ID),
102 sql.Named("", nodeBuf.Bytes()),
103 },
104 },
105 }); err != nil {
106 err = errors.Wrap(err, "execute query in dht database failed")
107 }
108
109 return
110}
111
112// KVServer holds LocalStorage instance and implements consistent persistence interface.
113type KVServer struct {

Callers

nothing calls this directly

Calls 12

DebugfFunction · 0.92
EncodeMsgPackFunction · 0.92
SetNodeAddrCacheFunction · 0.92
WithFieldsFunction · 0.92
SetNodeFunction · 0.92
WithFieldFunction · 0.92
ToRawNodeIDMethod · 0.80
ErrorMethod · 0.80
WithErrorMethod · 0.80
AddCacheMethod · 0.80
ExecMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected