Skip to content

Commit

Permalink
[MINOR] Clean code of FileSystemViewManager (#10797)
Browse files Browse the repository at this point in the history
Co-authored-by: wuzhiping <wuzhiping.007@bytedance.com>
  • Loading branch information
2 people authored and yihua committed May 14, 2024
1 parent e2e7c96 commit 39135e7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@
* @param <O> Type of outputs
*/
public abstract class HoodieTable<T, I, K, O> implements Serializable {

private static final Logger LOG = LoggerFactory.getLogger(HoodieTable.class);

protected final HoodieWriteConfig config;
protected final HoodieTableMetaClient metaClient;
protected final HoodieIndex<?, ?> index;
private SerializableConfiguration hadoopConfiguration;
private final SerializableConfiguration hadoopConfiguration;
protected final TaskContextSupplier taskContextSupplier;
private final HoodieTableMetadata metadata;
private final HoodieStorageLayout storageLayout;
Expand All @@ -145,7 +144,7 @@ protected HoodieTable(HoodieWriteConfig config, HoodieEngineContext context, Hoo
.build();
this.metadata = HoodieTableMetadata.create(context, metadataConfig, config.getBasePath());

this.viewManager = FileSystemViewManager.createViewManager(context, config.getMetadataConfig(), config.getViewStorageConfig(), config.getCommonConfig(), unused -> metadata);
this.viewManager = getViewManager();
this.metaClient = metaClient;
this.index = getIndex(config, context);
this.storageLayout = getStorageLayout(config);
Expand All @@ -164,7 +163,7 @@ protected HoodieStorageLayout getStorageLayout(HoodieWriteConfig config) {

private synchronized FileSystemViewManager getViewManager() {
if (null == viewManager) {
viewManager = FileSystemViewManager.createViewManager(getContext(), config.getMetadataConfig(), config.getViewStorageConfig(), config.getCommonConfig(), unused -> metadata);
viewManager = FileSystemViewManager.createViewManager(getContext(), config.getViewStorageConfig(), config.getCommonConfig(), unused -> metadata);
}
return viewManager;
}
Expand All @@ -180,8 +179,7 @@ public HoodieTableMetadata getMetadata() {
* @param records hoodieRecords to upsert
* @return HoodieWriteMetadata
*/
public abstract HoodieWriteMetadata<O> upsert(HoodieEngineContext context, String instantTime,
I records);
public abstract HoodieWriteMetadata<O> upsert(HoodieEngineContext context, String instantTime, I records);

/**
* Insert a batch of new records into Hoodie table at the supplied instantTime.
Expand All @@ -190,8 +188,7 @@ public abstract HoodieWriteMetadata<O> upsert(HoodieEngineContext context, Strin
* @param records hoodieRecords to upsert
* @return HoodieWriteMetadata
*/
public abstract HoodieWriteMetadata<O> insert(HoodieEngineContext context, String instantTime,
I records);
public abstract HoodieWriteMetadata<O> insert(HoodieEngineContext context, String instantTime, I records);

/**
* Bulk Insert a batch of new records into Hoodie table at the supplied instantTime.
Expand Down Expand Up @@ -270,7 +267,7 @@ public abstract HoodieWriteMetadata<O> insertPrepped(HoodieEngineContext context
* @return HoodieWriteMetadata
*/
public abstract HoodieWriteMetadata<O> bulkInsertPrepped(HoodieEngineContext context, String instantTime,
I preppedRecords, Option<BulkInsertPartitioner> bulkInsertPartitioner);
I preppedRecords, Option<BulkInsertPartitioner> bulkInsertPartitioner);

/**
* Replaces all the existing records and inserts the specified new records into Hoodie table at the supplied instantTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void initTimelineService() {
.serverPort(config.getViewStorageConfig().getRemoteViewServerPort()).build(),
FileSystem.get(new Configuration()),
FileSystemViewManager.createViewManager(
context, config.getMetadataConfig(), config.getViewStorageConfig(),
context, config.getViewStorageConfig(),
config.getCommonConfig(),
metaClient -> new HoodieBackedTestDelayedTableMetadata(
context, config.getMetadataConfig(), metaClient.getBasePathV2().toString(), true)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.hudi.client.common.HoodieSparkEngineContext;
import org.apache.hudi.common.config.HoodieCommonConfig;
import org.apache.hudi.common.config.HoodieMetadataConfig;
import org.apache.hudi.common.engine.HoodieLocalEngineContext;
import org.apache.hudi.common.table.marker.MarkerType;
import org.apache.hudi.common.table.view.FileSystemViewManager;
Expand Down Expand Up @@ -66,15 +65,13 @@ public void setup() throws IOException {

FileSystemViewStorageConfig storageConf =
FileSystemViewStorageConfig.newBuilder().withStorageType(FileSystemViewStorageType.SPILLABLE_DISK).build();
HoodieMetadataConfig metadataConfig = HoodieMetadataConfig.newBuilder().build();
HoodieLocalEngineContext localEngineContext = new HoodieLocalEngineContext(metaClient.getHadoopConf());

try {
timelineService = new TimelineService(localEngineContext, new Configuration(),
TimelineService.Config.builder().serverPort(0).enableMarkerRequests(true).build(),
FileSystem.get(new Configuration()),
FileSystemViewManager.createViewManager(
localEngineContext, metadataConfig, storageConf, HoodieCommonConfig.newBuilder().build()));
FileSystemViewManager.createViewManager(localEngineContext, storageConf, HoodieCommonConfig.newBuilder().build()));
timelineService.startService();
} catch (Exception ex) {
throw new RuntimeException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ public static TimelineService initTimelineService(
TimelineService.Config.builder().enableMarkerRequests(true)
.serverPort(config.getViewStorageConfig().getRemoteViewServerPort()).build(),
FileSystem.get(new Configuration()),
FileSystemViewManager.createViewManager(context, config.getMetadataConfig(),
config.getViewStorageConfig(), config.getCommonConfig()));
FileSystemViewManager.createViewManager(context, config.getViewStorageConfig(), config.getCommonConfig()));
timelineService.startService();
LOG.info("Timeline service server port: " + timelineServicePort);
return timelineService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public static HoodieTableMetaClient initTableAndGetMetaClient(Configuration hado
fs.mkdirs(auxiliaryFolder);
}

initializeBootstrapDirsIfNotExists(hadoopConf, basePath, fs);
initializeBootstrapDirsIfNotExists(basePath, fs);
HoodieTableConfig.create(fs, metaPathDir, props);
// We should not use fs.getConf as this might be different from the original configuration
// used to create the fs in unit tests
Expand All @@ -523,7 +523,7 @@ public static HoodieTableMetaClient initTableAndGetMetaClient(Configuration hado
return metaClient;
}

public static void initializeBootstrapDirsIfNotExists(Configuration hadoopConf, String basePath, FileSystem fs) throws IOException {
public static void initializeBootstrapDirsIfNotExists(String basePath, FileSystem fs) throws IOException {

// Create bootstrap index by partition folder if it does not exist
final Path bootstrap_index_folder_by_partition =
Expand Down Expand Up @@ -684,7 +684,7 @@ public String toString() {
}

public void initializeBootstrapDirsIfNotExists() throws IOException {
initializeBootstrapDirsIfNotExists(getHadoopConf(), basePath.toString(), getFs());
initializeBootstrapDirsIfNotExists(basePath.toString(), getFs());
}

private static HoodieTableMetaClient newMetaClient(Configuration conf, String basePath, boolean loadActiveTimelineOnLoad,
Expand Down
Loading

0 comments on commit 39135e7

Please sign in to comment.