[ 
https://issues.apache.org/jira/browse/HDDS-1501?focusedWorklogId=242896&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-242896
 ]

ASF GitHub Bot logged work on HDDS-1501:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/May/19 22:13
            Start Date: 15/May/19 22:13
    Worklog Time Spent: 10m 
      Work Description: swagle commented on pull request #819:  HDDS-1501 : 
Create a Recon task interface to update internal DB on updates from OM.
URL: https://github.com/apache/hadoop/pull/819#discussion_r284472229
 
 

 ##########
 File path: 
hadoop-ozone/ozone-recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OMDBUpdatesHandler.java
 ##########
 @@ -0,0 +1,216 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.recon.tasks;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.BUCKET_TABLE;
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.KEY_TABLE;
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.VOLUME_TABLE;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.utils.db.CodecRegistry;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.WriteBatch;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class used to listen on OM RocksDB updates.
+ */
+public class OMDBUpdatesHandler extends WriteBatch.Handler{
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OMDBUpdatesHandler.class);
+
+  private OMMetadataManager omMetadataManager;
+  private Map<Integer, String> tablesNames;
+  private CodecRegistry codecRegistry;
+  private List<OMDBUpdateEvent> omdbUpdateEvents = new ArrayList<>();
+
+  public OMDBUpdatesHandler(OMMetadataManager omMetadataManager) {
+    this.omMetadataManager = omMetadataManager;
+    tablesNames = omMetadataManager.getStore().getTableNames();
+    codecRegistry = omMetadataManager.getStore().getCodecRegistry();
+  }
+
+  @Override
+  public void put(int cfIndex, byte[] keyBytes, byte[] valueBytes) throws
+      RocksDBException {
+    try {
+      String tableName = tablesNames.get(cfIndex);
+      Class keyType = getKeyType(tableName);
+      Class valueType = getValueType(tableName);
+      if (valueType == null) {
+        return;
+      }
+      Object key = codecRegistry.asObject(keyBytes, keyType);
+      Object value = codecRegistry.asObject(valueBytes, valueType);
+      OMDBUpdateEvent.OMUpdateEventBuilder builder =
+          new OMDBUpdateEvent.OMUpdateEventBuilder<>();
+      builder.setTable(tableName);
+      builder.setKey(key);
+      builder.setValue(value);
+      builder.setAction(OMDBUpdateEvent.OMDBUpdateAction.PUT);
+      OMDBUpdateEvent putEvent = builder.build();
+      // Temporarily adding to an event buffer for testing. In subsequent 
JIRAs,
+      // a Recon side class will be implemented that requests delta updates
+      // from OM and calls on this handler. In that case, we will fill up
+      // this buffer and pass it on to the ReconTaskController which has
+      // tasks waiting on OM events.
+      omdbUpdateEvents.add(putEvent);
+      LOG.info("Generated OM update Event for table : " + putEvent.getTable()
+          + ", Key = " + putEvent.getKey());
+    } catch (IOException ioEx) {
+      LOG.error("Exception when reading key : " + ioEx);
+    }
+  }
+
+  @Override
+  public void delete(int cfIndex, byte[] keyBytes) throws RocksDBException {
+    try {
+      String tableName = tablesNames.get(cfIndex);
+      Class keyType = getKeyType(tableName);
+      Object key = codecRegistry.asObject(keyBytes, keyType);
+      OMDBUpdateEvent.OMUpdateEventBuilder builder =
+          new OMDBUpdateEvent.OMUpdateEventBuilder<>();
+      builder.setTable(tableName);
+      builder.setKey(key);
+      builder.setAction(OMDBUpdateEvent.OMDBUpdateAction.DELETE);
+      OMDBUpdateEvent deleteEvent = builder.build();
+      LOG.info("Generated OM delete Event for table : " + 
deleteEvent.getTable()
+          + ", Key = " + deleteEvent.getKey());
+      omdbUpdateEvents.add(deleteEvent);
+    } catch (IOException ioEx) {
+      LOG.error("Exception when reading key : " + ioEx);
+    }
+  }
+
+  // There are no use cases yet for the remaining methods in Recon. These
+  // will be implemented as and when need arises.
+
+  @Override
+  public void put(byte[] bytes, byte[] bytes1) {
+
+  }
+
+  @Override
+  public void merge(int i, byte[] bytes, byte[] bytes1)
+      throws RocksDBException {
+  }
+
+  @Override
+  public void merge(byte[] bytes, byte[] bytes1) {
+  }
+
+  @Override
+  public void delete(byte[] bytes) {
+  }
+
+  @Override
+  public void singleDelete(int i, byte[] bytes) throws RocksDBException {
+  }
+
+  @Override
+  public void singleDelete(byte[] bytes) {
+  }
+
+  @Override
+  public void deleteRange(int i, byte[] bytes, byte[] bytes1)
+      throws RocksDBException {
+  }
+
+  @Override
+  public void deleteRange(byte[] bytes, byte[] bytes1) {
+
+  }
+
+  @Override
+  public void logData(byte[] bytes) {
+
+  }
+
+  @Override
+  public void putBlobIndex(int i, byte[] bytes, byte[] bytes1)
+      throws RocksDBException {
+  }
+
+  @Override
+  public void markBeginPrepare() throws RocksDBException {
+
+  }
+
+  @Override
+  public void markEndPrepare(byte[] bytes) throws RocksDBException {
+
+  }
+
+  @Override
+  public void markNoop(boolean b) throws RocksDBException {
+
+  }
+
+  @Override
+  public void markRollback(byte[] bytes) throws RocksDBException {
+
+  }
+
+  @Override
+  public void markCommit(byte[] bytes) throws RocksDBException {
+
+  }
+
+  /**
+   * Return Key type class for a given table name.
+   * @param name table name.
+   * @return String.class by default.
+   */
+  private Class getKeyType(String name) {
+    return String.class;
+  }
+
+  /**
+   * Return Value type class for a given table.
+   * @param name table name
+   * @return Value type based on table name.
+   */
+  private Class getValueType(String name) {
 
 Review comment:
   Think of a unit test that would fail if OM schema changes.
 
----------------------------------------------------------------
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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 242896)
    Time Spent: 1.5h  (was: 1h 20m)

> Create a Recon task interface that is used to update the aggregate DB 
> whenever updates from OM are received.
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: HDDS-1501
>                 URL: https://issues.apache.org/jira/browse/HDDS-1501
>             Project: Hadoop Distributed Data Store
>          Issue Type: Sub-task
>          Components: Ozone Recon
>            Reporter: Aravindan Vijayan
>            Assignee: Aravindan Vijayan
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.5.0
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to