1
1
import { type Client , connect } from "./client" ;
2
2
import { Patterns } from "./patterns" ;
3
- import {
4
- updateInterest ,
5
- updateSticky ,
6
- type InterestUpdate ,
7
- type StickyUpdate ,
8
- } from "@cocalc/conat/core/server" ;
3
+ import { updateInterest , type InterestUpdate } from "@cocalc/conat/core/server" ;
9
4
import type { DStream } from "@cocalc/conat/sync/dstream" ;
10
5
import { once } from "@cocalc/util/async-utils" ;
11
6
import { server as createPersistServer } from "@cocalc/conat/persist/server" ;
@@ -47,14 +42,12 @@ export async function clusterLink(
47
42
return link ;
48
43
}
49
44
50
- export type Sticky = { [ pattern : string ] : { [ subject : string ] : string } } ;
51
45
export type Interest = Patterns < { [ queue : string ] : Set < string > } > ;
52
46
53
47
export { type ClusterLink } ;
54
48
55
49
class ClusterLink {
56
50
public interest : Interest = new Patterns ( ) ;
57
- public sticky : Sticky = { } ;
58
51
private streams : ClusterStreams ;
59
52
private state : "init" | "ready" | "closed" = "init" ;
60
53
private clientStateChanged = Date . now ( ) ; // when client status last changed
@@ -85,10 +78,7 @@ class ClusterLink {
85
78
clusterName : this . clusterName ,
86
79
} ) ;
87
80
for ( const update of this . streams . interest . getAll ( ) ) {
88
- updateInterest ( update , this . interest , this . sticky ) ;
89
- }
90
- for ( const update of this . streams . sticky . getAll ( ) ) {
91
- updateSticky ( update , this . sticky ) ;
81
+ updateInterest ( update , this . interest ) ;
92
82
}
93
83
// I have a slight concern about this because updates might not
94
84
// arrive in order during automatic failover. That said, maybe
@@ -97,7 +87,6 @@ class ClusterLink {
97
87
// it is about, and when that server goes down none of this state
98
88
// matters anymore.
99
89
this . streams . interest . on ( "change" , this . handleInterestUpdate ) ;
100
- this . streams . sticky . on ( "change" , this . handleStickyUpdate ) ;
101
90
this . state = "ready" ;
102
91
} ;
103
92
@@ -106,11 +95,7 @@ class ClusterLink {
106
95
} ;
107
96
108
97
handleInterestUpdate = ( update : InterestUpdate ) => {
109
- updateInterest ( update , this . interest , this . sticky ) ;
110
- } ;
111
-
112
- handleStickyUpdate = ( update : StickyUpdate ) => {
113
- updateSticky ( update , this . sticky ) ;
98
+ updateInterest ( update , this . interest ) ;
114
99
} ;
115
100
116
101
private handleClientStateChanged = ( ) => {
@@ -134,7 +119,6 @@ class ClusterLink {
134
119
if ( this . streams != null ) {
135
120
this . streams . interest . removeListener ( "change" , this . handleInterestUpdate ) ;
136
121
this . streams . interest . close ( ) ;
137
- this . streams . sticky . close ( ) ;
138
122
// @ts -ignore
139
123
delete this . streams ;
140
124
}
@@ -178,10 +162,9 @@ class ClusterLink {
178
162
return false ;
179
163
} ;
180
164
181
- hash = ( ) : { interest : number ; sticky : number } => {
165
+ hash = ( ) : { interest : number } => {
182
166
return {
183
167
interest : hashInterest ( this . interest ) ,
184
- sticky : hashSticky ( this . sticky ) ,
185
168
} ;
186
169
} ;
187
170
}
@@ -195,7 +178,6 @@ function clusterStreamNames({
195
178
} ) {
196
179
return {
197
180
interest : `cluster/${ clusterName } /${ id } /interest` ,
198
- sticky : `cluster/${ clusterName } /${ id } /sticky` ,
199
181
} ;
200
182
}
201
183
@@ -225,7 +207,6 @@ export async function createClusterPersistServer({
225
207
226
208
export interface ClusterStreams {
227
209
interest : DStream < InterestUpdate > ;
228
- sticky : DStream < StickyUpdate > ;
229
210
}
230
211
231
212
export async function clusterStreams ( {
@@ -252,27 +233,21 @@ export async function clusterStreams({
252
233
name : names . interest ,
253
234
...opts ,
254
235
} ) ;
255
- const sticky = await client . sync . dstream < StickyUpdate > ( {
256
- noInventory : true ,
257
- name : names . sticky ,
258
- ...opts ,
259
- } ) ;
260
236
logger . debug ( "clusterStreams: got them" , { clusterName } ) ;
261
- return { interest, sticky } ;
237
+ return { interest } ;
262
238
}
263
239
264
240
// Periodically delete not-necessary updates from the interest stream
265
241
export async function trimClusterStreams (
266
242
streams : ClusterStreams ,
267
243
data : {
268
244
interest : Patterns < { [ queue : string ] : Set < string > } > ;
269
- sticky : { [ pattern : string ] : { [ subject : string ] : string } } ;
270
245
links : { interest : Patterns < { [ queue : string ] : Set < string > } > } [ ] ;
271
246
} ,
272
247
// don't delete anything that isn't at lest minAge ms old.
273
248
minAge : number ,
274
- ) : Promise < { seqsInterest : number [ ] ; seqsSticky : number [ ] } > {
275
- const { interest, sticky } = streams ;
249
+ ) : Promise < { seqsInterest : number [ ] } > {
250
+ const { interest } = streams ;
276
251
// First deal with interst
277
252
// we iterate over the interest stream checking for subjects
278
253
// with no current interest at all; in such cases it is safe
@@ -300,45 +275,7 @@ export async function trimClusterStreams(
300
275
logger . debug ( "trimClusterStream: successfully trimmed interest" , { seqs } ) ;
301
276
}
302
277
303
- // Next deal with sticky -- trim ones where the pattern is no longer of interest.
304
- // There could be other reasons to trim but it gets much trickier. This one is more
305
- // obvious, except we have to check for any interest in the whole cluster, not
306
- // just this node.
307
- const seqs2 : number [ ] = [ ] ;
308
- function noInterest ( pattern : string ) {
309
- if ( data . interest . hasPattern ( pattern ) ) {
310
- return false ;
311
- }
312
- for ( const link of data . links ) {
313
- if ( link . interest . hasPattern ( pattern ) ) {
314
- return false ;
315
- }
316
- }
317
- // nobody cares
318
- return true ;
319
- }
320
- for ( let n = 0 ; n < sticky . length ; n ++ ) {
321
- const time = sticky . time ( n ) ;
322
- if ( time == null ) continue ;
323
- if ( now - time . valueOf ( ) <= minAge ) {
324
- break ;
325
- }
326
- const update = sticky . get ( n ) as StickyUpdate ;
327
- if ( noInterest ( update . pattern ) ) {
328
- const seq = sticky . seq ( n ) ;
329
- if ( seq != null ) {
330
- seqs2 . push ( seq ) ;
331
- }
332
- }
333
- }
334
- if ( seqs2 . length > 0 ) {
335
- // [ ] todo -- add to interest.delete a version where it takes an array of sequence numbers
336
- logger . debug ( "trimClusterStream: trimming sticky" , { seqs2 } ) ;
337
- await sticky . delete ( { seqs : seqs2 } ) ;
338
- logger . debug ( "trimClusterStream: successfully trimmed sticky" , { seqs2 } ) ;
339
- }
340
-
341
- return { seqsInterest : seqs , seqsSticky : seqs2 } ;
278
+ return { seqsInterest : seqs } ;
342
279
}
343
280
344
281
function hashSet ( X : Set < string > ) : number {
@@ -362,15 +299,3 @@ export function hashInterest(
362
299
) : number {
363
300
return interest . hash ( hashInterestValue ) ;
364
301
}
365
-
366
- export function hashSticky ( sticky : Sticky ) : number {
367
- let h = 0 ;
368
- for ( const pattern in sticky ) {
369
- h += hash_string ( pattern ) ;
370
- const x = sticky [ pattern ] ;
371
- for ( const subject in x ) {
372
- h += hash_string ( x [ subject ] ) ;
373
- }
374
- }
375
- return h ;
376
- }
0 commit comments