aryangupta1998 commented on code in PR #8081:
URL: https://github.com/apache/ozone/pull/8081#discussion_r2001316943
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -644,6 +655,7 @@ private OzoneManager(OzoneConfiguration conf, StartupOption
startupOption)
kmsProvider = null;
LOG.error("Fail to create Key Provider");
}
+ initializeEdekCache(conf);
Review Comment:
Done.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -727,6 +739,110 @@ private OzoneManager(OzoneConfiguration conf,
StartupOption startupOption)
omHostName = HddsUtils.getHostName(conf);
}
+ private void initializeEdekCache(OzoneConfiguration conf) {
+ int edekCacheLoaderDelay =
+ conf.getInt(OZONE_OM_EDEKCACHELOADER_INITIAL_DELAY_MS_KEY,
OZONE_OM_EDEKCACHELOADER_INITIAL_DELAY_MS_DEFAULT);
+ int edekCacheLoaderInterval =
+ conf.getInt(OZONE_OM_EDEKCACHELOADER_INTERVAL_MS_KEY,
OZONE_OM_EDEKCACHELOADER_INTERVAL_MS_DEFAULT);
+ int edekCacheLoaderMaxRetries =
+ conf.getInt(OZONE_OM_EDEKCACHELOADER_MAX_RETRIES_KEY,
OZONE_OM_EDEKCACHELOADER_MAX_RETRIES_DEFAULT);
+ if (kmsProvider != null) {
+ edekCacheLoader = Executors.newSingleThreadExecutor(
+ new ThreadFactoryBuilder().setDaemon(true)
+ .setNameFormat("Warm Up EDEK Cache Thread #%d")
+ .build());
+ warmUpEdekCache(edekCacheLoader, edekCacheLoaderDelay,
edekCacheLoaderInterval, edekCacheLoaderMaxRetries);
+ }
+ }
+
+ static class EDEKCacheLoader implements Runnable {
+ private final String[] keyNames;
+ private final KeyProviderCryptoExtension kp;
+ private int initialDelay;
+ private int retryInterval;
+ private int maxRetries;
+
+ EDEKCacheLoader(final String[] names, final KeyProviderCryptoExtension kp,
+ final int delay, final int interval, final int maxRetries) {
+ this.keyNames = names;
+ this.kp = kp;
+ this.initialDelay = delay;
+ this.retryInterval = interval;
+ this.maxRetries = maxRetries;
+ }
+
+ @Override
+ public void run() {
+ LOG.info("Warming up {} EDEKs... (initialDelay={}, "
+ + "retryInterval={}, maxRetries={})", keyNames.length,
initialDelay, retryInterval,
+ maxRetries);
+ try {
+ Thread.sleep(initialDelay);
+ } catch (InterruptedException ie) {
+ LOG.info("EDEKCacheLoader interrupted before warming up.");
+ return;
+ }
+
+ boolean success = false;
+ int retryCount = 0;
+ IOException lastSeenIOE = null;
+ long warmUpEDEKStartTime = monotonicNow();
+
+ while (!success && retryCount < maxRetries) {
+ try {
+ kp.warmUpEncryptedKeys(keyNames);
+ LOG.info("Successfully warmed up {} EDEKs.", keyNames.length);
+ success = true;
+ } catch (IOException ioe) {
+ lastSeenIOE = ioe;
+ LOG.info("Failed to warm up EDEKs.", ioe);
+ } catch (Exception e) {
+ LOG.error("Cannot warm up EDEKs.", e);
+ throw e;
+ }
+
+ if (!success) {
+ try {
+ Thread.sleep(retryInterval);
+ } catch (InterruptedException ie) {
+ LOG.info("EDEKCacheLoader interrupted during retry.");
+ break;
+ }
+ retryCount++;
+ }
+ }
+
+ long warmUpEDEKTime = monotonicNow() - warmUpEDEKStartTime;
+ LOG.debug("Time taken to load EDEK keys to the cache: {}",
warmUpEDEKTime);
+ if (!success) {
+ LOG.warn("Max retry {} reached, unable to warm up EDEKs.", maxRetries);
+ if (lastSeenIOE != null) {
+ LOG.warn("Last seen exception:", lastSeenIOE);
+ }
+ }
+ }
+ }
+
+ public void warmUpEdekCache(final ExecutorService executor, final int delay,
final int interval, int maxRetries) {
+ List<String> keys = new ArrayList<>();
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]