in hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/DBCheckpointServlet.java [151:277]
private void generateSnapshotCheckpoint(HttpServletRequest request,
HttpServletResponse response, boolean isFormData) {
if (dbStore == null) {
LOG.error(
"Unable to process metadata snapshot request. DB Store is null");
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// Check ACL for dbCheckpoint only when global Ozone ACL is enabled
if (aclEnabled) {
final java.security.Principal userPrincipal = request.getUserPrincipal();
if (userPrincipal == null) {
final String remoteUser = request.getRemoteUser();
LOG.error("Permission denied: Unauthorized access to /dbCheckpoint,"
+ " no user principal found. Current login user is {}.",
remoteUser != null ? "'" + remoteUser + "'" : "UNKNOWN");
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
} else {
final String userPrincipalName = userPrincipal.getName();
UserGroupInformation ugi =
UserGroupInformation.createRemoteUser(userPrincipalName);
if (!hasPermission(ugi)) {
LOG.error("Permission denied: User principal '{}' does not have"
+ " access to /dbCheckpoint.\nThis can happen when Ozone"
+ " Manager is started with a different user.\n"
+ " Please append '{}' to OM 'ozone.administrators'"
+ " config and restart OM to grant current"
+ " user access to this endpoint.",
userPrincipalName, userPrincipalName);
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
LOG.debug("Granted user principal '{}' access to /dbCheckpoint.",
userPrincipalName);
}
}
DBCheckpoint checkpoint = null;
boolean flush = false;
String flushParam =
request.getParameter(OZONE_DB_CHECKPOINT_REQUEST_FLUSH);
if (StringUtils.isNotEmpty(flushParam)) {
flush = Boolean.parseBoolean(flushParam);
}
List<String> receivedSstList = new ArrayList<>();
List<String> excludedSstList = new ArrayList<>();
String[] sstParam = isFormData ?
parseFormDataParameters(request) : request.getParameterValues(
OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST);
if (sstParam != null) {
receivedSstList.addAll(
Arrays.stream(sstParam)
.filter(s -> s.endsWith(ROCKSDB_SST_SUFFIX))
.distinct()
.collect(Collectors.toList()));
logSstFileList(receivedSstList,
"Received list of {} SST files to be excluded{}: {}", 5);
}
Path tmpdir = null;
try (BootstrapStateHandler.Lock lock = getBootstrapStateLock().lock()) {
tmpdir = Files.createTempDirectory(bootstrapTempData.toPath(),
"bootstrap-data-");
checkpoint = getCheckpoint(tmpdir, flush);
if (checkpoint == null || checkpoint.getCheckpointLocation() == null) {
LOG.error("Unable to process metadata snapshot request. " +
"Checkpoint request returned null.");
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
dbMetrics.setLastCheckpointCreationTimeTaken(
checkpoint.checkpointCreationTimeTaken());
Path file = checkpoint.getCheckpointLocation().getFileName();
if (file == null) {
return;
}
response.setContentType("application/x-tar");
response.setHeader("Content-Disposition",
"attachment; filename=\"" +
file + ".tar\"");
Instant start = Instant.now();
writeDbDataToStream(checkpoint, request,
response.getOutputStream(), receivedSstList, excludedSstList, tmpdir);
Instant end = Instant.now();
long duration = Duration.between(start, end).toMillis();
LOG.info("Time taken to write the checkpoint to response output " +
"stream: {} milliseconds", duration);
logSstFileList(excludedSstList,
"Excluded {} SST files from the latest checkpoint{}: {}", 5);
if (!excludedSstList.isEmpty()) {
dbMetrics.incNumIncrementalCheckpoint();
}
dbMetrics.setLastCheckpointStreamingNumSSTExcluded(
excludedSstList.size());
dbMetrics.setLastCheckpointStreamingTimeTaken(duration);
dbMetrics.incNumCheckpoints();
} catch (Exception e) {
LOG.error(
"Unable to process metadata snapshot request. ", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
dbMetrics.incNumCheckpointFails();
} finally {
try {
if (tmpdir != null) {
FileUtils.deleteDirectory(tmpdir.toFile());
}
} catch (IOException e) {
LOG.error("unable to delete: " + tmpdir);
}
if (checkpoint != null) {
try {
checkpoint.cleanupCheckpoint();
} catch (IOException e) {
LOG.error("Error trying to clean checkpoint at {} .",
checkpoint.getCheckpointLocation().toString());
}
}
}
}