hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [hadoop] swagle commented on a change in pull request #819: HDDS-1501 : Create a Recon task interface to update internal DB on updates from OM.
Date Wed, 15 May 2019 22:13:08 GMT
swagle commented on a change in 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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org


Mime
View raw message