Skip to content
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 @@ -45,6 +45,7 @@ public class MongoClientConfig
private String requiredReplicaSetName;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally disable local scheduling of Mongo splits

Why "additionally"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We disable it by default as enabling couples the storage and compute layer i.e split would be assigned to the worker which is shared with MongoDB which might cause some contention of resources.

private String implicitRowFieldPrefix = "_pos";
private boolean projectionPushDownEnabled = true;
private boolean allowLocalScheduling;

@NotNull
public String getSchemaCollection()
Expand Down Expand Up @@ -251,4 +252,17 @@ public MongoClientConfig setProjectionPushdownEnabled(boolean projectionPushDown
this.projectionPushDownEnabled = projectionPushDownEnabled;
return this;
}

public boolean isAllowLocalScheduling()
{
return allowLocalScheduling;
}

@Config("mongodb.allow-local-scheduling")
@ConfigDescription("Assign mongo splits to host if worker and mongo share the same cluster")
public MongoClientConfig setAllowLocalScheduling(boolean allowLocalScheduling)
{
this.allowLocalScheduling = allowLocalScheduling;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.mongodb;

import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import com.google.inject.Provides;
import com.google.inject.Scopes;
Expand Down Expand Up @@ -60,6 +61,12 @@ public void setup(Binder binder)
MongoClientConfig::getTlsEnabled,
new MongoSslModule()));

install(conditionalModule(
MongoClientConfig.class,
MongoClientConfig::isAllowLocalScheduling,
internalBinder -> internalBinder.bind(MongoServerDetailsProvider.class).toInstance(ImmutableList::of),
internalBinder -> internalBinder.bind(MongoServerDetailsProvider.class).to(SessionBasedMongoServerDetailsProvider.class).in(Scopes.SINGLETON)));

newSetBinder(binder, ConnectorTableFunction.class).addBinding().toProvider(Query.class).in(Scopes.SINGLETON);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed 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 io.trino.plugin.mongodb;

import io.trino.spi.HostAddress;

import java.util.List;

public interface MongoServerDetailsProvider
{
List<HostAddress> getServerAddress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package io.trino.plugin.mongodb;

import com.google.inject.Inject;
import io.trino.spi.HostAddress;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.ConnectorSplitManager;
import io.trino.spi.connector.ConnectorSplitSource;
Expand All @@ -24,17 +23,17 @@
import io.trino.spi.connector.DynamicFilter;
import io.trino.spi.connector.FixedSplitSource;

import java.util.List;
import static java.util.Objects.requireNonNull;

public class MongoSplitManager
implements ConnectorSplitManager
{
private final List<HostAddress> addresses;
private final MongoServerDetailsProvider serverDetailsProvider;

@Inject
public MongoSplitManager(MongoSession session)
public MongoSplitManager(MongoServerDetailsProvider serverDetailsProvider)
{
this.addresses = session.getAddresses();
this.serverDetailsProvider = requireNonNull(serverDetailsProvider, "serverDetailsProvider is null");
}

@Override
Expand All @@ -45,7 +44,7 @@ public ConnectorSplitSource getSplits(
DynamicFilter dynamicFilter,
Constraint constraint)
{
MongoSplit split = new MongoSplit(addresses);
MongoSplit split = new MongoSplit(serverDetailsProvider.getServerAddress());

return new FixedSplitSource(split);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed 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 io.trino.plugin.mongodb;

import com.google.inject.Inject;
import io.trino.spi.HostAddress;

import java.util.List;

import static java.util.Objects.requireNonNull;

public class SessionBasedMongoServerDetailsProvider
implements MongoServerDetailsProvider
{
private final MongoSession mongoSession;

@Inject
public SessionBasedMongoServerDetailsProvider(MongoSession mongoSession)
{
this.mongoSession = requireNonNull(mongoSession, "mongoSession is null");
}

@Override
public List<HostAddress> getServerAddress()
{
return mongoSession.getAddresses();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void testDefaults()
.setWriteConcern(WriteConcernType.ACKNOWLEDGED)
.setRequiredReplicaSetName(null)
.setImplicitRowFieldPrefix("_pos")
.setProjectionPushdownEnabled(true));
.setProjectionPushdownEnabled(true)
.setAllowLocalScheduling(false));
}

@Test
Expand All @@ -67,6 +68,7 @@ public void testExplicitPropertyMappings()
.put("mongodb.required-replica-set", "replica_set")
.put("mongodb.implicit-row-field-prefix", "_prefix")
.put("mongodb.projection-pushdown-enabled", "false")
.put("mongodb.allow-local-scheduling", "true")
.buildOrThrow();

MongoClientConfig expected = new MongoClientConfig()
Expand All @@ -85,7 +87,8 @@ public void testExplicitPropertyMappings()
.setWriteConcern(WriteConcernType.UNACKNOWLEDGED)
.setRequiredReplicaSetName("replica_set")
.setImplicitRowFieldPrefix("_prefix")
.setProjectionPushdownEnabled(false);
.setProjectionPushdownEnabled(false)
.setAllowLocalScheduling(true);

assertFullMapping(properties, expected);
}
Expand Down