Skip to content

Commit

Permalink
Return ConnectorCommitHandle for commit function
Browse files Browse the repository at this point in the history
    Instead of returning nothing for spi commit function, we return ConnectorCommitHandle
    objects, which will be used to return information for metastore operations.
  • Loading branch information
lliiun-z authored and highker committed Mar 22, 2022
1 parent 69a924e commit 7055463
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.facebook.presto.accumulo.io.AccumuloPageSinkProvider;
import com.facebook.presto.accumulo.io.AccumuloRecordSetProvider;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorPageSinkProvider;
import com.facebook.presto.spi.connector.ConnectorRecordSetProvider;
Expand All @@ -34,6 +35,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.facebook.presto.spi.transaction.IsolationLevel.READ_UNCOMMITTED;
import static com.facebook.presto.spi.transaction.IsolationLevel.checkConnectorSupports;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -94,9 +96,10 @@ public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel
}

@Override
public void commit(ConnectorTransactionHandle transactionHandle)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transactionHandle)
{
checkArgument(transactions.remove(transactionHandle) != null, "no such transaction: %s", transactionHandle);
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorAccessControl;
import com.facebook.presto.spi.connector.ConnectorCapabilities;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorPageSinkProvider;
import com.facebook.presto.spi.connector.ConnectorPlanOptimizerProvider;
Expand All @@ -41,6 +42,7 @@
import java.util.concurrent.ConcurrentMap;

import static com.facebook.presto.spi.connector.ConnectorCapabilities.NOT_NULL_COLUMN_CONSTRAINT;
import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.facebook.presto.spi.transaction.IsolationLevel.READ_COMMITTED;
import static com.facebook.presto.spi.transaction.IsolationLevel.checkConnectorSupports;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -128,9 +130,10 @@ public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction)
}

@Override
public void commit(ConnectorTransactionHandle transaction)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transaction)
{
checkArgument(transactions.remove(transaction) != null, "no such transaction: %s", transaction);
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorAccessControl;
import com.facebook.presto.spi.connector.ConnectorCapabilities;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorMetadataUpdaterProvider;
import com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider;
Expand All @@ -41,6 +42,7 @@

import static com.facebook.presto.spi.connector.ConnectorCapabilities.SUPPORTS_PAGE_SINK_COMMIT;
import static com.facebook.presto.spi.connector.ConnectorCapabilities.SUPPORTS_REWINDABLE_SPLIT_SOURCE;
import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.facebook.presto.spi.transaction.IsolationLevel.READ_UNCOMMITTED;
import static com.facebook.presto.spi.transaction.IsolationLevel.checkConnectorSupports;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -213,13 +215,14 @@ public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel
}

@Override
public void commit(ConnectorTransactionHandle transaction)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transaction)
{
TransactionalMetadata metadata = transactionManager.remove(transaction);
checkArgument(metadata != null, "no such transaction: %s", transaction);
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
metadata.commit();
}
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorAccessControl;
import com.facebook.presto.spi.connector.ConnectorCapabilities;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider;
import com.facebook.presto.spi.connector.ConnectorPageSinkProvider;
Expand All @@ -40,6 +41,7 @@
import java.util.Set;

import static com.facebook.presto.spi.connector.ConnectorCapabilities.NOT_NULL_COLUMN_CONSTRAINT;
import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.facebook.presto.spi.transaction.IsolationLevel.SERIALIZABLE;
import static com.facebook.presto.spi.transaction.IsolationLevel.checkConnectorSupports;
import static com.google.common.collect.Sets.immutableEnumSet;
Expand Down Expand Up @@ -186,9 +188,10 @@ public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel
}

@Override
public void commit(ConnectorTransactionHandle transaction)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transaction)
{
transactionManager.remove(transaction);
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.facebook.presto.lark.sheets.api.LarkSheetsApi;
import com.facebook.presto.lark.sheets.api.LarkSheetsSchemaStore;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorRecordSetProvider;
import com.facebook.presto.spi.connector.ConnectorSplitManager;
Expand All @@ -30,6 +31,7 @@
import java.util.List;
import java.util.function.Supplier;

import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static java.util.Objects.requireNonNull;

public class LarkSheetsConnector
Expand Down Expand Up @@ -99,9 +101,10 @@ public List<PropertyMetadata<?>> getSchemaProperties()
}

@Override
public void commit(ConnectorTransactionHandle transactionHandle)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transactionHandle)
{
transactionManager.remove(transactionHandle);
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.presto.spi.ConnectorId;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorTransactionHandle;
import com.facebook.presto.spi.function.FunctionNamespaceManager;
Expand Down Expand Up @@ -62,6 +63,7 @@
import static com.facebook.presto.spi.StandardErrorCode.READ_ONLY_VIOLATION;
import static com.facebook.presto.spi.StandardErrorCode.TRANSACTION_ALREADY_ABORTED;
import static com.facebook.presto.spi.StandardErrorCode.UNKNOWN_TRANSACTION;
import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
Expand Down Expand Up @@ -671,11 +673,12 @@ public ConnectorTransactionHandle getTransactionHandle()
return transactionHandle;
}

public void commit()
public ConnectorCommitHandle commit()
{
if (finished.compareAndSet(false, true)) {
connector.commit(transactionHandle);
return connector.commit(transactionHandle);
}
return INSTANCE;
}

public void abort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.facebook.presto.mongodb;

import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorPageSinkProvider;
import com.facebook.presto.spi.connector.ConnectorPageSourceProvider;
Expand All @@ -26,6 +27,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.facebook.presto.spi.transaction.IsolationLevel.READ_UNCOMMITTED;
import static com.facebook.presto.spi.transaction.IsolationLevel.checkConnectorSupports;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -78,9 +80,10 @@ public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction)
}

@Override
public void commit(ConnectorTransactionHandle transaction)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transaction)
{
checkArgument(transactions.remove(transaction) != null, "no such transaction: %s", transaction);
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.facebook.presto.spi.SystemTable;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorAccessControl;
import com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider;
import com.facebook.presto.spi.connector.ConnectorPageSinkProvider;
Expand All @@ -47,6 +48,7 @@

import static com.facebook.airlift.concurrent.Threads.daemonThreadsNamed;
import static com.facebook.presto.raptor.util.DatabaseUtil.onDemandDao;
import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static com.facebook.presto.spi.transaction.IsolationLevel.READ_COMMITTED;
import static com.facebook.presto.spi.transaction.IsolationLevel.checkConnectorSupports;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -136,10 +138,11 @@ public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel
}

@Override
public void commit(ConnectorTransactionHandle transaction)
public ConnectorCommitHandle commit(ConnectorTransactionHandle transaction)
{
checkArgument(transactions.remove(transaction) != null, "no such transaction: %s", transaction);
finishDelete(((RaptorTransactionHandle) transaction).getUuid());
return INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Set;

import static com.facebook.presto.spi.connector.EmptyConnectorCommitHandle.INSTANCE;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;

Expand Down Expand Up @@ -160,8 +161,9 @@ default ConnectorAccessControl getAccessControl()
* Commit the transaction. Will be called at most once and will not be called if
* {@link #rollback(ConnectorTransactionHandle)} is called.
*/
default void commit(ConnectorTransactionHandle transactionHandle)
default ConnectorCommitHandle commit(ConnectorTransactionHandle transactionHandle)
{
return INSTANCE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 com.facebook.presto.spi.connector;

public interface ConnectorCommitHandle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 com.facebook.presto.spi.connector;

public enum EmptyConnectorCommitHandle
implements ConnectorCommitHandle
{
INSTANCE;
}

0 comments on commit 7055463

Please sign in to comment.