Space headsync delayed start

This commit is contained in:
mcrakhman 2023-05-24 14:54:10 +02:00
parent f8c79c33bc
commit 2ab43e2b69
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B
3 changed files with 18 additions and 2 deletions

View File

@ -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) {

View File

@ -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()
})
}

View File

@ -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
}