Skip to content

Commit

Permalink
[transaction] Add transaction coordinator client (apache#4953)
Browse files Browse the repository at this point in the history
*Motivation*

Add the interface of transaction coordinator client. So that it can be used
by coordinator for committing transactions on topics and subscriptions.

NOTE: this PR is only introducing the interface. The implementation will come
in subsequent pull requests
  • Loading branch information
sijie authored Aug 20, 2019
1 parent 385a036 commit aa77572
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.pulsar.client.impl.transaction;

import java.util.concurrent.CompletableFuture;

/**
* The transaction coordinator client to commit and abort transactions on topics.
*/
public interface TransactionCoordinatorClient {

/**
* Commit the transaction associated with the topic.
*
* @param topic topic name
* @param txnIdMostBits the most bits of txn id
* @param txnIdLeastBits the least bits of txn id
* @return the future represents the commit result
*/
CompletableFuture<Void> commitTxnOnTopic(String topic,
long txnIdMostBits,
long txnIdLeastBits);

/**
* Abort the transaction associated with the topic.
*
* @param topic topic name
* @param txnIdMostBits the most bits of txn id
* @param txnIdLeastBits the least bits of txn id
* @return the future represents the abort result
*/
CompletableFuture<Void> abortTxnOnTopic(String topic,
long txnIdMostBits,
long txnIdLeastBits);

/**
* Commit the transaction associated with the topic subscription.
*
* @param topic topic name
* @param subscription subscription name
* @param txnIdMostBits the most bits of txn id
* @param txnIdLeastBits the least bits of txn id
* @return the future represents the commit result
*/
CompletableFuture<Void> commitTxnOnSubscription(String topic,
String subscription,
long txnIdMostBits,
long txnIdLeastBits);

/**
* Abort the transaction associated with the topic subscription.
*
* @param topic topic name
* @param subscription subscription name
* @param txnIdMostBits the most bits of txn id
* @param txnIdLeastBits the least bits of txn id
* @return the future represents the abort result
*/
CompletableFuture<Void> abortTxnOnSubscription(String topic,
String subscription,
long txnIdMostBits,
long txnIdLeastBits);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.pulsar.client.impl.transaction;

import java.util.concurrent.CompletableFuture;
import org.apache.pulsar.client.impl.PulsarClientImpl;
import org.apache.pulsar.common.util.FutureUtil;

/**
* The implementation of {@link TransactionCoordinatorClient}.
*/
public class TransactionCoordinatorClientImpl implements TransactionCoordinatorClient {

private final PulsarClientImpl client;

public TransactionCoordinatorClientImpl(PulsarClientImpl client) {
this.client = client;
}

@Override
public CompletableFuture<Void> commitTxnOnTopic(String topic, long txnIdMostBits, long txnIdLeastBits) {
return FutureUtil.failedFuture(
new UnsupportedOperationException("Not Implemented Yet"));
}

@Override
public CompletableFuture<Void> abortTxnOnTopic(String topic, long txnIdMostBits, long txnIdLeastBits) {
return FutureUtil.failedFuture(
new UnsupportedOperationException("Not Implemented Yet"));
}

@Override
public CompletableFuture<Void> commitTxnOnSubscription(String topic, String subscription, long txnIdMostBits, long txnIdLeastBits) {
return FutureUtil.failedFuture(
new UnsupportedOperationException("Not Implemented Yet"));
}

@Override
public CompletableFuture<Void> abortTxnOnSubscription(String topic, String subscription, long txnIdMostBits, long txnIdLeastBits) {
return FutureUtil.failedFuture(
new UnsupportedOperationException("Not Implemented Yet"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/**
* Transaction client implementation.
*/
package org.apache.pulsar.client.impl.transaction;

0 comments on commit aa77572

Please sign in to comment.