You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 124 Next »

Introduction

Apache Geode is a data management platform that provides real-time, consistent access to data-intensive applications throughout widely distributed cloud architectures. While it currently has high-speed client interfaces for Java, C++ and .NET there is both a need to create lighter-weight clients and a demand to access Geode from other programming languages. Unfortunately, the existing client-server protocol is undocumented.  It evolved over time and is overly complex to meet either of these needs.

This document describes a new, lighter-weight client/server protocol that may be implemented in phases, moving from a "basic client" to a more advanced "smart client".  It endeavors to provide a protocol that is also more amenable to more modern APIs such as those using asynchronous or reactive patterns.

You will notice that this document describes the protocol down to the level of byte-ordering and "bytes on the wire".  This is a description of the native serialization of the protocol that will be used for the initial implementation.  It is our intent to make this pluggable so that alternative serialization technologies may be used instead, such as Protobuf or Apache Thrift.  How that is done will be left as a goal for the architecture of the server component, with an additional goal of providing an IDL description of the protocol.

At the same time, we realize that serialization of application keys, values, callback arguments, function parameters and so forth are a separate matter and are not necessarily tied to the serialization protocol used for client/server messaging.  The initial protocol will support primitive types such as scalars, strings, and byte arrays.  It will also support JSON documents as values and convert between these and Geode PDX-serialized objects in the servers.

Goals

The high-level goals for the protocol are defined here.


Protocol Requirements

In the evaluation or definition of any protocol, it expected that the evaluated protocol/framework meets the following requirements:

  • Versioning: The protocol has to provide version information, in order to distinguish different protocol versions from one another.

  • Correlation Id: This number is a unique identifier that allows the system to correlate requests and responses.

  • Object Type: The type of a serialized object.

  • Response Type: It indicates whether a response is partial or complete.

  • ErrorCodes: It indicates the problem with API invocation.

  • Chunk Response: The ability to send a large response in multiple smaller, more manageable chunks.

  • Continuous Response: Client can register(Observer pattern) for events and then server notify the client if those events occur.

  • Request: The request message to be sent

  • Response: The response message received in relation to a request message

  • Request Format: Format of request API and its parameters, which client wants to invoke.

  • Response Format: Format for API return value, which client invoked.

  • Message: The generic construct that represents a message that is to be sent which contains a Message Header and Request/Response.

  • Serialized Byte Order: Big Endian

Approach

 During the investigation into frameworks that would "lower the barrier of entry," it became evident that there are two approaches that can be taken to solve the problem:

  1. Message Serialization Frameworks - These frameworks allow for the definition of a message in a generic IDL, the generation of language specific classes from the IDL, and the encoding/decoding of those message to be sent over a transport
  2. RPC Frameworks - There frameworks provide greater coverage in the node-to-node communication: the transport layer (HTTP, TCP, UDP), the message definition in IDL with corresponding serialization mechanism and the definition of methods in the IDL and the generation of corresponding service stubs

From an architectural perspective, the protocol proposal can be broken into two areas of interest:
  1. A Transport Layer (TCP, UDP, HTTP, etc..)
  2. Message encoding/decoding Layer
This proposal will:
  1. Define the message structure and protocol to be agnostic of transport used.
  2. Evaluate different Message Serialization Frameworks and RPC Frameworks.

Message Structure Definition

All details relating to the Message structure definition can be found here.


Connect 

In order to fit into the existing Geode client/server infrastructure, we will be leveraging the current Geode "cache server" component.  It accepts an initial byte that tells it what type of client is connecting to the server and how the client should be handled. A client using the new protocol can connect with the Geode server by sending a protocol byte. Initially, we will support the following two protocols:

  • byte - 110: Message will contain the whole request or response. 
  • byte - 111: If the message is large then client or server can divide the message into the set of small messages. Then they need to collect all the small message and parse the whole request or response.

We may add additional protocol definitions here to indicate the use of an alternative serialization mechanism.  For instance bytes 112 & 113 might indicate the but require the server to use Protobuf for serialization of client/server messages.  How we handle other serialization libraries will be addressed when the pluggable-serialization architecture is roughed out.

Protocol FieldDefinitions

API Id

The ApiId recognizes the API, a client wants to invoke on the server. The request format will contain the 2-byte(int16) for API id. It will be marked as ApiId in the request format.

API Version

API version will be associated with the request API. The request format will contain a 1-byte(int8) for the version. It will be marked as ApiVersion in the request format. Its current value will be 1.

Correlation Id

The purpose of correlation id to match the request and its corresponding response. The request format will contain the 4-bytes(int32) for correlation Id. It will be marked as CorrelationId in the request and response format. The client needs to send correlation id with the request and server will send the same id with the response.

Object Type

We will support all the object types which Geode understands. This would include all the primitive java types, an array of primitive types, collections, java serialization, data serializable, PDX serialization and custom user data serializers. The client needs to serialize objects as described here.  This might be extended as part of making the Geode storage format pluggable.

ObjectKeyType

Geode supports only few object types as the region Key. The region key will be marked as Key in the request format. the client needs to serialize key as described here.

ResponseType

The Response Type indicates whether the response is partial or complete. The response with the FullResponse type id indicates the completion of that request. And the response with PartialResponse type id indicates the response is partial. The response format will contain the 2-bytes(int16) for response type. It will be marked as ResponseTypeId in the response format.

ResponseTypeResponseTypeId
FullResponse1
PartialResponse2

Error Codes

The Error codes indicate the issue with the invocation of API at the server. We have defined the error code for various issues hereThe response format will contain the 2-bytes(int16) for error codes. It will be marked as ErrorCode in the response format.

Data Type Definitions

The protocol descriptions use the following types. These may be mapped to a pluggable serialization description language but their native serialization is described here.  The native serialization uses network byte order ("big-endian").

 

TypeNumber Of BytesValueSerializedBytes
booleanFixed = 1true0x01 
booleanFixed = 1false0x00
int8Fixed = 110x01
int16Fixed = 210x00 0x01 
int32Fixed = 410x00 0x00 0x00 0x01 
int64Fixed = 810x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 
String(modified UTF 8 )

Variable

  • 2 byte(int16) for length of encoded String
  • Utf Encoding
"Geode"

0x00 0x05 (length)

0x47 0x65 0x6f 0x64 0x65 (utf encoding)

byte[]

Variable

  • 2 bytes(int16) for number of bytes
  • series of bytes.
{1,2}

0x00 0x02 (length)

0x01 0x02 

bytes

Variable: series of bytes containing a serialized value.

  

Message Definition

A message is a series of bytes which contains the request or response. If the message is large, then we will have provision to divide the message into small messages. In that case, client/server needs to collect all messages to parse the request/response.

The message will be sent in following way.  A client can send the multiple messages on the connection and the server will respond to those messages in same order. 

Additional Request and Response message definitions can be found in the API's section.

Message definition grammar

In order to consistently define messages the Extended Backus–Naur form grammar will be used.

UsageNotation
definition=
alteration|
optional[ ... ]
repetition{ ... }

Generic Message definition

Every message will adhere to the following generic message definition. A Message will comprise of a MessageHeader and either a Request or Response component.

Message => MessageHeader (Request | Response)Description
MessageHeadervariable size, type = MessageHeaderThe MessageHeader corresponding to this Message.
Requestvariable size, type = RequestThis field will contain the Request component.
Responsevariable size, type = ResponseThis field will contain the Response component.

MessageHeader

The Message header is a fixed size header which contains the size of a message, boolean flag to indicates whether a message is partial, and correlation id for that request message. The correlation id is used for the dual purpose here.

  • If a message is sent in multiple sub-messages, then it will be used for combining the whole message. 
  • It will be used for correlating the request to its response.
MessageHeader => Size CorrelationId isPartialMessage hasMetaDataDescription
SizefixedSize = 4 bytes, type = int32Size of request or response
CorrelationIdfixedSize = 4 bytes, type = int32The correlationID used to track a request/response
isPartialMessagefixedSize = 1 byte, type = booleanIs this a partial message
hasMetaDatafixedSize = 1 byte, type = booleanDoes the message have meta data associated with it

Request

The request would contain the fixed size request header, optional metadata and request API parameters. 

Request => RequestHeader [MetaData] RequestAPI Description
RequestHeadervariable size, type = RequestHeaderThe RequestHeader corresponding to this Request
MetaDataoptional, variable size, type = MetaDataThis field is optional and will be populated if the MessageHeader.hasMeta is true

RequestAPI

variable size, type = variable

The Api specific Request message. Here are some examples of Request messages

PutRequest | GetRequest | PutAllRequest | GetAllRequest |ServerConfigRequest | ClientConfigRequest | AuthRequest

RequestHeader

The request header contains the ApiId, ApiVersion, and hasMetaData flag to indicate whether the request contains some metadata.

RequestHeader => ApiId apiVersionDescription
ApiIdfixedSize = 2 bytes, type = int16The Api ID for the Request. Supported ID's are defined on the API's page
apiVersionfixedSize = 1 byte, type = int8The version of the API being used.

Response

The response would contain the fixed size response header, optional metadata and return values.

  

Response => ResponseHeader [MetaData] APIResponseDescription
ResponseHeadervariable size, type = ResponseHeaderThe ResponseHeader corresponding to this Response
MetaDataoptional, variable size, type = MetaDataThis field is optional and will be populated if the MessageHeader.hasMeta is true
APIResponsevariable size, type = variable

The Api specific Reponse message. Here are some examples of Response messages

PutResponse | GetResponse | PutAllResponse | GetAllResponse | ServerConfigResposne | ClientConfigResponse | AuthResponse | ErrorResponse

ResponseHeader

The response header will have resposneType, which indicates its partial response, full response or error. A hasMetaData flag indicates whether the response contains some metadata.

ResponseHeader => ResponseTypeId | ErrorCodeDescription
ResponseTypeIdfixedSize = 2 bytes, type = int16The ResponeTypeId corresponding to either a Full or Partial message
ErrorCodefixedSize = 2 bytes, type = int16When there is error response will have error message(String) for it

ErrorResponse

The server will raise the error when it failed to execute API request from the client. The error code and message should help the client to diagnose the issue.

ErrorResponse => errorMessageDescription
errorMessagevariable size, type = StringThe errorMessage

Value

The Value is serialized bytes for the Geode region value. It contains value header and series of bytes. Using value header, we can send a big serialized object in more than one chunk. 

Value => {ValueHeader value}Description
ValueHeadervariable size, type = ValueHeaderThe ValueHeader corresponding to this Value entry
valuevariable size, type = bytesSerialized Value Object which Geode can understand

ValueHeader

The value header contains the value bytes size, and a flag indicates whether it contains all the value bytes. 

ValueHeader => Size hasPartialBytesDescription
SizefixedSize = 4 bytes, type = int32Number of serialized bytes
hasPartialBytesfixedSize = 1 byte, type = booleanWhether this contains partial bytes of value

MetaData

The purpose of a metadata to pass defined key value pair with request and response. That will be optional for a client. If there is any metadata associated with request or response, then need to set "hasMetadata" flag to "true" in request or response header. After that send metadata in the following format.

MetaData => NumberOfMetadata { MetadataKeyId MetadataKeyValue} Description
NumberOfMetadatafixedSize = 2 bytes, type = int16The number of MetaDataKeyId : MetaDataKeyValue combinations
MetadataKeyIdfixedSize = 2 bytes, type = int16Supported MetaDataKeyId's can be found in the table "Supported MetaData - MetaData KeyId"
MetadataKeyValuevariable size, type = variableThe MetaData value for the KeyId. The supported dataType can be found in the table "Supported MetaData - MetaData Value Type"

Supported MetaData

 We would have following pre-defined key and value for a metadata. Note this list will grow over time.

MetaData for Requests

Request MetaData KeyMetaData KeyIdMetaData Value exampleMetaData Value TypeDescription
JSON_KEY

1

true

fixedSize = 1 byte, type = boolean

Geode will expect key as JSON string(or bytes) and it will convert that string into PDX key.

If the response requires a key, then it will convert the PDX key to JSON string(or bytes) back.

JSON_VALUE

2

 

true

fixedSize = 1 byte, type = boolean

Geode will expect Value as JSON string(or bytes) and it will convert that string into PDX value.

If the response requires a value, then it will convert PDX value to JSON string(or bytes) back.

EVENT_ID

3

 

EventId {

uniqueId: type = String

ThreadId:type=int64

SequenceId: type=int64

}

variable size, type = bytes

The eventid is used to identify same region event in Geode. Geode keeps map of "uniqueId + threadId" Vs

"SequenceId" to know whether region event has been already seen or not.

 

MetaData for Responses

Response MetaData KeyMetaData KeyIdMetaData Value exampleMetaData Value TypeDescription
UPDATE_PR_META_DATA

1

true

fixedSize = 1 byte, type = boolean

[optional]The server accepted and forwarded the request to the appropriate

node holding the affected cache entry.  A smart client should refresh its partitioned

region location metadata for higher performance.

Examples

PutRequest

string regionName = "ExampleRegion"

Key = 101

Value = "New Geode Client Server Protocol"

CallbackArg = Null

MessageHeader

 

RequestHeader

PutRequest

Size CorrelationId PartialMessage hasMetaDataRequestType apiVersionRegionName Key CallbackArg Value ( ValueHeader value )

Size = Size of Request (65)

0x00 0x00 0x00 0x42

RequestType (PutRequestType = 3)

0x00 0x03

RegionName(type:String, value:"ExampleRegion" )

 len = 0x00 0x0d

Utf Encoding = 0x45 0x78 0x61 0x6d 0x70 0x6c 0x65 0x52 0x65 0x67 0x69 0x6f 0x6e 

Size = (number of serialized bytes = 35)

 0x00 0x00 0x00 0x23

CorrelationId = 1

0x00 0x00 0x00 0x01 

apiVersion (1)

0x01

Key (Serialzied using geode types, value = 101)

 Geode Int type = 0x39

Value = 0x00 0x00 0x00 0x65 

isPartialBytes = (It contains all serialized bytes, type = boolean)

0x00

PartialMessage = (type = Boolean, value = false)

0x00

 

CallbackArg (Serialzied using geode types, value = null)

Value = 0x29 

value (Serialized as Geode String type, value = "New Geode Client Server Protocol")

Geode String type = 0x57

Serialized Encoded length = 0x00 0x20

Encoded String = 0x4e 0x65 0x77 0x20 0x47 0x65 0x6f 0x64 0x65 0x20 0x43 0x6c 0x69 0x65 0x6e 0x74

0x20 0x53 0x65 0x72 0x76 0x65 0x72 0x20 0x50 0x72 0x6f 0x74 0x6f 0x63 0x6f 0x6c

hasMetaData (false)

0x00

   

PutResponse

MessageHeader

ResponseHeaderPutResponse
Size CorrelationId PartialMessage hasMetaDataResponseTypeIdSuccess

Size = Size of Request (4)

0x00 0x00 0x00 0x04

ResponseTypeId (FullResponse, type=int16, value =1)

0x00 0x01

Success(type=boolean, value = true)

0x01

CorrelationId = 1

0x00 0x00 0x00 0x01 

 

 

PartialMessage = (type = Boolean, value = false)

0x00

  

hasMetaData (false)

0x00

  

Messages

PutRequestMessagePutResponseMessage
PutRequestMessage {
	MessageHeader {
  		Size, 4 byte, int32
 		CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
 	}
 
 	RequestHeader {
 		ApiId, 2 byte, int16
 		ApiVersion, 1 byte, int8
 	}
 	PutRequest {
 		regionName, varaible , String {
			len, 2 byte, int16
			variable, utf encoding		
		}
 		key, variable, bytes
		CallbackArg, variable, bytes
 		Value {
 			ValueHeader {
				Size, 4 byte, int32
				hasPartialBytes, 1 byte, boolean
 			}
			value {
 				bytes, series of bytes
			}
 		}
 	}
}
PutResponseMessage {
	MessageHeader {
    	Size, 4 byte, int32
        CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
    }
    ResponseHeader {
 		ResponseTypeId, 2 byte, int16	
 	}
  	Success, 1 byte, boolean
}
GetRequestMessageGetResponseMessage
GetRequestMessage {
	MessageHeader {
  		Size, 4 byte, int32
 		CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
 	}
 
 	RequestHeader {
 		ApiId, 2 byte, int16
 		ApiVersion, 1 byte, int8
 	}
 	GetRequest {
 		regionName, varaible , String {
			len, 2 byte, int16
			variable, utf encoding		
		}
 		key, variable, bytes
		CallbackArg, variable, bytes
 	}
}
GetResponseMessage {
	MessageHeader {
    	Size, 4 byte, int32
        CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
    }
    ResponseHeader {
 		ResponseTypeId, 2 byte, int16
 	}
  	Result, variable, bytes
}
PutAllRequestMessagePutAllResponseMessage
PutAllRequestMessage {
	MessageHeader {
  		Size, 4 byte, int32
 		CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
 	}
 
 	RequestHeader {
 		ApiId, 2 byte, int16
 		ApiVersion, 1 byte, int8
 	}
 	PutRequest {
 		regionName, varaible , String {
			len, 2 byte, int16
			variable, utf encoding		
		}
		NumberOfKeyValuePair, 4 byte, int32 
		KeyValuePair  { 
	 		key, variable, bytes		
 			Value {
 				ValueHeader {
					Size, 4 byte, int32
					hasPartialBytes, 1 byte, boolean
 				}
				value {
 					bytes, series of bytes
				}
			}
 		}
		CallbackArg, variable, bytes
 	}
}
PutAllResponseMessage {
	MessageHeader {
    	Size, 4 byte, int32
        CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
    }
	ResponseHeader {
 		ResponseTypeId, 2 byte, int16
 	}
  	NumberOfKeysFailed , 4 byte, int32
}
GetAllRequestMessageGetAllResponseMessage
GetAllRequestMessage {
	MessageHeader {
  		Size, 4 byte, int32
		CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
 	}
 
 	RequestHeader {
 		ApiId, 2 byte, int16
 		ApiVersion, 1 byte, int8
 	}
 	GetRequest {
 		regionName, varaible , String {
			len, 2 byte, int16
			variable, utf encoding		
		}
		NumberOfKeys, 4 byte, int32 
		keys {
 			key, variable, bytes
		}
		CallbackArg, variable, bytes
 	}
}
GetAllResponseMessage {
	MessageHeader {
    	Size, 4 byte, int32
		CorrelationId, 4 byte, int32
        isPartialMessage, 1 byte, boolean
        hasMetaData, 1 byte, boolean
    }
    ResponseHeader {
 		ResponseTypeId, 2 byte, int16
 	}
  	NumberOfKeyValuePair, 4 byte, int32 
	KeyValuePair  { 
		key, variable, bytes		
 		value, variable, bytes
	}
}

 

RPC Frameworks

RPC frameworks such as Thrift or Apache Avro provide tools to generate client -server library based on a message schema. We are talking about how we may support various RPC frameworks to facilitate quick creation of GEODE clients in various languages supported by popular RPC frameworks.

Glossary

  • Partial Response
  • Full Response

 

  • No labels