Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HiveMetastoreDecorator and simplify metastore creation #19814

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.trino.plugin.deltalake.metastore.glue.DeltaLakeGlueMetastoreModule;
import io.trino.plugin.deltalake.metastore.thrift.DeltaLakeThriftMetastoreModule;
import io.trino.plugin.hive.HideDeltaLakeTables;
import io.trino.plugin.hive.metastore.DecoratedHiveMetastoreModule;
import io.trino.plugin.hive.metastore.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.MetastoreTypeConfig;

import static io.airlift.configuration.ConditionalModule.conditionalModule;
Expand All @@ -37,7 +37,7 @@ protected void setup(Binder binder)
bindMetastoreModule("file", new DeltaLakeFileMetastoreModule());
bindMetastoreModule("glue", new DeltaLakeGlueMetastoreModule());

install(new DecoratedHiveMetastoreModule(false));
install(new CachingHiveMetastoreModule(false));
}

private void bindMetastoreModule(String name, Module module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.plugin.deltalake.AllowDeltaLakeManagedTableRename;
import io.trino.plugin.hive.HideDeltaLakeTables;
import io.trino.plugin.hive.metastore.DecoratedHiveMetastoreModule;
import io.trino.plugin.hive.metastore.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.HiveMetastoreFactory;
import io.trino.plugin.hive.metastore.RawHiveMetastoreFactory;
Expand All @@ -39,7 +39,7 @@ public TestingDeltaLakeMetastoreModule(HiveMetastore metastore)
public void setup(Binder binder)
{
binder.bind(HiveMetastoreFactory.class).annotatedWith(RawHiveMetastoreFactory.class).toInstance(HiveMetastoreFactory.ofInstance(metastore));
install(new DecoratedHiveMetastoreModule(false));
install(new CachingHiveMetastoreModule(false));

binder.bind(Key.get(boolean.class, HideDeltaLakeTables.class)).toInstance(false);
binder.bind(Key.get(boolean.class, AllowDeltaLakeManagedTableRename.class)).toInstance(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,27 @@
import io.trino.plugin.hive.metastore.cache.SharedHiveMetastoreCache;
import io.trino.plugin.hive.metastore.cache.SharedHiveMetastoreCache.CachingHiveMetastoreFactory;
import io.trino.plugin.hive.metastore.procedure.FlushMetadataCacheProcedure;
import io.trino.plugin.hive.metastore.tracing.TracingHiveMetastoreDecorator;
import io.trino.spi.procedure.Procedure;
import io.trino.spi.security.ConnectorIdentity;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static io.airlift.configuration.ConfigBinder.configBinder;
import static java.util.Objects.requireNonNull;
import static org.weakref.jmx.guice.ExportBinder.newExporter;

public class DecoratedHiveMetastoreModule
public class CachingHiveMetastoreModule
extends AbstractConfigurationAwareModule
{
private final boolean installFlushMetadataCacheProcedure;

public DecoratedHiveMetastoreModule(boolean installFlushMetadataCacheProcedure)
public CachingHiveMetastoreModule(boolean installFlushMetadataCacheProcedure)
{
this.installFlushMetadataCacheProcedure = installFlushMetadataCacheProcedure;
}

@Override
protected void setup(Binder binder)
{
newSetBinder(binder, HiveMetastoreDecorator.class)
.addBinding().to(TracingHiveMetastoreDecorator.class).in(Scopes.SINGLETON);

configBinder(binder).bindConfig(CachingHiveMetastoreConfig.class);
// TODO this should only be bound when impersonation is actually enabled
configBinder(binder).bindConfig(ImpersonationCachingConfig.class);
Expand All @@ -72,47 +62,12 @@ protected void setup(Binder binder)
@Singleton
public static HiveMetastoreFactory createHiveMetastore(
@RawHiveMetastoreFactory HiveMetastoreFactory metastoreFactory,
Set<HiveMetastoreDecorator> decorators,
SharedHiveMetastoreCache sharedHiveMetastoreCache)
{
metastoreFactory = new DecoratingHiveMetastoreFactory(metastoreFactory, decorators);

// cross TX metastore cache is enabled wrapper with caching metastore
return sharedHiveMetastoreCache.createCachingHiveMetastoreFactory(metastoreFactory);
}

private static class DecoratingHiveMetastoreFactory
implements HiveMetastoreFactory
{
private final HiveMetastoreFactory delegate;
private final List<HiveMetastoreDecorator> sortedDecorators;

public DecoratingHiveMetastoreFactory(HiveMetastoreFactory delegate, Set<HiveMetastoreDecorator> decorators)
{
this.delegate = requireNonNull(delegate, "delegate is null");

this.sortedDecorators = decorators.stream()
.sorted(Comparator.comparing(HiveMetastoreDecorator::getPriority))
.collect(toImmutableList());
}

@Override
public boolean isImpersonationEnabled()
{
return delegate.isImpersonationEnabled();
}

@Override
public HiveMetastore createMetastore(Optional<ConnectorIdentity> identity)
{
HiveMetastore metastore = delegate.createMetastore(identity);
for (HiveMetastoreDecorator decorator : sortedDecorators) {
metastore = decorator.decorate(metastore);
}
return metastore;
}
}

@Provides
@Singleton
public static Optional<CachingHiveMetastore> createHiveMetastore(HiveMetastoreFactory metastoreFactory)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void setup(Binder binder)
bindMetastoreModule("glue", new GlueMetastoreModule());
}

install(new DecoratedHiveMetastoreModule(true));
install(new CachingHiveMetastoreModule(true));
}

private void bindMetastoreModule(String name, Module module)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.airlift.units.Duration;
import io.trino.plugin.hive.HideDeltaLakeTables;
import io.trino.plugin.hive.metastore.DecoratedHiveMetastoreModule;
import io.trino.plugin.hive.metastore.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.cache.CachingHiveMetastoreConfig;
import io.trino.plugin.hive.metastore.file.FileMetastoreModule;
import io.trino.plugin.iceberg.catalog.IcebergTableOperationsProvider;
Expand All @@ -47,7 +47,7 @@ protected void setup(Binder binder)
binder.bind(TrinoCatalogFactory.class).to(TrinoHiveCatalogFactory.class).in(Scopes.SINGLETON);
binder.bind(MetastoreValidator.class).asEagerSingleton();
binder.bind(Key.get(boolean.class, HideDeltaLakeTables.class)).toInstance(HIDE_DELTA_LAKE_TABLES_IN_ICEBERG);
install(new DecoratedHiveMetastoreModule(false));
install(new CachingHiveMetastoreModule(false));

configBinder(binder).bindConfigDefaults(CachingHiveMetastoreConfig.class, config -> {
// ensure caching metastore wrapper isn't created, as it's not leveraged by Iceberg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.airlift.units.Duration;
import io.trino.plugin.hive.HideDeltaLakeTables;
import io.trino.plugin.hive.metastore.DecoratedHiveMetastoreModule;
import io.trino.plugin.hive.metastore.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.cache.CachingHiveMetastoreConfig;
import io.trino.plugin.hive.metastore.thrift.ThriftMetastoreModule;
import io.trino.plugin.hive.metastore.thrift.TranslateHiveViews;
Expand Down Expand Up @@ -49,7 +49,7 @@ protected void setup(Binder binder)
binder.bind(MetastoreValidator.class).asEagerSingleton();
binder.bind(Key.get(boolean.class, TranslateHiveViews.class)).toInstance(false);
binder.bind(Key.get(boolean.class, HideDeltaLakeTables.class)).toInstance(HIDE_DELTA_LAKE_TABLES_IN_ICEBERG);
install(new DecoratedHiveMetastoreModule(false));
install(new CachingHiveMetastoreModule(false));

configBinder(binder).bindConfigDefaults(CachingHiveMetastoreConfig.class, config -> {
// ensure caching metastore wrapper isn't created, as it's not leveraged by Iceberg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.airlift.units.Duration;
import io.trino.plugin.hive.metastore.DecoratedHiveMetastoreModule;
import io.trino.plugin.hive.metastore.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.HiveMetastoreFactory;
import io.trino.plugin.hive.metastore.RawHiveMetastoreFactory;
Expand Down Expand Up @@ -45,7 +45,7 @@ public TestingIcebergFileMetastoreCatalogModule(HiveMetastore metastore)
protected void setup(Binder binder)
{
binder.bind(HiveMetastoreFactory.class).annotatedWith(RawHiveMetastoreFactory.class).toInstance(HiveMetastoreFactory.ofInstance(metastore));
install(new DecoratedHiveMetastoreModule(false));
install(new CachingHiveMetastoreModule(false));
binder.bind(IcebergTableOperationsProvider.class).to(FileMetastoreTableOperationsProvider.class).in(Scopes.SINGLETON);
binder.bind(TrinoCatalogFactory.class).to(TrinoHiveCatalogFactory.class).in(Scopes.SINGLETON);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.airlift.units.Duration;
import io.trino.plugin.hive.metastore.DecoratedHiveMetastoreModule;
import io.trino.plugin.hive.metastore.CachingHiveMetastoreModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.HiveMetastoreFactory;
import io.trino.plugin.hive.metastore.RawHiveMetastoreFactory;
Expand Down Expand Up @@ -46,7 +46,7 @@ public TestingIcebergHiveMetastoreCatalogModule(HiveMetastore hiveMetastore, Thr
@Override
protected void setup(Binder binder)
{
install(new DecoratedHiveMetastoreModule(false));
install(new CachingHiveMetastoreModule(false));
binder.bind(ThriftMetastoreFactory.class).toInstance(this.thriftMetastoreFactory);
binder.bind(HiveMetastoreFactory.class).annotatedWith(RawHiveMetastoreFactory.class).toInstance(HiveMetastoreFactory.ofInstance(this.hiveMetastore));
binder.bind(IcebergTableOperationsProvider.class).to(HiveMetastoreTableOperationsProvider.class).in(Scopes.SINGLETON);
Expand Down
Loading