Browse files

adding record load code

  • Loading branch information...
1 parent bf4ddf8 commit b88a6f8274506e543c00ef4159366e85ddb6dc04 @tenderlove committed Dec 1, 2010
Showing with 45 additions and 4 deletions.
  1. +8 −1 lib/orient.rb
  2. +37 −3 lib/orient/connections/binary.rb
View
9 lib/orient.rb
@@ -7,7 +7,14 @@ module Orient
if $0 == __FILE__
conn = Orient::Connections::Binary.new 'localhost'
clusters = conn.db_open 'local:demo', 'admin', 'admin'
- p conn.count clusters.find { |c| c.name == 'default' }
+ clusters.each do |cluster|
+ p cluster.name => conn.count(cluster.name)
+ end
+
+ cluster = clusters.find { |c| c.name == 'city' }
+ p cluster
+ conn.record_load(cluster.id, 1)
+ #p conn.count clusters.find { |c| c.name == 'default' }
#conn.datacluster_count clusters
#conn.datacluster_datarange clusters.first
end
View
40 lib/orient/connections/binary.rb
@@ -6,15 +6,49 @@ class Cluster < Struct.new(:name, :id, :type)
module Connections
class Binary
+ RECORD_LOAD = 30
+ COUNT = 40
+
def initialize remote_host, port = 2424, lhost = nil, lport = nil
@socket = TCPSocket.new remote_host, port, lhost, lport
@tx = 0
end
- def count cluster
- header = [ 40, @tx ]
+ def record_load cluster_id, record_id, query_plan = "*:-1"
+ header = [ RECORD_LOAD, @tx ]
+ header = header.pack('cN')
+ packet = [
+ cluster_id,
+ record_id >> 32,
+ record_id & 0xFFFF,
+ ].pack 'nNN'
+
+ str = [
+ [ query_plan.bytesize, query_plan ],
+ ]
+ str = str.map { |tuple| [tuple.first].pack('N') + tuple.last }.join
+
+ @socket.write(header + packet + str)
+ response, txid = @socket.read(5).unpack('cN')
+ raise unless response == 0
+
+ @tx += 1
+
+ status = @socket.read(1).unpack('c').first
+ begin
+ len = @socket.read(4).unpack('N').first
+ record = @socket.read(len)
+ record_version, record_type = @socket.read(5).unpack('Nc')
+ p record
+ p record_type.chr
+ status = @socket.read(1).unpack('c').first
+ end while status == 2
+ end
+
+ def count cluster_name
+ header = [ COUNT, @tx ]
header = header.pack('cN')
- name = cluster.name
+ name = cluster_name
str = [
[ name.bytesize, name ],
]

0 comments on commit b88a6f8

Please sign in to comment.