After some minor tweaks in the Ruby FlockDB client I can issue commands from the IRB interactive shell and can see the server implements the expected behavior.
The IRB client does the right thing. I can pass a list of integers to the add command and I get the desired result.
I added some print statements to the FlockDB server code and can see the server side code processes the list correctly.
1.9.3-p194 :001 > require "flockdb"
=> true
1.9.3-p194 :002 > flock = Flock.new("localhost:7915",{ :graphs => { :follows => 1, :blocks => 2 , :loves => 3, :hates => 4}, :transport_wrapper => Thrift::FramedTransport})
=> #<Flock::Client:0x000000027764e0 @graphs={:follows=>1, :blocks=>2, :loves=>3, :hates=>4}, @service=<Flock::Service(Flock::Edges::FlockDB::Client) @current_server=localhost:7915>>
1.9.3-p194 :003 > flock.add(1, 2, [2,3,4,5])
=> nil
1.9.3-p194 :006 > flock.select(1, 2, nil).to_a
=> [3, 5, 2, 4]
1.9.3-p194 :007 >
I am using the following Java code in my client:
// Create and open the connection to the server.
TTransport transport = new TFramedTransport(new TSocket("localhost", 7915, 10000));
TProtocol protocol = new TBinaryProtocol(transport);
FlockDB.Client client = new FlockDB.Client(protocol);
try {
transport.open();
} catch (TException x) {
x.printStackTrace();
}
// Create the query term
QueryTerm queryTerm = new QueryTerm(1, 1, true);
// Allocate a ByteBuffer with 4 bytes for an int.
ByteBuffer destinationIdsBuffer = ByteBuffer.allocate(4);
// Use standard putInt api to add an integer to the buffer.
destinationIdsBuffer.putInt(5);
// set the destination Ids buffer in the query term.
queryTerm.setDestination_ids(destinationIdsBuffer);
// Create the necessary objects to wrap the query term.
ExecuteOperation exOp = new ExecuteOperation(ExecuteOperationType.Add, queryTerm);
List<ExecuteOperation> exOperationList = new ArrayList<ExecuteOperation>();
exOperationList.add(exOp);
ExecuteOperations exOperations = new ExecuteOperations(exOperationList, Priority.High);
// Make the call to the thrift API
try {
client.execute(exOperations);
} catch (TException x) {
x.printStackTrace();
} catch (FlockException e) {
e.printStackTrace();
}
The client code generated by Thrift uses a ByteArray as the class for the destination_Ids field. So I am trying to set the destinationIds of the QueryTerm object using a ByteArray I create in my client code.
The server, however, does not get the destination_Ids I am passing in the byte array.
The log below shows the place where the FlockDB server processes the destination ids.
I can see the server received a non null HeapByteBuffer. The byte buffer position is 69 and its capacity is 80.
After reading the byte buffer into the WrappedArray, the WrappedArray is empty.
If I increase the size of the ByteBuffer allocation on the client side to around 20, and add only 5 to the buffer using putInt(5),
then I can see 2 values inside the WrappedArray (see below). But the values are (0,0) and not 5.
A size of 20 seems to be the threshold -- if the size is less than 20, the server does not see any value.
If instead of a single value, I tried to add 5 integers to the byte array, then again I get an empty WrappedArray (see below).
I tried several different mechanisms to fill the byte array of the ByteBuffer, but was not able to get the desired result.
I tried to fill the first 4 bytes of the array directly using different byte ordering (most significant bytes first, least significant bytes first) but it did not chang anything. I was not able to get a single integer value across the wire.
INF [20120621-10:24:53.228] flockdb: execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(java.nio.HeapByteBuffer[pos=69 lim=69 cap=80]),None),None)),None,High)
INF [20120621-10:24:53.228] flockdb: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(java.nio.HeapByteBuffer[pos=69 lim=69 cap=80]),None),None)),None,High)
INF [20120621-10:24:53.229] flockdb: EdgesService: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None)),None,High)
INF [20120621-10:24:53.229] queries: ExecuteCompiler.apply ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None)),None,High) Program.size = 1
INF [20120621-10:24:53.229] queries: ExecuteCompiler.apply op = ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None) Term = QueryTerm(1,1,true,Some(WrappedArray()),List())
INF [20120621-10:24:53.229] queries: ExecuteCompiler.processDestinations source = 1 destinationIds.isDefined true
INF [20120621-10:24:53.229] queries: ExecuteCompiler.processDestinations destinationIds = WrappedArray()
INF [20120621-10:24:53.230] flockdb: wrapRPC rpcName = execute fPromise@1561232967(ivar=Ivar@1687277323(state=Done(Return(()))), cancelled=Ivar@548409026(state=Linked(Ivar@1580755471(state=Waiting(List(),List())))))
INF [20120621-10:24:53.230] flockdb: EdgesService: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None)),None,High)
INF [20120621-10:24:53.230] queries: ExecuteCompiler.apply ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None)),None,High) Program.size = 1
Using:
INF [20120621-10:31:35.644] flockdb: execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(java.nio.HeapByteBuffer[pos=69 lim=85 cap=96]),None),None)),None,High)
INF [20120621-10:31:35.645] flockdb: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(java.nio.HeapByteBuffer[pos=69 lim=85 cap=96]),None),None)),None,High)
INF [20120621-10:31:35.645] flockdb: EdgesService: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray(0, 0)),List()),None)),None,High)
INF [20120621-10:31:35.645] queries: ExecuteCompiler.apply ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray(0, 0)),List()),None)),None,High) Program.size = 1
INF [20120621-10:31:35.645] queries: ExecuteCompiler.apply op = ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray(0, 0)),List()),None) Term = QueryTerm(1,1,true,Some(WrappedArray(0, 0)),List())
INF [20120621-10:31:35.645] queries: ExecuteCompiler.processDestinations source = 1 destinationIds.isDefined true
INF [20120621-10:31:35.645] queries: ExecuteCompiler.processDestinations destinationIds = WrappedArray(0, 0)
INF [20120621-10:41:54.508] flockdb: execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(java.nio.HeapByteBuffer[pos=69 lim=69 cap=80]),None),None)),None,High)
INF [20120621-10:41:54.509] flockdb: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(java.nio.HeapByteBuffer[pos=69 lim=69 cap=80]),None),None)),None,High)
INF [20120621-10:41:54.509] flockdb: EdgesService: Call to Execute ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None)),None,High)
INF [20120621-10:41:54.509] queries: ExecuteCompiler.apply ExecuteOperations(ArrayBuffer(ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None)),None,High) Program.size = 1
INF [20120621-10:41:54.509] queries: ExecuteCompiler.apply op = ExecuteOperation(Add,QueryTerm(1,1,true,Some(WrappedArray()),List()),None) Term = QueryTerm(1,1,true,Some(WrappedArray()),List())
INF [20120621-10:41:54.509] queries: ExecuteCompiler.processDestinations source = 1 destinationIds.isDefined true
INF [20120621-10:41:54.509] queries: ExecuteCompiler.processDestinations destinationIds = WrappedArray()