Skip to content

Commit 070c7e4

Browse files
committed
fix host index keepalive
1 parent c25248d commit 070c7e4

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

pkg/metadata.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,7 @@ func (m *BlobCacheMetadata) GetAvailableHosts(ctx context.Context, removeHostCal
323323
}
324324

325325
func (m *BlobCacheMetadata) AddHostToIndex(ctx context.Context, host *BlobCacheHost) error {
326-
err := m.rdb.SAdd(ctx, MetadataKeys.MetadataHostIndex(), host.Addr).Err()
327-
if err != nil {
328-
return err
329-
}
330-
331-
return m.SetHostKeepAlive(ctx, host)
326+
return m.rdb.SAdd(ctx, MetadataKeys.MetadataHostIndex(), host.Addr).Err()
332327
}
333328

334329
func (m *BlobCacheMetadata) RemoveHostFromIndex(ctx context.Context, host *BlobCacheHost) error {
@@ -341,11 +336,6 @@ func (m *BlobCacheMetadata) SetHostKeepAlive(ctx context.Context, host *BlobCach
341336
return err
342337
}
343338

344-
err = m.AddHostToIndex(ctx, host)
345-
if err != nil {
346-
return err
347-
}
348-
349339
return m.rdb.Set(ctx, MetadataKeys.MetadataHostKeepAlive(host.Addr), hostBytes, time.Duration(defaultHostKeepAliveTimeoutS)*time.Second).Err()
350340
}
351341

pkg/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,14 @@ func NewCacheService(ctx context.Context, cfg BlobCacheConfig) (*CacheService, e
9999
}
100100

101101
func (cs *CacheService) HostKeepAlive() {
102-
err := cs.metadata.AddHostToIndex(cs.ctx, cs.cas.currentHost)
102+
err := cs.metadata.SetHostKeepAlive(cs.ctx, cs.cas.currentHost)
103103
if err != nil {
104-
Logger.Fatalf("Failed to add host to index: %v", err)
104+
Logger.Warnf("Failed to set host keepalive: %v", err)
105+
}
106+
107+
err = cs.metadata.AddHostToIndex(cs.ctx, cs.cas.currentHost)
108+
if err != nil {
109+
Logger.Warnf("Failed to add host to index: %v", err)
105110
}
106111

107112
ticker := time.NewTicker(time.Duration(defaultHostKeepAliveIntervalS) * time.Second)
@@ -114,6 +119,8 @@ func (cs *CacheService) HostKeepAlive() {
114119
case <-ticker.C:
115120
cs.cas.currentHost.PrivateAddr = fmt.Sprintf("%s:%d", cs.privateIpAddr, cs.cfg.Port)
116121
cs.cas.currentHost.CapacityUsagePct = cs.usagePct()
122+
123+
cs.metadata.AddHostToIndex(cs.ctx, cs.cas.currentHost)
117124
cs.metadata.SetHostKeepAlive(cs.ctx, cs.cas.currentHost)
118125
}
119126
}

0 commit comments

Comments
 (0)