Space headsync delayed start
This commit is contained in:
parent
f8c79c33bc
commit
2ab43e2b69
@ -29,6 +29,7 @@ type TreeHeads struct {
|
||||
|
||||
type HeadSync interface {
|
||||
Init(objectIds []string, deletionState settingsstate.ObjectDeletionState)
|
||||
Run()
|
||||
|
||||
UpdateHeads(id string, heads []string)
|
||||
HandleRangeRequest(ctx context.Context, req *spacesyncproto.HeadSyncRequest) (resp *spacesyncproto.HeadSyncResponse, err error)
|
||||
@ -48,6 +49,7 @@ type headSync struct {
|
||||
syncer DiffSyncer
|
||||
configuration nodeconf.NodeConf
|
||||
spaceIsDeleted *atomic.Bool
|
||||
isRunning bool
|
||||
|
||||
syncPeriod int
|
||||
}
|
||||
@ -93,7 +95,11 @@ func NewHeadSync(
|
||||
func (d *headSync) Init(objectIds []string, deletionState settingsstate.ObjectDeletionState) {
|
||||
d.fillDiff(objectIds)
|
||||
d.syncer.Init(deletionState)
|
||||
}
|
||||
|
||||
func (d *headSync) Run() {
|
||||
d.periodicSync.Run()
|
||||
d.isRunning = true
|
||||
}
|
||||
|
||||
func (d *headSync) HandleRangeRequest(ctx context.Context, req *spacesyncproto.HeadSyncRequest) (resp *spacesyncproto.HeadSyncResponse, err error) {
|
||||
@ -135,8 +141,10 @@ func (d *headSync) RemoveObjects(ids []string) {
|
||||
}
|
||||
|
||||
func (d *headSync) Close() (err error) {
|
||||
d.periodicSync.Close()
|
||||
return nil
|
||||
if d.isRunning {
|
||||
d.periodicSync.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *headSync) fillDiff(objectIds []string) {
|
||||
|
||||
@ -51,6 +51,7 @@ func TestDiffService(t *testing.T) {
|
||||
storageMock.EXPECT().WriteSpaceHash(hash)
|
||||
pSyncMock.EXPECT().Run()
|
||||
service.Init([]string{initId}, delState)
|
||||
service.Run()
|
||||
})
|
||||
|
||||
t.Run("update heads", func(t *testing.T) {
|
||||
@ -64,7 +65,9 @@ func TestDiffService(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("close", func(t *testing.T) {
|
||||
pSyncMock.EXPECT().Run()
|
||||
pSyncMock.EXPECT().Close()
|
||||
service.Run()
|
||||
service.Close()
|
||||
})
|
||||
}
|
||||
|
||||
@ -96,6 +96,7 @@ func NewSpaceId(id string, repKey uint64) string {
|
||||
type Space interface {
|
||||
Id() string
|
||||
Init(ctx context.Context) error
|
||||
StartHeadSync()
|
||||
|
||||
StoredIds() []string
|
||||
DebugAllHeads() []headsync.TreeHeads
|
||||
@ -231,6 +232,10 @@ func (s *space) Init(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *space) StartHeadSync() {
|
||||
s.headSync.Run()
|
||||
}
|
||||
|
||||
func (s *space) ObjectSync() objectsync.ObjectSync {
|
||||
return s.objectSync
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user