Code Monkey home page Code Monkey logo

Comments (1)

neverchanje avatar neverchanje commented on September 13, 2024 1

"auto-compression" is not an accurate saying of this feature.

Background

Design

There's something more to discuss:

1. API Design

How 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.
For example:

  1. requests (within a table) for write (multiset) with auto-retry but read (multiget) without retrying
  2. requests (within a table) for one type of data with compression but others not.

2. Implementation Design

How can we design the API with as little modification of TableHandler as possible? In other words, can we design TableHandler to be more extensible, for features like compression or auto-retry?


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;
}

from pegasus-java-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.