-
Notifications
You must be signed in to change notification settings - Fork 25
support option to enable compression and hide details of compression from users #123
Comments
"auto-compression" is not an accurate saying of this feature. BackgroundDesignThere's something more to discuss: 1. API DesignHow to design the API? Can we make this feature backward compatible with the previous API? Is one more new method needed for every type of Pegasus RPC? Since it's required to be backward compatible with API modified as minimum as possible, we provide this feature as a table-level option rather than a call-level option. class TableOptions {
// Compression is one of the options.
bool enableCompression() {}
bool enableAutoRetry() {}
bool enableBackupRequest() {}
TableOptions withZstdCompression() {}
TableOptions withAutoRetry(int maxRetries, BackoffPolicy backoff) {}
TableOptions withBackupRequest(int backupRequestDelayMs) {}
}
class PegasusClientInterface {
PegasusTableInterface openTable(String tableName, TableOptions opts);
} However, there may be some cases that users require finer-grained control over RPC.
2. Implementation DesignHow can we design the API with as little modification of One possible solution is to firstly refactor TableHandler, this refactoring suits go-client as well. It was inspired by grpc UnaryInterceptor and CallOption. // TableInterceptor is a plugin to control the behavior of an RPC to a Pegasus table.
//
// request
// client ----> Pegasus Table
// |
// | ---- TableInterceptor is a middle layer to control the RPC process.
// |
// <----
// response
//
interface TableInterceptor {
// The behavior before the ReplicaSession sends the RPC.
void interceptBefore(ClientRequestRound rpc, TableHandler table, TableOptions opts) throws Exception;
// The behavior after the ReplicaSession get reply or failure of the RPC.
void interceptAfter(ClientRequestRound rpc, error_types errno, TableHandler table, TableOptions opts) Exception;
} This is a simple implementation of interceptor of backup request. class BackupRequestInterceptor implements TableInterceptor {
void interceptBefore(ClientRequestRound rpc, TableHandler table, TableOptions opts) throws Exception {
if (opts.enableBackupRequest()) {
rpc.backupRequestTask = executor.schedule();
}
}
void interceptAfter(ClientRequestRound rpc, TableHandler table, TableOptions opts) throws Exception {}
private int backupRequestDelayMs;
} To implement compression: class CompressionInterceptor implements TableInterceptor {
void interceptBefore(ClientRequestRound rpc, TableHandler table, TableOptions opts) throws Exception {
if(opts.enableCompression()) {
rpc.operator.compress();
}
}
void interceptAfter(ClientRequestRound rpc, TableHandler table, TableOptions opts) throws Exception {
if(opts.enableCompression()) {
rpc.operator.decompress();
}
}
} Where are these interceptors registered? One possible mean is: class TableHandler {
public TableHandler(ClusterManager mgr, String name, TableOptions options) {
...
interceptors.add(new CompressionInterceptor()).add(new BackupRequestInterceptor());
}
void call() {
for(TableInterceptor interceptor : interceptors) {
interceptor.interceptBefore();
}
primarySession.send( () -> {
for(TableInterceptor interceptor : interceptors) {
interceptor.interceptAfter();
}
}
}
private List<TableInterceptor> interceptors;
} |
This issue is based on #121 and is the details of
Support auto-compress
.This feature is simple:
The text was updated successfully, but these errors were encountered: