Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RANGER-4943: Error in ElasticSearchAuditDestination shutting down RestHighLevelClient client #397

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.security.auth.kerberos.KerberosTicket;

import java.io.File;
import java.io.IOException;
import java.security.PrivilegedActionException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -319,32 +320,30 @@ private String connectionString() {
}

private RestHighLevelClient newClient() {
RestHighLevelClient restHighLevelClient = null;

try {
if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password) && password.contains("keytab") && new File(password).exists()) {
subject = CredentialsProviderUtil.login(user, password);
}

RestClientBuilder restClientBuilder = getRestClientBuilder(hosts, protocol, user, password, port);
restHighLevelClient = new RestHighLevelClient(restClientBuilder);
boolean exists = false;

try (RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder)) {
LOG.debug("Initialized client");

boolean exists = false;

try {
exists = restHighLevelClient.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
} catch (Exception e) {
LOG.warn("Error validating index {}", this.index);
}

if (exists) {
LOG.debug("Index exists");
} else {
LOG.info("Index does not exist");
}
try {
exists = restHighLevelClient.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
} catch (Exception e) {
LOG.warn("Error validating index {}", this.index);
}

return restHighLevelClient;
if (exists) {
LOG.debug("Index exists");
} else {
LOG.info("Index does not exist");
}

return restHighLevelClient;
} catch (Throwable t) {
lastLoggedAt.updateAndGet(lastLoggedAt -> {
long now = System.currentTimeMillis();
Expand All @@ -358,6 +357,16 @@ private RestHighLevelClient newClient() {
return lastLoggedAt;
}
});

if (restHighLevelClient != null) {
try {
restHighLevelClient.close();
LOG.debug("Closed RestHighLevelClient after failure");
} catch (IOException e) {
LOG.warn("Error closing RestHighLevelClient: {}", e.getMessage(), e);
}
}

return null;
}
}
Expand Down