[HUDI-3772] Fixing auto adjustment of lock configs for deltastreamer (#5207)
This commit is contained in:
committed by
GitHub
parent
cc3737be50
commit
84064a9b08
@@ -480,6 +480,12 @@ public class HoodieWriteConfig extends HoodieConfig {
|
||||
.sinceVersion("0.11.0")
|
||||
.withDocumentation("Control to enable release all persist rdds when the spark job finish.");
|
||||
|
||||
public static final ConfigProperty<Boolean> AUTO_ADJUST_LOCK_CONFIGS = ConfigProperty
|
||||
.key("hoodie.auto.adjust.lock.configs")
|
||||
.defaultValue(false)
|
||||
.sinceVersion("0.11.0")
|
||||
.withDocumentation("Auto adjust lock configurations when metadata table is enabled and for async table services.");
|
||||
|
||||
private ConsistencyGuardConfig consistencyGuardConfig;
|
||||
private FileSystemRetryConfig fileSystemRetryConfig;
|
||||
|
||||
@@ -1968,6 +1974,9 @@ public class HoodieWriteConfig extends HoodieConfig {
|
||||
* Hoodie Client Lock Configs.
|
||||
* @return
|
||||
*/
|
||||
public boolean isAutoAdjustLockConfigs() {
|
||||
return getBooleanOrDefault(AUTO_ADJUST_LOCK_CONFIGS);
|
||||
}
|
||||
|
||||
public String getLockProviderClass() {
|
||||
return getString(HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME);
|
||||
@@ -2443,6 +2452,11 @@ public class HoodieWriteConfig extends HoodieConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withAutoAdjustLockConfigs(boolean autoAdjustLockConfigs) {
|
||||
writeConfig.setValue(AUTO_ADJUST_LOCK_CONFIGS, String.valueOf(autoAdjustLockConfigs));
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void setDefaults() {
|
||||
writeConfig.setDefaultValue(MARKERS_TYPE, getDefaultMarkersType(engineType));
|
||||
// Check for mandatory properties
|
||||
@@ -2480,41 +2494,42 @@ public class HoodieWriteConfig extends HoodieConfig {
|
||||
HoodieLayoutConfig.newBuilder().fromProperties(writeConfig.getProps()).build());
|
||||
writeConfig.setDefaultValue(TIMELINE_LAYOUT_VERSION_NUM, String.valueOf(TimelineLayoutVersion.CURR_VERSION));
|
||||
|
||||
autoAdjustConfigsForConcurrencyMode();
|
||||
}
|
||||
|
||||
private void autoAdjustConfigsForConcurrencyMode() {
|
||||
boolean isMetadataTableEnabled = writeConfig.getBoolean(HoodieMetadataConfig.ENABLE);
|
||||
// isLockProviderPropertySet must be fetched before setting defaults of HoodieLockConfig
|
||||
final TypedProperties writeConfigProperties = writeConfig.getProps();
|
||||
final boolean isLockProviderPropertySet = writeConfigProperties.containsKey(HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME)
|
||||
|| writeConfigProperties.containsKey(HoodieLockConfig.LOCK_PROVIDER_CLASS_PROP);
|
||||
|
||||
if (!isLockConfigSet) {
|
||||
HoodieLockConfig.Builder lockConfigBuilder = HoodieLockConfig.newBuilder().fromProperties(writeConfig.getProps());
|
||||
writeConfig.setDefault(lockConfigBuilder.build());
|
||||
}
|
||||
writeConfig.setDefaultOnCondition(!isLockConfigSet,
|
||||
HoodieLockConfig.newBuilder().fromProperties(writeConfig.getProps()).build());
|
||||
|
||||
if (isMetadataTableEnabled) {
|
||||
// When metadata table is enabled, optimistic concurrency control must be used for
|
||||
// single writer with async table services.
|
||||
// Async table services can update the metadata table and a lock provider is
|
||||
// needed to guard against any concurrent table write operations. If user has
|
||||
// not configured any lock provider, let's use the InProcess lock provider.
|
||||
boolean areTableServicesEnabled = writeConfig.areTableServicesEnabled();
|
||||
boolean areAsyncTableServicesEnabled = writeConfig.areAnyTableServicesAsync();
|
||||
autoAdjustConfigsForConcurrencyMode(isLockProviderPropertySet);
|
||||
}
|
||||
|
||||
if (!isLockProviderPropertySet && areTableServicesEnabled && areAsyncTableServicesEnabled) {
|
||||
// This is targeted at Single writer with async table services
|
||||
// If user does not set the lock provider, likely that the concurrency mode is not set either
|
||||
// Override the configs for metadata table
|
||||
writeConfig.setValue(WRITE_CONCURRENCY_MODE.key(),
|
||||
WriteConcurrencyMode.OPTIMISTIC_CONCURRENCY_CONTROL.value());
|
||||
writeConfig.setValue(HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME.key(),
|
||||
InProcessLockProvider.class.getName());
|
||||
LOG.info(String.format("Automatically set %s=%s and %s=%s since user has not set the "
|
||||
+ "lock provider for single writer with async table services",
|
||||
WRITE_CONCURRENCY_MODE.key(), WriteConcurrencyMode.OPTIMISTIC_CONCURRENCY_CONTROL.value(),
|
||||
HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME.key(), InProcessLockProvider.class.getName()));
|
||||
private void autoAdjustConfigsForConcurrencyMode(boolean isLockProviderPropertySet) {
|
||||
if (writeConfig.isAutoAdjustLockConfigs()) {
|
||||
// auto adjustment is required only for deltastreamer and spark streaming where async table services can be executed in the same JVM.
|
||||
boolean isMetadataTableEnabled = writeConfig.getBoolean(HoodieMetadataConfig.ENABLE);
|
||||
|
||||
if (isMetadataTableEnabled) {
|
||||
// When metadata table is enabled, optimistic concurrency control must be used for
|
||||
// single writer with async table services.
|
||||
// Async table services can update the metadata table and a lock provider is
|
||||
// needed to guard against any concurrent table write operations. If user has
|
||||
// not configured any lock provider, let's use the InProcess lock provider.
|
||||
boolean areTableServicesEnabled = writeConfig.areTableServicesEnabled();
|
||||
boolean areAsyncTableServicesEnabled = writeConfig.areAnyTableServicesAsync();
|
||||
if (!isLockProviderPropertySet && areTableServicesEnabled && areAsyncTableServicesEnabled) {
|
||||
// This is targeted at Single writer with async table services
|
||||
// If user does not set the lock provider, likely that the concurrency mode is not set either
|
||||
// Override the configs for metadata table
|
||||
writeConfig.setValue(WRITE_CONCURRENCY_MODE.key(),
|
||||
WriteConcurrencyMode.OPTIMISTIC_CONCURRENCY_CONTROL.value());
|
||||
writeConfig.setValue(HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME.key(),
|
||||
InProcessLockProvider.class.getName());
|
||||
LOG.info(String.format("Automatically set %s=%s and %s=%s since user has not set the "
|
||||
+ "lock provider for single writer with async table services",
|
||||
WRITE_CONCURRENCY_MODE.key(), WriteConcurrencyMode.OPTIMISTIC_CONCURRENCY_CONTROL.value(),
|
||||
HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME.key(), InProcessLockProvider.class.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user