Skip to content

Commit 1f40ee5

Browse files
committed
fix: fixed broken HA test, reduced errors in console on HA replication issues
1 parent 79633a4 commit 1f40ee5

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

server/src/main/java/com/arcadedb/server/http/handler/AbstractServerHttpHandler.java

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ protected String parseRequestPayload(final HttpServerExchange e) {
6060
e.startBlocking();
6161

6262
if (!mustExecuteOnWorkerThread())
63-
LogManager.instance().log(this, Level.SEVERE, "Error: handler must return true at mustExecuteOnWorkerThread() to read payload from request");
63+
LogManager.instance()
64+
.log(this, Level.SEVERE, "Error: handler must return true at mustExecuteOnWorkerThread() to read payload from request");
6465

6566
final AtomicReference<String> result = new AtomicReference<>();
6667
e.getRequestReceiver().receiveFullBytes(
@@ -90,7 +91,7 @@ public void handleRequest(final HttpServerExchange exchange) {
9091
final HeaderValues authorization = exchange.getRequestHeaders().get("Authorization");
9192
if (isRequireAuthentication() && (authorization == null || authorization.isEmpty())) {
9293
exchange.setStatusCode(401);
93-
exchange.getResponseHeaders().put(Headers.WWW_AUTHENTICATE,"Basic");
94+
exchange.getResponseHeaders().put(Headers.WWW_AUTHENTICATE, "Basic");
9495
sendErrorResponse(exchange, 401, "", null, null);
9596
return;
9697
}
@@ -130,39 +131,56 @@ public void handleRequest(final HttpServerExchange exchange) {
130131

131132
} catch (final ServerSecurityException e) {
132133
// PASS SecurityException TO THE CLIENT
133-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Security error on command execution (%s)", e, SecurityException.class.getSimpleName());
134+
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Security error on command execution (%s): %s",
135+
SecurityException.class.getSimpleName(), e.getMessage());
134136
sendErrorResponse(exchange, 403, "Security error", e, null);
135137
} catch (final ServerIsNotTheLeaderException e) {
136-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
138+
LogManager.instance()
139+
.log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(),
140+
e.getMessage());
137141
sendErrorResponse(exchange, 400, "Cannot execute command", e, e.getLeaderAddress());
138142
} catch (final NeedRetryException e) {
139-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
143+
LogManager.instance()
144+
.log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(),
145+
e.getMessage());
140146
sendErrorResponse(exchange, 503, "Cannot execute command", e, null);
141147
} catch (final DuplicatedKeyException e) {
142-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
143-
sendErrorResponse(exchange, 503, "Found duplicate key in index", e, e.getIndexName() + "|" + e.getKeys() + "|" + e.getCurrentIndexedRID());
148+
LogManager.instance()
149+
.log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(),
150+
e.getMessage());
151+
sendErrorResponse(exchange, 503, "Found duplicate key in index", e,
152+
e.getIndexName() + "|" + e.getKeys() + "|" + e.getCurrentIndexedRID());
144153
} catch (final RecordNotFoundException e) {
145-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
154+
LogManager.instance()
155+
.log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(),
156+
e.getMessage());
146157
sendErrorResponse(exchange, 404, "Record not found", e, null);
147158
} catch (final IllegalArgumentException e) {
148-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
159+
LogManager.instance()
160+
.log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(),
161+
e.getMessage());
149162
sendErrorResponse(exchange, 400, "Cannot execute command", e, null);
150163
} catch (final CommandExecutionException | CommandParsingException e) {
151164
Throwable realException = e;
152165
if (e.getCause() != null)
153166
realException = e.getCause();
154167

155-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
168+
LogManager.instance()
169+
.log(this, getUserSevereErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(),
170+
e.getMessage());
156171
sendErrorResponse(exchange, 500, "Cannot execute command", realException, null);
157172
} catch (final TransactionException e) {
158173
Throwable realException = e;
159174
if (e.getCause() != null)
160175
realException = e.getCause();
161176

162-
LogManager.instance().log(this, getUserSevereErrorLogLevel(), "Error on transaction execution (%s)", e, getClass().getSimpleName());
177+
LogManager.instance()
178+
.log(this, getUserSevereErrorLogLevel(), "Error on transaction execution (%s): %s", getClass().getSimpleName(),
179+
e.getMessage());
163180
sendErrorResponse(exchange, 500, "Error on transaction commit", realException, null);
164181
} catch (final Throwable e) {
165-
LogManager.instance().log(this, getErrorLogLevel(), "Error on command execution (%s)", e, getClass().getSimpleName());
182+
LogManager.instance()
183+
.log(this, getErrorLogLevel(), "Error on command execution (%s): %s", getClass().getSimpleName(), e.getMessage());
166184
sendErrorResponse(exchange, 500, "Internal error", e, null);
167185
} finally {
168186
LogManager.instance().setContext(null);
@@ -189,15 +207,17 @@ protected JSONObject createResult(final SecurityUser user, final Database databa
189207
final JSONObject json = new JSONObject();
190208
if (database != null)
191209
json.setDateFormat(database.getSchema().getDateTimeFormat());
192-
json.put("user", user.getName()).put("version", Constants.getVersion()).put("serverName", httpServer.getServer().getServerName());
210+
json.put("user", user.getName()).put("version", Constants.getVersion())
211+
.put("serverName", httpServer.getServer().getServerName());
193212
return json;
194213
}
195214

196215
protected String decode(final String command) {
197216
return command.replace("&amp;", " ").replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&#039;", "'");
198217
}
199218

200-
protected String error2json(final String error, final String detail, final Throwable exception, final String exceptionArgs, final String help) {
219+
protected String error2json(final String error, final String detail, final Throwable exception, final String exceptionArgs,
220+
final String help) {
201221
final JSONObject json = new JSONObject();
202222
json.put("error", error);
203223
if (detail != null)
@@ -232,14 +252,19 @@ protected String getQueryParameter(final HttpServerExchange exchange, final Stri
232252
}
233253

234254
private Level getErrorLogLevel() {
235-
return "development".equals(httpServer.getServer().getConfiguration().getValueAsString(GlobalConfiguration.SERVER_MODE)) ? Level.SEVERE : Level.FINE;
255+
return "development".equals(httpServer.getServer().getConfiguration().getValueAsString(GlobalConfiguration.SERVER_MODE)) ?
256+
Level.SEVERE :
257+
Level.FINE;
236258
}
237259

238260
private Level getUserSevereErrorLogLevel() {
239-
return "development".equals(httpServer.getServer().getConfiguration().getValueAsString(GlobalConfiguration.SERVER_MODE)) ? Level.INFO : Level.FINE;
261+
return "development".equals(httpServer.getServer().getConfiguration().getValueAsString(GlobalConfiguration.SERVER_MODE)) ?
262+
Level.INFO :
263+
Level.FINE;
240264
}
241265

242-
private void sendErrorResponse(final HttpServerExchange exchange, final int code, final String errorMessage, final Throwable e, final String exceptionArgs) {
266+
private void sendErrorResponse(final HttpServerExchange exchange, final int code, final String errorMessage, final Throwable e,
267+
final String exceptionArgs) {
243268
if (!exchange.isResponseStarted())
244269
exchange.setStatusCode(code);
245270
exchange.getResponseSender().send(error2json(errorMessage, e != null ? e.getMessage() : "", e, exceptionArgs, null));

server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderChanges3TimesIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void testReplication() {
100100
}
101101

102102
}
103+
break;
103104

104105
} catch (final NeedRetryException | TimeoutException | TransactionException e) {
105106
if (e instanceof TimeoutException) {
@@ -108,18 +109,17 @@ public void testReplication() {
108109
}
109110
// IGNORE IT
110111
LogManager.instance()
111-
.log(this, Level.SEVERE, "Error on creating vertex %d, retrying (retry=%d/%d)...", e, counter, retry, maxRetry);
112+
.log(this, Level.SEVERE, "Error on creating vertex %d, retrying (retry=%d/%d): %s", counter, retry, maxRetry,
113+
e.getMessage());
112114
CodeUtils.sleep(500);
113115

114116
} catch (final DuplicatedKeyException e) {
115117
// THIS MEANS THE ENTRY WAS INSERTED BEFORE THE CRASH
116-
LogManager.instance().log(this, Level.SEVERE, "Error: %s (IGNORE IT)", null, e.toString());
118+
LogManager.instance().log(this, Level.SEVERE, "Error: %s (IGNORE IT)", e.getMessage());
117119
} catch (final Exception e) {
118120
// IGNORE IT
119-
LogManager.instance().log(this, Level.SEVERE, "Generic Exception: %s", e, e.getMessage());
121+
LogManager.instance().log(this, Level.SEVERE, "Generic Exception: %s", e.getMessage());
120122
}
121-
122-
break;
123123
}
124124
}
125125

0 commit comments

Comments
 (0)