- Client SDK will connect to a node, get node information and decide if it needs to connect to a primary for writes, or pick a replica to connect to for reads - Updated service with a GetNodeInfo rpc call which returns information about the node to enable the smart selection code in the sdks
36 lines
853 B
Go
36 lines
853 B
Go
package replication
|
|
|
|
// GetReplicaInfo returns information about all connected replicas
|
|
func (p *Primary) GetReplicaInfo() []ReplicationNodeInfo {
|
|
p.mu.RLock()
|
|
defer p.mu.RUnlock()
|
|
|
|
var replicas []ReplicationNodeInfo
|
|
|
|
// Convert replica sessions to ReplicationNodeInfo
|
|
for _, session := range p.sessions {
|
|
if !session.Connected {
|
|
continue
|
|
}
|
|
|
|
replica := ReplicationNodeInfo{
|
|
Address: session.ID, // We don't have actual address, so use ID
|
|
LastSequence: session.LastAckSequence,
|
|
Available: session.Active,
|
|
Region: "",
|
|
Meta: map[string]string{},
|
|
}
|
|
|
|
replicas = append(replicas, replica)
|
|
}
|
|
|
|
return replicas
|
|
}
|
|
|
|
// GetLastSequence returns the highest sequence number that has been synced to disk
|
|
func (p *Primary) GetLastSequence() uint64 {
|
|
p.mu.RLock()
|
|
defer p.mu.RUnlock()
|
|
return p.lastSyncedSeq
|
|
}
|