Skip to content

Commit ee3a839

Browse files
authored
Merge pull request #11 from ShareChat/xds-cache
Xds cache
2 parents ebfafc9 + 4b7e052 commit ee3a839

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

pkg/cache/v3/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type ConfigWatcher interface {
6666
//
6767
// Cancel is an optional function to release resources in the producer. If
6868
// provided, the consumer may call this function multiple times.
69-
CreateDeltaWatch(*DeltaRequest, stream.StreamState, chan DeltaResponse) (cancel func())
69+
CreateDeltaWatch(*DeltaRequest, stream.StreamState, chan DeltaResponse) (delayedResponse bool, cancel func())
7070
}
7171

7272
// ConfigFetcher fetches configuration resources from cache

pkg/cache/v3/linear.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func (cache *LinearCache) CreateWatch(request *Request, _ stream.StreamState, va
382382
}
383383
}
384384

385-
func (cache *LinearCache) CreateDeltaWatch(request *DeltaRequest, state stream.StreamState, value chan DeltaResponse) func() {
385+
func (cache *LinearCache) CreateDeltaWatch(request *DeltaRequest, state stream.StreamState, value chan DeltaResponse) (bool, func()) {
386386
cache.mu.Lock()
387387
defer cache.mu.Unlock()
388388

@@ -412,10 +412,10 @@ func (cache *LinearCache) CreateDeltaWatch(request *DeltaRequest, state stream.S
412412

413413
cache.deltaWatches[watchID] = DeltaResponseWatch{Request: request, Response: value, StreamState: state}
414414

415-
return cache.cancelDeltaWatch(watchID)
415+
return false, cache.cancelDeltaWatch(watchID)
416416
}
417417

418-
return nil
418+
return false, nil
419419
}
420420

421421
func (cache *LinearCache) updateVersionMap(modified map[string]struct{}) error {

pkg/cache/v3/mux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ func (mux *MuxCache) CreateWatch(request *Request, state stream.StreamState, val
4747
return cache.CreateWatch(request, state, value)
4848
}
4949

50-
func (mux *MuxCache) CreateDeltaWatch(request *DeltaRequest, state stream.StreamState, value chan DeltaResponse) func() {
50+
func (mux *MuxCache) CreateDeltaWatch(request *DeltaRequest, state stream.StreamState, value chan DeltaResponse) (bool, func()) {
5151
key := mux.ClassifyDelta(request)
5252
cache, exists := mux.Caches[key]
5353
if !exists {
5454
value <- nil
55-
return nil
55+
return false, nil
5656
}
5757
return cache.CreateDeltaWatch(request, state, value)
5858
}

pkg/cache/v3/simple.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (cache *snapshotCache) BatchUpsertResources(ctx context.Context, typ string
313313
info.mu.Lock()
314314

315315
// Respond to delta watches for the node.
316-
err := cache.respondDeltaWatches(ctx, info, snapshot)
316+
err := cache.respondDeltaWatches(ctx, info, s)
317317
if err != nil {
318318
info.mu.Unlock()
319319
continue
@@ -904,7 +904,7 @@ func createResponse(ctx context.Context, request *Request, resources map[string]
904904
}
905905

906906
// CreateDeltaWatch returns a watch for a delta xDS request which implements the Simple SnapshotCache.
907-
func (cache *snapshotCache) CreateDeltaWatch(request *DeltaRequest, state stream.StreamState, value chan DeltaResponse) func() {
907+
func (cache *snapshotCache) CreateDeltaWatch(request *DeltaRequest, state stream.StreamState, value chan DeltaResponse) (bool, func()) {
908908
nodeID := cache.hash.ID(request.GetNode())
909909
t := request.GetTypeUrl()
910910

@@ -934,12 +934,12 @@ func (cache *snapshotCache) CreateDeltaWatch(request *DeltaRequest, state stream
934934
cache.log.Errorf("failed to compute version for snapshot resources inline: %s", err)
935935
}
936936
// We don't need to respond. We're handling this in a better way in ads.
937-
// response, err := cache.respondDelta(context.Background(), snapshot, request, value, state)
937+
response, err := cache.respondDelta(context.Background(), snapshot, request, value, state)
938938
if err != nil {
939939
cache.log.Errorf("failed to respond with delta response: %s", err)
940940
}
941941

942-
delayedResponse = true // response == nil
942+
delayedResponse = response == nil
943943
}
944944

945945
if delayedResponse {
@@ -952,10 +952,10 @@ func (cache *snapshotCache) CreateDeltaWatch(request *DeltaRequest, state stream
952952
}
953953

954954
info.setDeltaResponseWatch(watchID, DeltaResponseWatch{Request: request, Response: value, StreamState: state})
955-
return cache.cancelDeltaWatch(nodeID, watchID)
955+
return delayedResponse, cache.cancelDeltaWatch(nodeID, watchID)
956956
}
957957

958-
return nil
958+
return false, nil
959959
}
960960

961961
func GetEnvoyNodeStr(node *core.Node) string {

0 commit comments

Comments
 (0)