Module 5a - Apache Thrift Flashcards
What are the 4 internal software layers involved in a thrift service? What are they for?
- Server - receives incoming connections
- Processor - reads/writes I/O streams
- Protocol - encodes/decodes data (can be into JSON)
- Transport - reads/writes network (can use TCP, or HTTP)
Give an example of a thrift IDL (.thrift file) for an interface that calculates the square root of a number, and throws an exception
service MathService { double sqrt(1: double num) throws (1: IllegalArgument ia) }
exception IllegalArgument {
1: string message;
}
What are the 9 base types for the thrift IDL?
bool byte i16 i32 i64 double binary string void
What are the 3 types of datatype containers in the thrift IDL?
list
set
map
What are the other language constructs that thrift provides in its IDL?
const typedef enum struct exception
What are the field modifiers for function signatures that thrift provides in its IDL?
required
optional
default values
What is the “oneway” keyword used for in the thrift IDL?
building oneway thrift RPCs
What does the service keyword define in the thrift IDL?
A service consists of a set of named functions, each with a list of parameters and a return type
What does the “namespace” keyword determine in the thrift IDL?
Determines the java package
After the IDL has been defined in a thrift file (lets call it file.thrift), what command is used to generate the source code files for the services?
thrift –gen file.thrift
What steps must a synchronous thrift RPC client program execute when calling a service handler and invoking an RPC from the server?
Client must:
1. create a TSocket object using the network address of the server
- Create a TTransport object using the TSocket object from step 1
- Create a TProtocol object using the TTransport object from step 2
- Create the service handler object from the TProtocol object in step 3. The client can now call the server’s service handlers and invoke the RPC
What steps must a single-threaded thrift RPC server program execute when setting up a server which allows clients to invoke RPC calls to it?
- Create a Processor object from the generated service handler files
- Create a TServerSocket object using a port number to bind to
- Create objects for protocolFactory, transportFactory, and processorFactory. The processorFactory will be the processor object from step 1
- Create the TServer object from the arguments in step 3.
- run the blocking “serve()” call
What is the purpose of having the same “Protocol” and the “Transport” on the client and server for thrift RPC?
Protocol ensures that the data encoding formatting matches for the server and the client (JSON or otherwise)
Transport ensures that the network protocols that the server and client use are consistent
In what way does a thrift client violate the principle of location transparency?
The thrift client must know the host name and port number of a given server
In what way does a thrift client-server system violate the principle of location transparency?
Server may throw a variety of exceptions, and the exceptions will be passed along the network to the Client