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