Skip to content

Commit b51b5db

Browse files
committed
introduce repo sync leave
1 parent 90181e9 commit b51b5db

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed

repo/repo_mgmt.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func (r *Repo) onMgmtCmd(_ enc.Name, wire enc.Wire, reply func(enc.Wire) error)
2121
return
2222
}
2323

24+
if cmd.SyncLeave != nil {
25+
go r.handleSyncLeave(cmd.SyncLeave, reply)
26+
return
27+
}
28+
2429
log.Warn(r, "Unknown management command received")
2530
}
2631

@@ -42,6 +47,25 @@ func (r *Repo) handleSyncJoin(cmd *tlv.SyncJoin, reply func(enc.Wire) error) {
4247
reply(res.Encode())
4348
}
4449

50+
// (AI GENERATED DESCRIPTION): Handles a SyncLeave command by stopping an SVS session for the specified group when the protocol is `SyncProtocolSvsV3`; otherwise, responds with an error status.
51+
func (r *Repo) handleSyncLeave(cmd *tlv.SyncLeave, reply func(enc.Wire) error) {
52+
res := tlv.RepoCmdRes{Status: 200}
53+
54+
if cmd.Protocol != nil && cmd.Protocol.Name.Equal(tlv.SyncProtocolSvsV3) {
55+
if err := r.stopSvs(cmd); err != nil {
56+
res.Status = 500
57+
res.Message = err.Error()
58+
log.Error(r, "Failed to stop SVS", "err", err)
59+
}
60+
reply(res.Encode())
61+
return
62+
}
63+
64+
log.Warn(r, "Unknown sync protocol specified in command", "protocol", cmd.Protocol)
65+
res.Status = 400
66+
reply(res.Encode())
67+
}
68+
4569
// (AI GENERATED DESCRIPTION): Starts a SyncJoin session for the specified group, initializing a new RepoSvs if one isn’t already active and storing it in the repository’s group session map.
4670
func (r *Repo) startSvs(cmd *tlv.SyncJoin) error {
4771
if cmd.Group == nil || len(cmd.Group.Name) == 0 {
@@ -66,3 +90,29 @@ func (r *Repo) startSvs(cmd *tlv.SyncJoin) error {
6690

6791
return nil
6892
}
93+
94+
// stopSvs stops an SVS instance for the specified group.
95+
func (r *Repo) stopSvs(cmd *tlv.SyncLeave) error {
96+
if cmd.Group == nil || len(cmd.Group.Name) == 0 {
97+
return fmt.Errorf("missing group name")
98+
}
99+
100+
hash := cmd.Group.Name.TlvStr()
101+
102+
r.mutex.Lock()
103+
svs, ok := r.groupsSvs[hash]
104+
r.mutex.Unlock()
105+
if !ok {
106+
return fmt.Errorf("group not joined")
107+
}
108+
109+
if err := svs.Stop(); err != nil {
110+
return err
111+
}
112+
113+
r.mutex.Lock()
114+
delete(r.groupsSvs, hash)
115+
r.mutex.Unlock()
116+
117+
return nil
118+
}

repo/tlv/definitions.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var SyncProtocolSvsV3 = enc.Name{
1515
type RepoCmd struct {
1616
//+field:struct:SyncJoin
1717
SyncJoin *SyncJoin `tlv:"0x1DB0"`
18+
//+field:struct:SyncLeave
19+
SyncLeave *SyncLeave `tlv:"0x1DB1"`
1820
//+field:struct:BlobFetch
1921
BlobFetch *BlobFetch `tlv:"0x1DB2"`
2022
}
@@ -37,6 +39,13 @@ type SyncJoin struct {
3739
HistorySnapshot *HistorySnapshotConfig `tlv:"0x1A4"`
3840
}
3941

42+
type SyncLeave struct {
43+
//+field:struct:spec.NameContainer
44+
Protocol *spec.NameContainer `tlv:"0x191"`
45+
//+field:struct:spec.NameContainer
46+
Group *spec.NameContainer `tlv:"0x193"`
47+
}
48+
4049
type HistorySnapshotConfig struct {
4150
//+field:natural
4251
Threshold uint64 `tlv:"0x1A5"`

repo/tlv/zz_generated.go

Lines changed: 197 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)