@@ -140,9 +140,8 @@ RestHandler::status RestAgencyHandler::handleWrite() {
140
140
}
141
141
142
142
auto s = std::chrono::system_clock::now (); // Leadership established?
143
- std::chrono::seconds timeout (1 );
143
+ std::chrono::duration< double > timeout (_agent-> config (). minPing () );
144
144
while (_agent->size () > 1 && _agent->leaderID () == " " ) {
145
- std::this_thread::sleep_for (duration_t (100 ));
146
145
if ((std::chrono::system_clock::now ()-s) > timeout) {
147
146
Builder body;
148
147
body.openObject ();
@@ -153,12 +152,12 @@ RestHandler::status RestAgencyHandler::handleWrite() {
153
152
LOG_TOPIC (ERR, Logger::AGENCY) << " We don't know who the leader is" ;
154
153
return status::DONE;
155
154
}
155
+ std::this_thread::sleep_for (duration_t (100 ));
156
156
}
157
157
158
158
write_ret_t ret = _agent->write (query);
159
159
160
160
if (ret.accepted ) { // We're leading and handling the request
161
-
162
161
bool found;
163
162
std::string call_mode = _request->header (" x-arangodb-agency-mode" , found);
164
163
if (!found) {
@@ -227,9 +226,8 @@ inline RestHandler::status RestAgencyHandler::handleRead() {
227
226
}
228
227
229
228
auto s = std::chrono::system_clock::now (); // Leadership established?
230
- std::chrono::seconds timeout (1 );
231
- while (_agent->size () > 1 && _agent->leaderID () == " " ) {
232
- std::this_thread::sleep_for (duration_t (100 ));
229
+ std::chrono::duration<double > timeout (_agent->config ().minPing ());
230
+ while (_agent->size () > 1 && _agent->leaderID () == NO_LEADER) {
233
231
if ((std::chrono::system_clock::now ()-s) > timeout) {
234
232
Builder body;
235
233
body.openObject ();
@@ -240,6 +238,7 @@ inline RestHandler::status RestAgencyHandler::handleRead() {
240
238
LOG_TOPIC (ERR, Logger::AGENCY) << " We don't know who the leader is" ;
241
239
return status::DONE;
242
240
}
241
+ std::this_thread::sleep_for (duration_t (100 ));
243
242
}
244
243
245
244
read_ret_t ret = _agent->read (query);
@@ -252,7 +251,20 @@ inline RestHandler::status RestAgencyHandler::handleRead() {
252
251
generateResult (GeneralResponse::ResponseCode::OK, ret.result ->slice ());
253
252
}
254
253
} else { // Redirect to leader
255
- redirectRequest (ret.redirect );
254
+ if (_agent->leaderID () == NO_LEADER) {
255
+
256
+ Builder body;
257
+ body.openObject ();
258
+ body.add (" message" , VPackValue (" No leader" ));
259
+ body.close ();
260
+ generateResult (GeneralResponse::ResponseCode::SERVICE_UNAVAILABLE,
261
+ body.slice ());
262
+ LOG_TOPIC (ERR, Logger::AGENCY) << " We don't know who the leader is" ;
263
+ return status::DONE;
264
+
265
+ } else {
266
+ redirectRequest (ret.redirect );
267
+ }
256
268
return status::DONE;
257
269
}
258
270
} else {
@@ -263,6 +275,7 @@ inline RestHandler::status RestAgencyHandler::handleRead() {
263
275
}
264
276
265
277
RestHandler::status RestAgencyHandler::handleConfig () {
278
+
266
279
Builder body;
267
280
body.add (VPackValue (VPackValueType::Object));
268
281
body.add (" term" , Value (_agent->term ()));
0 commit comments