Skip to content

Passive Update mode supported #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tools/dpvs-agent/cmd/ipvs/post_vs_vip_port_rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package ipvs

import (
"sort"
"strings"

"github.com/dpvs-agent/models"
Expand Down Expand Up @@ -73,11 +74,57 @@ func (h *postVsRs) Handle(params apiVs.PostVsVipPortRsParams) middleware.Respond
rss[i].SetInhibited(&inhibited)
}

update := !*params.PassiveUpdate

shareSnapshot := settings.ShareSnapshot()
if shareSnapshot.ServiceLock(params.VipPort) {
defer shareSnapshot.ServiceUnlock(params.VipPort)
}

// default passiveUpdate == false
if *params.PassiveUpdate {
// passiveUpdate == true
vsModel := shareSnapshot.ServiceGet(params.VipPort)
if vsModel == nil {
h.logger.Info("Try update update. vs not found in snapshot.", "VipPort", params.VipPort)
update = true
}

if vsModel != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the contrary side of previous if condition. if...else... is more efficient.

if len(vsModel.RSs.Items) != len(rss) {
h.logger.Info("Try update update. vs rss len has changed.", "VipPort", params.VipPort)
update = true
Comment on lines +89 to +96
Copy link
Preview

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message contains a duplicated word 'update update'. Consider revising it to a clearer message such as 'Attempt update: vs not found in snapshot.'

Suggested change
h.logger.Info("Try update update. vs not found in snapshot.", "VipPort", params.VipPort)
update = true
}
if vsModel != nil {
if len(vsModel.RSs.Items) != len(rss) {
h.logger.Info("Try update update. vs rss len has changed.", "VipPort", params.VipPort)
update = true
h.logger.Info("Attempt update: vs not found in snapshot.", "VipPort", params.VipPort)
update = true
}
if vsModel != nil {
if len(vsModel.RSs.Items) != len(rss) {
h.logger.Info("Attempt update: vs rss len has changed.", "VipPort", params.VipPort)

Copilot uses AI. Check for mistakes.

Comment on lines +95 to +96
Copy link
Preview

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message uses the duplicated phrase 'update update'. Consider revising it to 'Attempt update: vs RS list length has changed.' for clarity.

Suggested change
h.logger.Info("Try update update. vs rss len has changed.", "VipPort", params.VipPort)
update = true
h.logger.Info("Attempt update: vs RS list length has changed.", "VipPort", params.VipPort)

Copilot uses AI. Check for mistakes.

}

if len(vsModel.RSs.Items) == len(rss) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the contrary side of previous if condition. if...else... is more efficient.

cacheRSs := (types.SliceRealServerSpecExpandModel)(vsModel.RSs.Items)
sort.Sort(cacheRSs)

newRSs := (types.SliceRealServerSpec)(rss)
sort.Sort(newRSs)

for i, newRs := range newRSs {
cacheRs := cacheRSs[i]
if int(cacheRs.Spec.Weight) != int(newRs.GetWeight()) {
h.logger.Info("Try update update. rs weight has changed.", "VipPort", params.VipPort, "rs", newRs.ID(), "cache weight", cacheRs.Spec.Weight, "update weight", newRs.GetWeight())
update = true
break
}

if !strings.EqualFold(strings.ToUpper(cacheRs.Spec.Mode), strings.ToUpper(newRs.GetFwdModeString())) {
h.logger.Info("Try update update. rs nat mode has changed.", "VipPort", params.VipPort, "rs", newRs.ID(), "cache nat mode", cacheRs.Spec.Mode, "update nat mode", newRs.GetFwdModeString())
update = true
break
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it need to consider any other field changes in RS?

}
}
}
}

if !update {
return apiVs.NewPostVsVipPortRsOK().WithPayload("PassiveUpdate")
}

result := front.Update(rss, h.connPool, h.logger)
switch result {
case types.EDPVS_EXIST, types.EDPVS_OK:
Expand Down
47 changes: 47 additions & 0 deletions tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,54 @@ func (h *putVsItem) Handle(params apiVs.PutVsVipPortParams) middleware.Responder
}
}

update := !*params.PassiveUpdate

shareSnapshot := settings.ShareSnapshot()
if shareSnapshot.ServiceRLock(vs.ID()) {
vsModel := shareSnapshot.ServiceGet(vs.ID())
if vsModel == nil {
shareSnapshot.ServiceRUnlock(vs.ID())
return apiVs.NewPutVsVipPortInvalidBackend()
}

if *params.PassiveUpdate {
// bypass VIP, Port, Protocol, Af, netmask
if vsModel.Fwmark != vs.GetFwmark() ||
vsModel.ConnTimeout != vs.GetConnTimeout() ||
vsModel.Bps != vs.GetBps() ||
vsModel.LimitProportion != vs.GetLimitProportion() {

h.logger.Info("Try to update !!! Fwmark | ConnTimeout | Bps | LimitProportion has Changed.", "VipPort", params.VipPort)

update = true
}

// ExpireQuiescent | SynProxy | Quic | Persistence
newFlags := vs.GetFlags()
newFlagsNOT := ^newFlags
tmpFlags := vsModel.RAMFlags ^ newFlagsNOT
if (tmpFlags & vsModel.RAMFlags) != newFlags {
Comment on lines +116 to +119
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's purpose of the four line codes? To tell if vsModel.RAMFlags != vs.GetFlags()?


h.logger.Info("Try to update !!! the flags has changed.", "VipPort", params.VipPort)

update = true
}

if !strings.EqualFold(vs.GetSchedName(), vsModel.SchedName) {

h.logger.Info("Try to update !!! the SchedName has changed.", "VipPort", params.VipPort)

update = true
}
}

shareSnapshot.ServiceRUnlock(vs.ID())
}

if !update {
return apiVs.NewPutVsVipPortOK().WithPayload("PassiveUpdate")
}

result := vs.Add(h.connPool, h.logger)
h.logger.Info("Add virtual server done.", "vs", vs, "result", result.String())
switch result {
Expand Down
11 changes: 11 additions & 0 deletions tools/dpvs-agent/dpvs-agent-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ parameters:
- off
default: unset
required: false
passive-update:
name: passiveUpdate
in: query
type: boolean
default: false
required: false
version:
name: version
in: query
Expand Down Expand Up @@ -561,6 +567,9 @@ definitions:
format: "uint32"
Flags:
type: "string"
RamFlags:
type: "integer"
format: "uint32"
SynProxy:
type: "string"
enum:
Expand Down Expand Up @@ -1164,6 +1173,7 @@ paths:
tags:
- "virtualserver"
parameters:
- "$ref": "#/parameters/passive-update"
- "$ref": "#/parameters/snapshot"
- "$ref": "#/parameters/service-id"
- "$ref": "#/parameters/vs-config"
Expand Down Expand Up @@ -1381,6 +1391,7 @@ paths:
tags:
- "virtualserver"
parameters:
- "$ref": "#/parameters/passive-update"
- "$ref": "#/parameters/snapshot"
- "$ref": "#/parameters/service-id"
- "$ref": "#/parameters/rss-config"
Expand Down
3 changes: 3 additions & 0 deletions tools/dpvs-agent/models/virtual_server_spec_expand.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/dpvs-agent/pkg/ipc/types/getmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (vs *VirtualServerSpec) GetModel() *models.VirtualServerSpecExpand {
Match: vs.match.GetModel(),
Stats: vs.stats.GetModel(),
DestCheck: vs.GetDestCheck(),
RAMFlags: vs.GetFlags(),
}

flags := ""
Expand Down
14 changes: 14 additions & 0 deletions tools/dpvs-agent/pkg/ipc/types/realserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ import (
"github.com/dpvs-agent/pkg/ipc/pool"
)

type SliceRealServerSpec []*RealServerSpec

func (rss SliceRealServerSpec) Len() int {
return len(rss)
}

func (rss SliceRealServerSpec) Swap(i, j int) {
rss[i], rss[j] = rss[j], rss[i]
}

func (rss SliceRealServerSpec) Less(i, j int) bool {
return rss[i].ID() < rss[j].ID()
}

type RealServerSpec struct {
af uint32
port uint16
Expand Down
16 changes: 16 additions & 0 deletions tools/dpvs-agent/pkg/ipc/types/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ func (spec *VirtualServerSpecExpandModel) ID() string {
return fmt.Sprintf("%s-%d-%s", net.ParseIP(spec.Addr).String(), spec.Port, proto)
}

type SliceRealServerSpecExpandModel []*models.RealServerSpecExpand

func (rss SliceRealServerSpecExpandModel) Len() int {
return len(rss)
}

func (rss SliceRealServerSpecExpandModel) Swap(i, j int) {
rss[i], rss[j] = rss[j], rss[i]
}

func (rss SliceRealServerSpecExpandModel) Less(i, j int) bool {
rs1 := (*RealServerSpecExpandModel)(rss[i])
rs2 := (*RealServerSpecExpandModel)(rss[j])
return rs1.ID() < rs2.ID()
}

func (node *NodeSnapshot) LoadFrom(cacheFile string, logger hclog.Logger) error {
content, err := os.ReadFile(cacheFile)
if err != nil {
Expand Down
38 changes: 38 additions & 0 deletions tools/dpvs-agent/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading