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:12:14 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_r284472028
 
 

 ##########
 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);
 
 Review comment:
   Looks like a repetitive code, a Builder pattern for EventInfo would be nice.

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