bvaradar commented on code in PR #11923:
URL: https://github.com/apache/hudi/pull/11923#discussion_r1840835061


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/timeline/versioning/v1/TimelineArchiverV1.java:
##########
@@ -0,0 +1,444 @@
+/*
+ * 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.hudi.client.timeline.versioning.v1;
+
+import org.apache.hudi.avro.model.HoodieArchivedMetaEntry;
+import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
+import org.apache.hudi.client.transaction.TransactionManager;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.model.HoodieArchivedLogFile;
+import org.apache.hudi.common.model.HoodieAvroIndexedRecord;
+import org.apache.hudi.common.model.HoodieAvroPayload;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieLogFormat.Writer;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import 
org.apache.hudi.common.table.log.block.HoodieLogBlock.HeaderMetadataType;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.InstantFileNameFactory;
+import org.apache.hudi.common.table.timeline.MetadataConversionUtils;
+import org.apache.hudi.common.table.timeline.TimelineUtils;
+import org.apache.hudi.common.table.timeline.versioning.v1.ActiveTimelineV1;
+import org.apache.hudi.common.table.timeline.versioning.v1.ArchivedTimelineV1;
+import org.apache.hudi.common.table.timeline.versioning.v1.InstantComparatorV1;
+import 
org.apache.hudi.common.table.timeline.versioning.v1.InstantFileNameFactoryV1;
+import org.apache.hudi.common.util.ClusteringUtils;
+import org.apache.hudi.common.util.CollectionUtils;
+import org.apache.hudi.common.util.CompactionUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieCommitException;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.metadata.HoodieTableMetadata;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.action.compact.CompactionTriggerStrategy;
+import org.apache.hudi.table.marker.WriteMarkers;
+import org.apache.hudi.table.marker.WriteMarkersFactory;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.client.utils.ArchivalUtils.getMinAndMaxInstantsToKeep;
+import static 
org.apache.hudi.common.table.timeline.InstantComparatorUtils.GREATER_THAN;
+import static 
org.apache.hudi.common.table.timeline.InstantComparatorUtils.LESSER_THAN;
+import static 
org.apache.hudi.common.table.timeline.InstantComparatorUtils.LESSER_THAN_OR_EQUALS;
+import static 
org.apache.hudi.common.table.timeline.InstantComparatorUtils.compareTimestamps;
+
+/**
+ * Archiver to bound the growth of files under .hoodie meta path.
+ */
+public class TimelineArchiverV1<T extends HoodieAvroPayload, I, K, O> 
implements HoodieTimelineArchiver<T, I, K, O> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(TimelineArchiverV1.class);
+
+  private final StoragePath archiveFilePath;
+  private final HoodieWriteConfig config;
+  private Writer writer;
+  private final int maxInstantsToKeep;
+  private final int minInstantsToKeep;
+  private final HoodieTable<T, I, K, O> table;
+  private final HoodieTableMetaClient metaClient;
+  private final TransactionManager txnManager;
+
+  public TimelineArchiverV1(HoodieWriteConfig config, HoodieTable<T, I, K, O> 
table) {
+    this.config = config;
+    this.table = table;
+    this.metaClient = table.getMetaClient();
+    this.archiveFilePath = 
ArchivedTimelineV1.getArchiveLogPath(metaClient.getArchivePath());
+    this.txnManager = new TransactionManager(config, 
table.getMetaClient().getStorage());
+    Pair<Integer, Integer> minAndMaxInstants = 
getMinAndMaxInstantsToKeep(table, metaClient);
+    this.minInstantsToKeep = minAndMaxInstants.getLeft();
+    this.maxInstantsToKeep = minAndMaxInstants.getRight();
+  }
+
+  private Writer openWriter() {
+    try {
+      if (this.writer == null) {
+        return 
HoodieLogFormat.newWriterBuilder().onParentPath(archiveFilePath.getParent())
+            
.withFileId(archiveFilePath.getName()).withFileExtension(HoodieArchivedLogFile.ARCHIVE_EXTENSION)
+            .withStorage(metaClient.getStorage()).build();
+      } else {
+        return this.writer;
+      }
+    } catch (IOException e) {
+      throw new HoodieException("Unable to initialize HoodieLogFormat writer", 
e);
+    }
+  }
+
+  public Writer reOpenWriter() {
+    try {
+      if (this.writer != null) {
+        this.writer.close();
+        this.writer = null;
+      }
+      this.writer = openWriter();
+      return writer;
+    } catch (IOException e) {
+      throw new HoodieException("Unable to initialize HoodieLogFormat writer", 
e);
+    }
+  }
+
+  private void close() {
+    try {
+      if (this.writer != null) {
+        this.writer.close();
+      }
+    } catch (IOException e) {
+      throw new HoodieException("Unable to close HoodieLogFormat writer", e);
+    }
+  }
+
+  @Override
+  public int archiveIfRequired(HoodieEngineContext context, boolean 
acquireLock) throws IOException {
+    //NOTE:  We permanently disable merging archive files. This is different 
from 0.15 behavior.

Review Comment:
   This is bring cascading changes in 
https://github.com/apache/hudi/commit/1accbe7052a9bca5f2158b5e697e1c91e70182e2 .



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to