@@ -25,20 +25,23 @@ void TPQWriteServiceImpl::TSession::OnCreated() { // Start waiting fo
25
25
ReplyWithError (" proxy overloaded" , NPersQueue::NErrorCode::OVERLOAD);
26
26
return ;
27
27
}
28
- TMaybe<TString> localCluster = Proxy->AvailableLocalCluster ();
29
28
if (NeedDiscoverClusters) {
29
+ TMaybe<TString> localCluster = Proxy->AvailableLocalCluster ();
30
30
if (!localCluster.Defined ()) {
31
31
ReplyWithError (" initializing" , NPersQueue::NErrorCode::INITIALIZING);
32
32
return ;
33
33
} else if (localCluster->empty ()) {
34
34
ReplyWithError (" cluster disabled" , NPersQueue::NErrorCode::CLUSTER_DISABLED);
35
35
return ;
36
- } else {
37
- CreateActor (*localCluster);
36
+ } else if (!CreateActor (*localCluster)) {
37
+ Proxy->ReleaseSession (this );
38
+ return ;
38
39
}
39
- } else {
40
- CreateActor (TString ());
40
+ } else if (!CreateActor (TString ())) {
41
+ Proxy->ReleaseSession (this );
42
+ return ;
41
43
}
44
+
42
45
ReadyForNextRead ();
43
46
}
44
47
@@ -61,9 +64,14 @@ void TPQWriteServiceImpl::TSession::OnRead(const TWriteRequest& request) {
61
64
}
62
65
63
66
void TPQWriteServiceImpl::TSession::OnDone () {
67
+ {
68
+ TGuard<TSpinLock> lock (Lock);
69
+ IsDone = true ;
70
+ }
64
71
SendEvent (new TEvPQProxy::TEvDone ());
65
72
}
66
73
74
+
67
75
TPQWriteServiceImpl::TSession::TSession (std::shared_ptr<TPQWriteServiceImpl> proxy,
68
76
grpc::ServerCompletionQueue* cq, ui64 cookie, const TActorId& schemeCache,
69
77
TIntrusivePtr<NMonitoring::TDynamicCounters> counters, bool needDiscoverClusters)
@@ -97,18 +105,30 @@ bool TPQWriteServiceImpl::TSession::IsShuttingDown() const {
97
105
return Proxy->IsShuttingDown ();
98
106
}
99
107
100
- void TPQWriteServiceImpl::TSession::CreateActor (const TString &localCluster) {
108
+ bool TPQWriteServiceImpl::TSession::CreateActor (const TString &localCluster) {
109
+ TGuard<TSpinLock> lock (Lock);
110
+ if (IsDone) {
111
+ ReplyWithError (" is done" , NPersQueue::NErrorCode::INITIALIZING);
112
+ return false ;
113
+ }
101
114
102
115
auto classifier = Proxy->GetClassifier ();
103
116
ActorId = Proxy->ActorSystem ->Register (
104
117
new TWriteSessionActor (this , Cookie, SchemeCache, Counters, localCluster,
105
118
classifier ? classifier->ClassifyAddress (GetPeerName ())
106
119
: " unknown" ), TMailboxType::Simple, 0
107
120
);
121
+ return true ;
108
122
}
109
123
110
124
void TPQWriteServiceImpl::TSession::SendEvent (IEventBase* ev) {
111
- Proxy->ActorSystem ->Send (ActorId, ev);
125
+ std::unique_ptr<IEventBase> e;
126
+ e.reset (ev);
127
+
128
+ TGuard<TSpinLock> lock (Lock);
129
+ if (ActorId) {
130
+ Proxy->ActorSystem ->Send (ActorId, e.release ());
131
+ }
112
132
}
113
133
114
134
// /////////////////////////////////////////////////////////////////////////////
0 commit comments