java/client: Add VitessException for app-level errors.

This commit is contained in:
Anthony Yeh 2015-08-12 15:59:19 -07:00
Родитель 68f98fcde3
Коммит e676bcc059
5 изменённых файлов: 54 добавлений и 31 удалений

Просмотреть файл

@ -34,46 +34,46 @@ import java.util.Iterator;
public interface RpcClient extends Closeable {
// executeShard sends a single query to a set of shards.
ExecuteShardsResponse executeShard(
Context ctx, ExecuteShardsRequest request) throws VitessRpcException;
Context ctx, ExecuteShardsRequest request) throws VitessException, VitessRpcException;
// executeKeyspaceIds sends a query with keyspace ids as bind variables.
ExecuteKeyspaceIdsResponse executeKeyspaceIds(
Context ctx, ExecuteKeyspaceIdsRequest request) throws VitessRpcException;
Context ctx, ExecuteKeyspaceIdsRequest request) throws VitessException, VitessRpcException;
// executeKeyRanges sends a query with a set of key ranges.
ExecuteKeyRangesResponse executeKeyRanges(
Context ctx, ExecuteKeyRangesRequest request) throws VitessRpcException;
Context ctx, ExecuteKeyRangesRequest request) throws VitessException, VitessRpcException;
// executeBatchKeyspaceIds sends a list of queries with keyspace ids as bind variables.
ExecuteBatchKeyspaceIdsResponse executeBatchKeyspaceIds(
Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessRpcException;
Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessException, VitessRpcException;
// executeBatchShards sends a list of queries to a set of shards.
ExecuteBatchShardsResponse executeBatchShards(
Context ctx, ExecuteBatchShardsRequest request) throws VitessRpcException;
Context ctx, ExecuteBatchShardsRequest request) throws VitessException, VitessRpcException;
// streamExecuteShard starts stream queries with multiple shards.
Iterator<StreamExecuteShardsResponse> streamExecuteShard(
Context ctx, StreamExecuteShardsRequest request) throws VitessRpcException;
Context ctx, StreamExecuteShardsRequest request) throws VitessException, VitessRpcException;
// streamExecuteKeyspaceIds starts a list of stream queries with keyspace ids as bind variables.
Iterator<StreamExecuteKeyspaceIdsResponse> streamExecuteKeyspaceIds(
Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessRpcException;
Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessException, VitessRpcException;
// streamExecuteKeyRanges starts stream query with a set of key ranges.
Iterator<StreamExecuteKeyRangesResponse> streamExecuteKeyRanges(
Context ctx, StreamExecuteKeyRangesRequest request) throws VitessRpcException;
Context ctx, StreamExecuteKeyRangesRequest request) throws VitessException, VitessRpcException;
// begin starts a transaction.
BeginResponse begin(Context ctx, BeginRequest request) throws VitessRpcException;
BeginResponse begin(Context ctx, BeginRequest request) throws VitessException, VitessRpcException;
// commit commits a transaction.
CommitResponse commit(Context ctx, CommitRequest request) throws VitessRpcException;
CommitResponse commit(Context ctx, CommitRequest request) throws VitessException, VitessRpcException;
// rollback rollbacks a pending transaction.
RollbackResponse rollback(Context ctx, RollbackRequest request) throws VitessRpcException;
RollbackResponse rollback(Context ctx, RollbackRequest request) throws VitessException, VitessRpcException;
// getSrvKeyspace returns a list of serving keyspaces.
GetSrvKeyspaceResponse getSrvKeyspace(
Context ctx, GetSrvKeyspaceRequest request) throws VitessRpcException;
Context ctx, GetSrvKeyspaceRequest request) throws VitessException, VitessRpcException;
}

Просмотреть файл

@ -27,7 +27,7 @@ import java.util.Iterator;
/**
* VTGateConn manages a VTGate connection.
* TODO(shengzhe): define VitessException for app-level error
*
* <p>Usage:
*
* <code>
@ -79,46 +79,46 @@ public class VTGateConn implements Closeable {
}
public ExecuteShardsResponse ExecuteShard(Context ctx, ExecuteShardsRequest request)
throws VitessRpcException {
throws VitessException, VitessRpcException {
return this.client.executeShard(ctx, request);
}
public ExecuteKeyspaceIdsResponse ExecuteKeyspaceIds(Context ctx, ExecuteKeyspaceIdsRequest request)
throws VitessRpcException {
throws VitessException, VitessRpcException {
return this.client.executeKeyspaceIds(ctx, request);
}
public ExecuteKeyRangesResponse executeKeyRanges(Context ctx, ExecuteKeyRangesRequest request)
throws VitessRpcException {
throws VitessException, VitessRpcException {
return this.client.executeKeyRanges(ctx, request);
}
public ExecuteBatchKeyspaceIdsResponse executeBatchKeyspaceIds(
Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessRpcException {
Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessException, VitessRpcException {
return this.client.executeBatchKeyspaceIds(ctx, request);
}
public ExecuteBatchShardsResponse executeBatchShards(Context ctx, ExecuteBatchShardsRequest request)
throws VitessRpcException {
throws VitessException, VitessRpcException {
return this.client.executeBatchShards(ctx, request);
}
public Iterator<StreamExecuteShardsResponse> streamExecuteShard(
Context ctx, StreamExecuteShardsRequest request) throws VitessRpcException {
Context ctx, StreamExecuteShardsRequest request) throws VitessException, VitessRpcException {
return this.client.streamExecuteShard(ctx, request);
}
public Iterator<StreamExecuteKeyspaceIdsResponse> streamExecuteKeyspaceIds(
Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessRpcException {
Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessException, VitessRpcException {
return this.client.streamExecuteKeyspaceIds(ctx, request);
}
public Iterator<StreamExecuteKeyRangesResponse> streamExecuteKeyRanges(
Context ctx, StreamExecuteKeyRangesRequest request) throws VitessRpcException {
Context ctx, StreamExecuteKeyRangesRequest request) throws VitessException, VitessRpcException {
return this.client.streamExecuteKeyRanges(ctx, request);
}
public VTGateTx begin(Context ctx, BeginRequest request) throws VitessRpcException {
public VTGateTx begin(Context ctx, BeginRequest request) throws VitessException, VitessRpcException {
BeginResponse response = this.client.begin(ctx, request);
if (response.hasError()) {
throw new VitessRpcException(response.getError().getMessage());
@ -127,7 +127,7 @@ public class VTGateConn implements Closeable {
}
public GetSrvKeyspaceResponse getSrvKeyspace(Context ctx, GetSrvKeyspaceRequest request)
throws VitessRpcException {
throws VitessException, VitessRpcException {
return this.client.getSrvKeyspace(ctx, request);
}

Просмотреть файл

@ -37,7 +37,7 @@ public class VTGateTx {
}
public QueryResult executeShard(Context ctx, ExecuteShardsRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("executeShard: not in transaction");
}
@ -47,7 +47,7 @@ public class VTGateTx {
}
public QueryResult executeKeyspaceIds(Context ctx, ExecuteKeyspaceIdsRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("executeKeyspaceIds: not in transaction");
}
@ -57,7 +57,7 @@ public class VTGateTx {
}
public QueryResult executeKeyRanges(Context ctx, ExecuteKeyRangesRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("executeKeyRanges: not in transaction");
}
@ -68,7 +68,7 @@ public class VTGateTx {
public List<QueryResult> executeBatchKeyspaceIds(
Context ctx, ExecuteBatchKeyspaceIdsRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("executeBatchKeyspaceIds: not in transaction");
}
@ -78,7 +78,7 @@ public class VTGateTx {
}
public List<QueryResult> executeBatchShards(Context ctx, ExecuteBatchShardsRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("executeBatchShards: not in transaction");
}
@ -89,7 +89,7 @@ public class VTGateTx {
public CommitResponse commit(Context ctx, CommitRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("commit: not in transaction");
}
@ -100,7 +100,7 @@ public class VTGateTx {
}
public RollbackResponse rollback(Context ctx, RollbackRequest request)
throws VitessRpcException, VitessNotInTransactionException {
throws VitessException, VitessRpcException, VitessNotInTransactionException {
if (this.session == null) {
throw new VitessNotInTransactionException("rollback: not in transaction");
}

Просмотреть файл

@ -0,0 +1,23 @@
package com.youtube.vitess.client;
/**
* VitessException indicates an error returned by VTGate.
*/
public class VitessException extends Exception {
public VitessException() {
super();
}
public VitessException(String message) {
super(message);
}
public VitessException(String message, Throwable cause) {
super(message, cause);
}
public VitessException(Throwable cause) {
super(cause);
}
}

Просмотреть файл

@ -1,7 +1,7 @@
package com.youtube.vitess.client;
/**
* VitessRpcException indicates a rpc error between client and VTGate.
* VitessRpcException indicates an RPC error while trying to communicate with VTGate.
*/
public class VitessRpcException extends Exception {