[HUDI-2285][HUDI-2476] Metadata table synchronous design. Rebased and Squashed from pull/3426 (#3590)
* [HUDI-2285] Adding Synchronous updates to metadata before completion of commits in data timelime. - This patch adds synchronous updates to metadata table. In other words, every write is first committed to metadata table followed by data table. While reading metadata table, we ignore any delta commits that are present only in metadata table and not in data table timeline. - Compaction of metadata table is fenced by the condition that we trigger compaction only when there are no inflight requests in datatable. This ensures that all base files in metadata table is always in sync with data table(w/o any holes) and only there could be some extra invalid commits among delta log files in metadata table. - Due to this, archival of data table also fences itself up until compacted instant in metadata table. All writes to metadata table happens within the datatable lock. So, metadata table works in one writer mode only. This might be tough to loosen since all writers write to same FILES partition and so, will result in a conflict anyways. - As part of this, have added acquiring locks in data table for those operations which were not before while committing (rollback, clean, compaction, cluster). To note, we were not doing any conflict resolution. All we are doing here is to commit by taking a lock. So that all writes to metadata table is always a single writer. - Also added building block to add buckets for partitions, which will be leveraged by other indexes like record level index, etc. For now, FILES partition has only one bucket. In general, any number of buckets per partition is allowed and each partition has a fixed fileId prefix with incremental suffix for each bucket within each partition. Have fixed [HUDI-2476]. This fix is about retrying a failed compaction if it succeeded in metadata for first time, but failed w/ data table. - Enabling metadata table by default. - Adding more tests for metadata table Co-authored-by: Prashant Wason <pwason@uber.com>
This commit is contained in:
committed by
GitHub
parent
46808dcb1f
commit
5f32162a2f
@@ -28,6 +28,7 @@ import org.apache.hudi.exception.HoodieIOException;
|
||||
import org.apache.hudi.exception.HoodieLockException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.hudi.common.config.LockConfiguration.FILESYSTEM_LOCK_PATH_PROP_KEY;
|
||||
@@ -39,12 +40,12 @@ import static org.apache.hudi.common.config.LockConfiguration.LOCK_ACQUIRE_RETRY
|
||||
* create operation. This lock does not support cleaning/expiring the lock after a failed write hence cannot be used
|
||||
* in production environments.
|
||||
*/
|
||||
public class FileSystemBasedLockProviderTestClass implements LockProvider<String> {
|
||||
public class FileSystemBasedLockProviderTestClass implements LockProvider<String>, Serializable {
|
||||
|
||||
private static final String LOCK_NAME = "acquired";
|
||||
|
||||
private String lockPath;
|
||||
private FileSystem fs;
|
||||
private transient FileSystem fs;
|
||||
protected LockConfiguration lockConfiguration;
|
||||
|
||||
public FileSystemBasedLockProviderTestClass(final LockConfiguration lockConfiguration, final Configuration configuration) {
|
||||
@@ -55,7 +56,7 @@ public class FileSystemBasedLockProviderTestClass implements LockProvider<String
|
||||
|
||||
public void acquireLock() {
|
||||
try {
|
||||
fs.create(new Path(lockPath + "/" + LOCK_NAME)).close();
|
||||
fs.create(new Path(lockPath + "/" + LOCK_NAME), false).close();
|
||||
} catch (IOException e) {
|
||||
throw new HoodieIOException("Failed to acquire lock", e);
|
||||
}
|
||||
@@ -78,7 +79,12 @@ public class FileSystemBasedLockProviderTestClass implements LockProvider<String
|
||||
&& (numRetries <= lockConfiguration.getConfig().getInteger(LOCK_ACQUIRE_NUM_RETRIES_PROP_KEY))) {
|
||||
Thread.sleep(lockConfiguration.getConfig().getInteger(LOCK_ACQUIRE_RETRY_WAIT_TIME_IN_MILLIS_PROP_KEY));
|
||||
}
|
||||
acquireLock();
|
||||
synchronized (LOCK_NAME) {
|
||||
if (fs.exists(new Path(lockPath + "/" + LOCK_NAME))) {
|
||||
return false;
|
||||
}
|
||||
acquireLock();
|
||||
}
|
||||
return true;
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new HoodieLockException("Failed to acquire lock", e);
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.common.testutils;
|
||||
|
||||
import org.apache.hudi.avro.model.HoodieCleanMetadata;
|
||||
import org.apache.hudi.avro.model.HoodieRequestedReplaceMetadata;
|
||||
import org.apache.hudi.avro.model.HoodieRestoreMetadata;
|
||||
import org.apache.hudi.avro.model.HoodieRollbackMetadata;
|
||||
import org.apache.hudi.common.model.HoodieCommitMetadata;
|
||||
import org.apache.hudi.common.model.HoodieReplaceCommitMetadata;
|
||||
import org.apache.hudi.common.model.WriteOperationType;
|
||||
import org.apache.hudi.common.table.HoodieTableMetaClient;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
import org.apache.hudi.metadata.HoodieTableMetadataWriter;
|
||||
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link HoodieTestTable} impl used for testing metadata. This class does synchronous updates to HoodieTableMetadataWriter if non null.
|
||||
*/
|
||||
public class HoodieMetadataTestTable extends HoodieTestTable {
|
||||
|
||||
private HoodieTableMetadataWriter writer;
|
||||
|
||||
protected HoodieMetadataTestTable(String basePath, FileSystem fs, HoodieTableMetaClient metaClient, HoodieTableMetadataWriter writer) {
|
||||
super(basePath, fs, metaClient);
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public static HoodieTestTable of(HoodieTableMetaClient metaClient) {
|
||||
return HoodieMetadataTestTable.of(metaClient, null);
|
||||
}
|
||||
|
||||
public static HoodieTestTable of(HoodieTableMetaClient metaClient, HoodieTableMetadataWriter writer) {
|
||||
testTableState = HoodieTestTableState.of();
|
||||
return new HoodieMetadataTestTable(metaClient.getBasePath(), metaClient.getRawFs(), metaClient, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieCommitMetadata doWriteOperation(String commitTime, WriteOperationType operationType,
|
||||
List<String> newPartitionsToAdd, List<String> partitions,
|
||||
int filesPerPartition, boolean bootstrap, boolean createInflightCommit) throws Exception {
|
||||
HoodieCommitMetadata commitMetadata = super.doWriteOperation(commitTime, operationType, newPartitionsToAdd, partitions, filesPerPartition, bootstrap, createInflightCommit);
|
||||
if (writer != null && !createInflightCommit) {
|
||||
writer.update(commitMetadata, commitTime);
|
||||
}
|
||||
return commitMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieTestTable moveInflightCommitToComplete(String instantTime, HoodieCommitMetadata metadata) throws IOException {
|
||||
super.moveInflightCommitToComplete(instantTime, metadata);
|
||||
if (writer != null) {
|
||||
writer.update(metadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public HoodieTestTable moveInflightCommitToComplete(String instantTime, HoodieCommitMetadata metadata, boolean ignoreWriter) throws IOException {
|
||||
super.moveInflightCommitToComplete(instantTime, metadata);
|
||||
if (!ignoreWriter && writer != null) {
|
||||
writer.update(metadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieTestTable moveInflightCompactionToComplete(String instantTime, HoodieCommitMetadata metadata) throws IOException {
|
||||
super.moveInflightCompactionToComplete(instantTime, metadata);
|
||||
if (writer != null) {
|
||||
writer.update(metadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieCleanMetadata doClean(String commitTime, Map<String, Integer> partitionFileCountsToDelete) throws IOException {
|
||||
HoodieCleanMetadata cleanMetadata = super.doClean(commitTime, partitionFileCountsToDelete);
|
||||
if (writer != null) {
|
||||
writer.update(cleanMetadata, commitTime);
|
||||
}
|
||||
return cleanMetadata;
|
||||
}
|
||||
|
||||
public HoodieTestTable addCompaction(String instantTime, HoodieCommitMetadata commitMetadata) throws Exception {
|
||||
super.addCompaction(instantTime, commitMetadata);
|
||||
if (writer != null) {
|
||||
writer.update(commitMetadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieTestTable addRollback(String instantTime, HoodieRollbackMetadata rollbackMetadata) throws IOException {
|
||||
super.addRollback(instantTime, rollbackMetadata);
|
||||
if (writer != null) {
|
||||
writer.update(rollbackMetadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieTestTable addRestore(String instantTime, HoodieRestoreMetadata restoreMetadata) throws IOException {
|
||||
super.addRestore(instantTime, restoreMetadata);
|
||||
if (writer != null) {
|
||||
writer.update(restoreMetadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieTestTable addReplaceCommit(
|
||||
String instantTime,
|
||||
Option<HoodieRequestedReplaceMetadata> requestedReplaceMetadata,
|
||||
Option<HoodieCommitMetadata> inflightReplaceMetadata,
|
||||
HoodieReplaceCommitMetadata completeReplaceMetadata) throws Exception {
|
||||
super.addReplaceCommit(instantTime, requestedReplaceMetadata, inflightReplaceMetadata, completeReplaceMetadata);
|
||||
if (writer != null) {
|
||||
writer.update(completeReplaceMetadata, instantTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user