You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/04/13 16:39:40 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #913: Add v2 manifests (WIP)

rdblue commented on a change in pull request #913: Add v2 manifests (WIP)
URL: https://github.com/apache/incubator-iceberg/pull/913#discussion_r407577108
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/GenericManifestEntry.java
 ##########
 @@ -0,0 +1,179 @@
+/*
+ * 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.iceberg;
+
+import com.google.common.base.MoreObjects;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.avro.specific.SpecificData;
+import org.apache.iceberg.avro.AvroSchemaUtil;
+import org.apache.iceberg.types.Types;
+
+class GenericManifestEntry implements ManifestEntry, IndexedRecord, SpecificData.SchemaConstructable {
+  private final org.apache.avro.Schema schema;
+  private final V1Metadata.IndexedDataFile fileWrapper;
+  private Status status = Status.EXISTING;
+  private Long snapshotId = null;
+  private Long sequenceNumber = null;
+  private DataFile file = null;
+
+  GenericManifestEntry(org.apache.avro.Schema schema) {
+    this.schema = schema;
+    this.fileWrapper = null; // do not use the file wrapper to read
+  }
+
+  GenericManifestEntry(Types.StructType partitionType) {
+    this.schema = AvroSchemaUtil.convert(V1Metadata.entrySchema(partitionType), "manifest_entry");
+    this.fileWrapper = new V1Metadata.IndexedDataFile(schema.getField("data_file").schema());
+  }
+
+  private GenericManifestEntry(GenericManifestEntry toCopy, boolean fullCopy) {
+    this.schema = toCopy.schema;
+    this.fileWrapper = new V1Metadata.IndexedDataFile(schema.getField("data_file").schema());
+    this.status = toCopy.status;
+    this.snapshotId = toCopy.snapshotId;
+    if (fullCopy) {
+      this.file = toCopy.file().copy();
+    } else {
+      this.file = toCopy.file().copyWithoutStats();
+    }
+  }
+
+  ManifestEntry wrapExisting(Long newSnapshotId, Long newSequenceNumber, DataFile newFile) {
+    this.status = Status.EXISTING;
+    this.snapshotId = newSnapshotId;
+    this.sequenceNumber = newSequenceNumber;
+    this.file = newFile;
+    return this;
+  }
+
+  ManifestEntry wrapAppend(Long newSnapshotId, DataFile newFile) {
+    this.status = Status.ADDED;
+    this.snapshotId = newSnapshotId;
+    this.sequenceNumber = null;
 
 Review comment:
   When a file is appended, it must have the sequence number of the snapshot where it is committed. The problem is that the sequence number isn't determined until the snapshot's commit is successful. Two committers may be racing to add a commit with the same sequence number.
   
   That's why sequence numbers are assigned initially through inheritance. Every snapshot commit attempt writes a new root manifest list with a new sequence number based on the table metadata's last sequence number. If two writers are trying to commit different snapshots as sequence number 5, one will win and the other will retry with 6. To avoid rewriting the metadata tree below the manifest list, sequence numbers that might change are inherited instead of written into the initial files.

----------------------------------------------------------------
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: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org