sync ids on add
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m45s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m45s
This commit is contained in:
@@ -166,6 +166,8 @@ const (
|
|||||||
//AckError = uint16(6)
|
//AckError = uint16(6)
|
||||||
Ping = uint16(7)
|
Ping = uint16(7)
|
||||||
Pong = uint16(8)
|
Pong = uint16(8)
|
||||||
|
GetCartIds = uint16(9)
|
||||||
|
CartIdsResponse = uint16(10)
|
||||||
)
|
)
|
||||||
|
|
||||||
type PacketWithData struct {
|
type PacketWithData struct {
|
||||||
@@ -317,6 +319,15 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case GetCartIds:
|
||||||
|
ids := make([]string, 0, len(p.local.grains))
|
||||||
|
for id := range p.local.grains {
|
||||||
|
ids = append(ids, id.String())
|
||||||
|
}
|
||||||
|
SendPacket(conn, CartIdsResponse, func(w io.Writer) error {
|
||||||
|
_, err := w.Write([]byte(strings.Join(ids, ";")))
|
||||||
|
return err
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,6 +349,27 @@ func (h *RemoteHost) Negotiate(knownHosts []string) ([]string, error) {
|
|||||||
return strings.Split(string(packet.Data), ";"), nil
|
return strings.Split(string(packet.Data), ";"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *RemoteHost) GetCartMappings() []CartId {
|
||||||
|
err := SendPacket(g.connection, GetCartIds, func(w io.Writer) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting mappings: %v\n", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
packet, err := g.queue.Expect(CartIdsResponse, time.Second*3)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting mappings: %v\n", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
parts := strings.Split(string(packet.Data), ";")
|
||||||
|
ids := make([]CartId, 0, len(parts))
|
||||||
|
for _, p := range parts {
|
||||||
|
ids = append(ids, ToCartId(p))
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) Negotiate(knownHosts []string) ([]string, error) {
|
func (p *SyncedPool) Negotiate(knownHosts []string) ([]string, error) {
|
||||||
allHosts := make(map[string]struct{}, 0)
|
allHosts := make(map[string]struct{}, 0)
|
||||||
for _, r := range p.remotes {
|
for _, r := range p.remotes {
|
||||||
@@ -425,7 +457,14 @@ func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
|
|||||||
p.remotes = append(p.remotes, remote)
|
p.remotes = append(p.remotes, remote)
|
||||||
connectedRemotes.Set(float64(len(p.remotes)))
|
connectedRemotes.Set(float64(len(p.remotes)))
|
||||||
log.Printf("Added remote %s\n", remote.Host)
|
log.Printf("Added remote %s\n", remote.Host)
|
||||||
|
go func() {
|
||||||
|
ids := remote.GetCartMappings()
|
||||||
|
p.mu.Lock()
|
||||||
|
for _, id := range ids {
|
||||||
|
p.remoteIndex[id] = remote.Pool
|
||||||
|
}
|
||||||
|
p.mu.Unlock()
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user