@@ -242,38 +242,18 @@ func (cm *manager) InitiateViewWithIdentity(view view.View, id view.Identity, c
242
242
}
243
243
244
244
func (cm * manager ) InitiateContext (view view.View ) (view.Context , error ) {
245
- cm .contextsSync .Lock ()
246
- ctx := cm .ctx
247
- cm .contextsSync .Unlock ()
248
-
249
- return cm .InitiateContextFrom (ctx , view , cm .me (), "" )
245
+ return cm .InitiateContextFrom (cm .ctx , view , cm .me (), "" )
250
246
}
251
247
252
248
func (cm * manager ) InitiateContextWithIdentity (view view.View , id view.Identity ) (view.Context , error ) {
253
- cm .contextsSync .Lock ()
254
- ctx := cm .ctx
255
- cm .contextsSync .Unlock ()
256
-
257
- return cm .InitiateContextFrom (ctx , view , id , "" )
249
+ return cm .InitiateContextFrom (cm .ctx , view , id , "" )
258
250
}
259
251
260
252
func (cm * manager ) InitiateContextWithIdentityAndID (view view.View , id view.Identity , contextID string ) (view.Context , error ) {
261
- cm .contextsSync .Lock ()
262
- ctx := cm .ctx
263
- cm .contextsSync .Unlock ()
264
-
265
- return cm .InitiateContextFrom (ctx , view , id , contextID )
253
+ return cm .InitiateContextFrom (cm .ctx , view , id , contextID )
266
254
}
267
255
268
256
func (cm * manager ) InitiateContextFrom (ctx context.Context , view view.View , id view.Identity , contextID string ) (view.Context , error ) {
269
- if ctx == nil {
270
- cm .contextsSync .Lock ()
271
- ctx = cm .ctx
272
- cm .contextsSync .Unlock ()
273
- }
274
- if ctx == nil {
275
- ctx = context .Background ()
276
- }
277
257
if id .IsNone () {
278
258
id = cm .me ()
279
259
}
@@ -295,9 +275,7 @@ func (cm *manager) InitiateContextFrom(ctx context.Context, view view.View, id v
295
275
}
296
276
297
277
func (cm * manager ) Start (ctx context.Context ) {
298
- cm .contextsSync .Lock ()
299
278
cm .ctx = ctx
300
- cm .contextsSync .Unlock ()
301
279
session , err := cm .commLayer .MasterSession ()
302
280
if err != nil {
303
281
return
@@ -422,7 +400,6 @@ func (cm *manager) newContext(id view.Identity, msg *view.Message) (view.Context
422
400
cm .contextsSync .Lock ()
423
401
defer cm .contextsSync .Unlock ()
424
402
425
- isNew := false
426
403
caller , err := cm .endpointService .GetIdentity (msg .FromEndpoint , msg .FromPKID )
427
404
if err != nil {
428
405
return nil , false , err
@@ -445,35 +422,27 @@ func (cm *manager) newContext(id view.Identity, msg *view.Message) (view.Context
445
422
cm .m .Contexts .Set (float64 (len (cm .contexts )))
446
423
ok = false
447
424
}
448
- if ! ok {
449
- if logger .IsEnabledFor (zapcore .DebugLevel ) {
450
- logger .Debugf ("[%s] Create new context to respond [contextID:%s]\n " , id , msg .ContextID )
451
- }
452
- backend , err := cm .commLayer .NewSessionWithID (msg .SessionID , contextID , msg .FromEndpoint , msg .FromPKID , caller , msg )
453
- if err != nil {
454
- return nil , false , err
455
- }
456
- ctx := cm .ctx
457
- if ctx == nil {
458
- ctx = context .Background ()
459
- }
460
- ctx = trace .ContextWithSpanContext (ctx , trace .SpanContextFromContext (msg .Ctx ))
461
- newCtx , err := NewContext (ctx , cm .sp , contextID , cm .commLayer , cm .endpointService , id , backend , caller , cm .viewTracer )
462
- if err != nil {
463
- return nil , false , err
464
- }
465
- childContext := & childContext {ParentContext : newCtx }
466
- cm .contexts [contextID ] = childContext
467
- cm .m .Contexts .Set (float64 (len (cm .contexts )))
468
- viewContext = childContext
469
- isNew = true
470
- } else {
471
- if logger .IsEnabledFor (zapcore .DebugLevel ) {
472
- logger .Debugf ("[%s] No new context to respond, reuse [contextID:%s]\n " , id , msg .ContextID )
473
- }
425
+ if ok {
426
+ logger .Debugf ("[%s] No new context to respond, reuse [contextID:%s]\n " , id , msg .ContextID )
427
+ return viewContext , false , nil
428
+ }
429
+
430
+ logger .Debugf ("[%s] Create new context to respond [contextID:%s]\n " , id , msg .ContextID )
431
+ backend , err := cm .commLayer .NewSessionWithID (msg .SessionID , contextID , msg .FromEndpoint , msg .FromPKID , caller , msg )
432
+ if err != nil {
433
+ return nil , false , err
474
434
}
435
+ ctx := trace .ContextWithSpanContext (cm .ctx , trace .SpanContextFromContext (msg .Ctx ))
436
+ newCtx , err := NewContext (ctx , cm .sp , contextID , cm .commLayer , cm .endpointService , id , backend , caller , cm .viewTracer )
437
+ if err != nil {
438
+ return nil , false , err
439
+ }
440
+ childContext := & childContext {ParentContext : newCtx }
441
+ cm .contexts [contextID ] = childContext
442
+ cm .m .Contexts .Set (float64 (len (cm .contexts )))
443
+ viewContext = childContext
475
444
476
- return viewContext , isNew , nil
445
+ return viewContext , true , nil
477
446
}
478
447
479
448
func (cm * manager ) deleteContext (id view.Identity , contextID string ) {
0 commit comments