ijokarumawak commented on a change in pull request #3462: NIFI-6243 Add Support 
for AtomicDistributedCache to the HBase 1.x and…
URL: https://github.com/apache/nifi/pull/3462#discussion_r282356137
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/src/main/java/org/apache/nifi/hbase/HBase_1_1_2_ClientMapCacheService.java
 ##########
 @@ -229,6 +230,35 @@ public void close() throws IOException {
     protected void finalize() throws Throwable {
     }
 
+    @Override
+    public <K, V> AtomicCacheEntry<K, V, Long> fetch(K key, Serializer<K> 
keySerializer, Deserializer<V> valueDeserializer) throws IOException {
+        final byte[] rowIdBytes = serialize(key, keySerializer);
+        final HBaseRowHandler handler = new HBaseRowHandler();
+
+        final List<Column> columnsList = new ArrayList<>(1);
+        columnsList.add(new Column(hBaseColumnFamilyBytes, 
hBaseColumnQualifierBytes));
+
+        hBaseClientService.scan(hBaseCacheTableName, rowIdBytes, rowIdBytes, 
columnsList, authorizations, handler);
+
+        if (handler.numRows() > 1) {
+            throw new IOException("Found multiple rows in HBase for key");
+        } else if (handler.numRows() == 1) {
+            return new AtomicCacheEntry<>(key, 
deserialize(handler.getLastResultBytes(), valueDeserializer), 0L);
 
 Review comment:
   I think HBase 1.x fetch and replace should use `AtomicCacheEntry<K, V, 
byte[]>` instead of  `AtomicCacheEntry<K, V, Long>`.
   
   The expected use of `AtomicCacheEntity` is as follows:
   1. Application code uses `fetch` to get the latest AtomicCacheEntity, let's 
call it `e0`. `e0` has key `k0,` and value v0. The detail of revision depends 
on the target cache storage. If HBase 1.x only supports atomic replace using 
the original value, then AtomicCacheEntry for HBase 1.x should use 
`AtomicCacheEntry<K, V, byte[]>` so that it can hold the original byte[] value 
as a revision.
   2. The app code then update the cache value, `v0` to `v1`.
   3. Then the app code calls `replace` with `e0`. Now `e0` has key `k0`, value 
`v1` and revision `v0`.
   4. HBase checks if the stored value is still `v0`, if so, it puts `v1` as 
the latest cell value.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to