use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class BookieWatcher method replaceBookie.
/**
* Choose a bookie to replace bookie <i>bookieIdx</i> in <i>existingBookies</i>.
* @param existingBookies
* list of existing bookies.
* @param bookieIdx
* index of the bookie in the list to be replaced.
* @return the bookie to replace.
* @throws BKNotEnoughBookiesException
*/
public BookieSocketAddress replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, List<BookieSocketAddress> existingBookies, int bookieIdx, Set<BookieSocketAddress> excludeBookies) throws BKNotEnoughBookiesException {
long startTime = MathUtils.nowInNano();
BookieSocketAddress addr = existingBookies.get(bookieIdx);
BookieSocketAddress socketAddress;
try {
// we exclude the quarantined bookies also first
Set<BookieSocketAddress> existingAndQuarantinedBookies = new HashSet<BookieSocketAddress>(existingBookies);
existingAndQuarantinedBookies.addAll(quarantinedBookies.asMap().keySet());
socketAddress = placementPolicy.replaceBookie(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, existingAndQuarantinedBookies, addr, excludeBookies);
replaceBookieTimer.registerSuccessfulEvent(MathUtils.nowInNano() - startTime, TimeUnit.NANOSECONDS);
} catch (BKNotEnoughBookiesException e) {
if (log.isDebugEnabled()) {
log.debug("Not enough healthy bookies available, using quarantined bookies");
}
socketAddress = placementPolicy.replaceBookie(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, new HashSet<BookieSocketAddress>(existingBookies), addr, excludeBookies);
replaceBookieTimer.registerFailedEvent(MathUtils.nowInNano() - startTime, TimeUnit.NANOSECONDS);
}
return socketAddress;
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class Cookie method writeToRegistrationManager.
/**
* Writes cookie details to registration manager.
*
* @param rm registration manager
* @param conf configuration
* @param version version
* @throws BookieException when fail to write the cookie.
*/
public void writeToRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version) throws BookieException {
BookieSocketAddress address = null;
try {
address = Bookie.getBookieAddress(conf);
} catch (UnknownHostException e) {
throw new UnknownBookieIdException(e);
}
byte[] data = toString().getBytes(UTF_8);
rm.writeCookie(address.toString(), new Versioned<>(data, version));
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class Cookie method deleteFromRegistrationManager.
/**
* Deletes cookie from registration manager.
*
* @param rm registration manager
* @param conf configuration
* @param version cookie version
* @throws BookieException when fail to delete cookie.
*/
public void deleteFromRegistrationManager(RegistrationManager rm, ServerConfiguration conf, Version version) throws BookieException {
BookieSocketAddress address = null;
try {
address = Bookie.getBookieAddress(conf);
} catch (UnknownHostException e) {
throw new UnknownBookieIdException(e);
}
deleteFromRegistrationManager(rm, address, version);
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class RecoveryBookieService method handle.
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
HttpServiceResponse response = new HttpServiceResponse();
String requestBody = request.getBody();
RecoveryRequestJsonBody requestJsonBody;
if (requestBody == null) {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("No request body provide.");
return response;
}
try {
requestJsonBody = JsonUtil.fromJson(requestBody, RecoveryRequestJsonBody.class);
LOG.debug("bookie_src: [" + requestJsonBody.bookieSrc.get(0) + "], delete_cookie: [" + requestJsonBody.deleteCookie + "]");
} catch (JsonUtil.ParseJsonException e) {
LOG.error("Meet Exception: ", e);
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("ERROR parameters: " + e.getMessage());
return response;
}
if (HttpServer.Method.PUT == request.getMethod() && !requestJsonBody.bookieSrc.isEmpty()) {
runFunctionWithRegistrationManager(conf, rm -> {
String[] bookieSrcString = requestJsonBody.bookieSrc.get(0).split(":");
BookieSocketAddress bookieSrc = new BookieSocketAddress(bookieSrcString[0], Integer.parseInt(bookieSrcString[1]));
boolean deleteCookie = requestJsonBody.deleteCookie;
executor.execute(() -> {
try {
LOG.info("Start recovering bookie.");
bka.recoverBookieData(bookieSrc);
if (deleteCookie) {
Versioned<Cookie> cookie = Cookie.readFromRegistrationManager(rm, bookieSrc);
cookie.getValue().deleteFromRegistrationManager(rm, bookieSrc, cookie.getVersion());
}
LOG.info("Complete recovering bookie");
} catch (Exception e) {
LOG.error("Exception occurred while recovering bookie", e);
}
});
return null;
});
response.setCode(HttpServer.StatusCode.OK);
response.setBody("Success send recovery request command.");
return response;
} else {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Not found method. Should be PUT method");
return response;
}
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class WhoIsAuditorService method handle.
/*
* Print the node which holds the auditor lock.
*/
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
HttpServiceResponse response = new HttpServiceResponse();
if (HttpServer.Method.GET == request.getMethod()) {
BookieSocketAddress bookieId = null;
try {
bookieId = AuditorElector.getCurrentAuditor(conf, zk);
if (bookieId == null) {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("No auditor elected");
return response;
}
} catch (Exception e) {
LOG.error("Meet Exception: ", e);
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Exception when get." + e.getMessage());
return response;
}
response.setCode(HttpServer.StatusCode.OK);
response.setBody("Auditor: " + bookieId.getSocketAddress().getAddress().getCanonicalHostName() + "/" + bookieId.getSocketAddress().getAddress().getHostAddress() + ":" + bookieId.getSocketAddress().getPort());
LOG.debug("response body:" + response.getBody());
return response;
} else {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Not found method. Should be GET method");
return response;
}
}
Aggregations