Module: OrientdbBinary::DatabaseOperations::DataCluster

Included in:
OrientdbBinary::Database
Defined in:
lib/orientdb_binary/database_operations/data_cluster.rb

Instance Method Summary collapse

Instance Method Details

#add_datacluster(args) ⇒ Object

Add datacluster. name: string optional parameters: cluster_type: string (PHYSICAL or MEMORY), for memory databases it should be ‘MEMORY’, for local/plocal it can be either ‘MEMORY or ’PHYSICAL’ datasegment_name: string (should exists, ‘default’ is used by default) location: string cluster_id: string, should be -1 for new clusters

Usage: db.add_datacluster(name: “posts”) # uses default datasegment If needed datasegment should be created before db.add_datasegment(name: “posts”) db.add_datacluster(name: “posts”, datasegment_name: “posts”)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/orientdb_binary/database_operations/data_cluster.rb', line 25

def add_datacluster(args)
  types = {
    local: 'PHYSICAL',
    plocal: 'PHYSICAL',
    memory: 'MEMORY'
  }

  defaults = {
    cluster_type: types[@db_params[:storage].to_sym],
    datasegment_name: "default",
    location: args[:name] + "_datacluster",
    cluster_id: -1
  }

  options = defaults.merge(args)

  OrientdbBinary::Protocols::DataclusterAdd.new(params(options)).process(socket)
end

#count_datacluster(args) ⇒ Object

cluster_ids: array of ids or cluster_names: array of names Usage: db.count_datacluster(cluster_ids: [0,1,2,3]) db.count_datacluster(cluster_names: [‘default’, ‘posts’])



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/orientdb_binary/database_operations/data_cluster.rb', line 80

def count_datacluster(args)
  if args[:cluster_names] and not args[:cluster_ids]
    args[:cluster_ids] = args[:cluster_names].map do |name|
      cluster = find_datacluster_by(cluster_name: name)
      cluster[:cluster_id] if cluster
    end
  end
  args[:cluster_ids] = args[:cluster_ids].delete_if {|cluster| !cluster}
  args[:cluster_count] = args[:cluster_ids].length

  OrientdbBinary::Protocols::DataclusterCount.new(params(args)).process(socket)
end

#datacluster_lh_cluster_is_usedObject

it looks like it’s not supported (?)



110
111
112
113
# File 'lib/orientdb_binary/database_operations/data_cluster.rb', line 110

def datacluster_lh_cluster_is_used()
  # OrientdbBinary::Protocols::DataclusterLhClusterIsUsed.new(session: session).process(socket)
  return nil
end

#datarange_datacluster(args) ⇒ Object

cluster_id: int or cluster_name: string Usage: db.datarange_datacluster(cluster_id: 7) db.datarange_datacluster(cluster_name: ‘posts’)



100
101
102
103
104
105
106
107
# File 'lib/orientdb_binary/database_operations/data_cluster.rb', line 100

def datarange_datacluster(args)
  if args[:cluster_name] and not args[:cluster_id]
    if cluster=find_datacluster_by(cluster_name: args[:cluster_name])
      args[:cluster_id] = cluster[:cluster_id]
    end
  end
  OrientdbBinary::Protocols::DataclusterDatarange.new(params(args)).process(socket)
end

#drop_datacluster(args) ⇒ Object

Drops datacluster cluster_id: int or cluster_name: string Usage: db.drop_datacluster(cluster_id: 7) db.drop_datacluster(cluster_name: ‘posts’)



64
65
66
67
68
69
70
71
# File 'lib/orientdb_binary/database_operations/data_cluster.rb', line 64

def drop_datacluster(args)
  if args[:cluster_name] and not args[:cluster_id]
    if cluster=find_datacluster_by(cluster_name: args[:cluster_name])
      args[:cluster_id] = cluster[:cluster_id]
    end
  end
  OrientdbBinary::Protocols::DataclusterDrop.new(params(args)).process(socket)
end

#find_datacluster_by(arg) ⇒ Object

Find cluster by its parameter Usage: db.find_datacluster_by(name: ‘default’) db.find_datacluster_by(id: 1) Only first cluster is returned!



50
51
52
53
54
# File 'lib/orientdb_binary/database_operations/data_cluster.rb', line 50

def find_datacluster_by(arg)
  key = arg.keys.first
  val = arg[key]
  @clusters.select {|cluster| cluster["#{key}".to_sym] == val}.first
end