kevdoran commented on a change in pull request #4510:
URL: https://github.com/apache/nifi/pull/4510#discussion_r510242994



##########
File path: 
nifi-nar-bundles/nifi-hazelcast-bundle/nifi-hazelcast-services/src/main/resources/docs/org.apache.nifi.hazelcast.services.cachemanager.EmbeddedHazelcastCacheManager/additionalDetails.html
##########
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+      http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<head>
+    <meta charset="utf-8" />
+    <title>EmbeddedHazelcastCacheManager</title>
+    <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" 
type="text/css" />
+</head>
+
+<body>
+<h2>EmbeddedHazelcastCacheManager</h2>

Review comment:
       Excellent documentation!

##########
File path: 
nifi-nar-bundles/nifi-hazelcast-bundle/nifi-hazelcast-services/src/main/java/org/apache/nifi/hazelcast/services/cache/IMapBasedHazelcastCache.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.hazelcast.services.cache;
+
+import com.hazelcast.map.IMap;
+import com.hazelcast.map.ReachedMaxSizeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Predicate;
+
+/**
+ * Implementation of {@link HazelcastCache} backed by Hazelcast's IMap data 
structure. It's purpose is to wrap Hazelcast implementation specific details in 
order to
+ * make it possible to easily change version or data structure.
+ */
+public class IMapBasedHazelcastCache implements HazelcastCache {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(IMapBasedHazelcastCache.class);
+
+    private final long ttlInMillis;
+    private final IMap<String, byte[]> storage;
+
+    /**
+     * @param storage Reference to the actual storage. It should be the IMap 
with the same identifier as cache name.
+     * @param ttlInMillis The guaranteed lifetime of a cache entry in 
milliseconds.
+     */
+    public IMapBasedHazelcastCache(
+            final IMap<String, byte[]> storage,
+            final long ttlInMillis) {
+        this.ttlInMillis = ttlInMillis;
+        this.storage = storage;
+    }
+
+    @Override
+    public String name() {
+        return storage.getName();
+    }
+
+    @Override
+    public byte[] get(final String key) {
+        return storage.get(key);
+    }
+
+    @Override
+    public byte[] putIfAbsent(final String key, final byte[] value) {
+        return storage.putIfAbsent(key, value, ttlInMillis, 
TimeUnit.MILLISECONDS);
+    }
+
+    @Override
+    public boolean put(final String key, final byte[] value) {
+        try {
+            storage.put(key, value, ttlInMillis, TimeUnit.MILLISECONDS);
+            return true;
+        } catch (final ReachedMaxSizeException e) {
+            LOGGER.error("Cache {} reached the maximum allowed size!", 
storage.getName());
+            return false;
+        }

Review comment:
       If Hazelcast 4 is similar to 3 in this regard, then I believe there are 
some other runtime-exceptions that IMap datastructures can throw. One in 
particular is a SplitBrainProtectionException, which can occur on an external 
HZ cluster if nodes lose connectivity to each other, such as unwanted network 
partitioning. It might be worth adding handling for that, usually the solution 
would be a configurable number of retries as the same operation can succeed if 
called to a HZ instance that is part of the majority/quorum above the split 
brain protection threshold.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to