Class Moped::Node
In: lib/moped/node.rb
Parent: Object

Represents a client to a node in a server cluster.

@since 1.0.0

Methods

Included Modules

Executable Instrumentable

Attributes

address  [R]  @!attribute address
  @return [ Address ] The address.

@!attribute down_at

  @return [ Time ] The time the node was marked as down.

@!attribute latency

  @return [ Integer ] The latency in milliseconds.

@!attribute options

  @return [ Hash ] The node options.

@!attribute refreshed_at

  @return [ Time ] The last time the node did a refresh.
credentials  [RW]  @!attribute credentials
  @return [ Hash ] The credentials of the node.
down_at  [R]  @!attribute address
  @return [ Address ] The address.

@!attribute down_at

  @return [ Time ] The time the node was marked as down.

@!attribute latency

  @return [ Integer ] The latency in milliseconds.

@!attribute options

  @return [ Hash ] The node options.

@!attribute refreshed_at

  @return [ Time ] The last time the node did a refresh.
latency  [R]  @!attribute address
  @return [ Address ] The address.

@!attribute down_at

  @return [ Time ] The time the node was marked as down.

@!attribute latency

  @return [ Integer ] The latency in milliseconds.

@!attribute options

  @return [ Hash ] The node options.

@!attribute refreshed_at

  @return [ Time ] The last time the node did a refresh.
options  [R]  @!attribute address
  @return [ Address ] The address.

@!attribute down_at

  @return [ Time ] The time the node was marked as down.

@!attribute latency

  @return [ Integer ] The latency in milliseconds.

@!attribute options

  @return [ Hash ] The node options.

@!attribute refreshed_at

  @return [ Time ] The last time the node did a refresh.
refreshed_at  [R]  @!attribute address
  @return [ Address ] The address.

@!attribute down_at

  @return [ Time ] The time the node was marked as down.

@!attribute latency

  @return [ Integer ] The latency in milliseconds.

@!attribute options

  @return [ Hash ] The node options.

@!attribute refreshed_at

  @return [ Time ] The last time the node did a refresh.

Public Class methods

Creat the new node.

@example Create the new node.

  Node.new("127.0.0.1:27017")

@param [ String ] address The location of the server node. @param [ Hash ] options Additional options for the node (ssl)

@since 1.0.0

Public Instance methods

Is this node equal to another?

@example Is the node equal to another.

  node == other

@param [ Node ] other The other node.

@return [ true, false ] If the addresses are equal.

@since 1.0.0

Is the node an arbiter?

@example Is the node an arbiter?

  node.arbiter?

@return [ true, false ] If the node is an arbiter.

@since 1.0.0

Is the node auto-discovering new peers in the cluster?

@example Is the node auto discovering?

  node.auto_discovering?

@return [ true, false ] If the node is auto discovering.

@since 2.0.0

Execute a command against a database.

@example Execute a command.

  node.command(database, { ping: 1 })

@param [ Database ] database The database to run the command on. @param [ Hash ] cmd The command to execute. @options [ Hash ] options The command options.

@raise [ OperationFailure ] If the command failed.

@return [ Hash ] The result of the command.

@since 1.0.0

Is the node currently connected?

@example Is the node connected?

  node.connected?

@return [ true, false ] If the node is connected or not.

@since 2.0.0

Get the underlying connection for the node.

@example Get the node‘s connection.

  node.connection

@return [ Connection ] The connection.

@since 2.0.0

Force the node to disconnect from the server.

@example Disconnect the node.

  node.disconnect

@return [ true ] If the disconnection succeeded.

@since 1.2.0

Mark the node as down.

@example Mark the node as down.

  node.down!

@return [ nil ] Nothing.

@since 2.0.0

Is the node down?

@example Is the node down?

  node.down?

@return [ Time, nil ] The time the node went down, or nil if up.

@since 1.0.0

Yields the block if a connection can be established, retrying when a connection error is raised.

@example Ensure we are connection.

  node.ensure_connected do
    #...
  end

@raises [ ConnectionFailure ] When a connection cannot be established.

@return [ nil ] nil.

@since 1.0.0

Set a flag on the node for the duration of provided block so that an exception is raised if the node is no longer the primary node.

@example Ensure this node is primary.

  node.ensure_primary do
    node.command(ismaster: 1)
  end

@return [ nil ] nil.

@since 1.0.0s

eql?(other)

Alias for #==

Execute a get more operation on the node.

@example Execute a get more.

  node.get_more(database, collection, 12345, -1)

@param [ Database ] database The database to get more from. @param [ Collection ] collection The collection to get more from. @param [ Integer ] cursor_id The id of the cursor on the server. @param [ Integer ] limit The number of documents to limit. @raise [ CursorNotFound ] if the cursor has been killed

@return [ Message ] The result of the operation.

@since 1.0.0

Get the hash identifier for the node.

@example Get the hash identifier.

  node.hash

@return [ Integer ] The hash identifier.

@since 1.0.0

Insert documents into the database.

@example Insert documents.

  node.insert(database, collection, [{ name: "Tool" }])

@param [ Database ] database The database to insert to. @param [ Collection ] collection The collection to insert to. @param [ Array<Hash> ] documents The documents to insert.

@return [ Message ] The result of the operation.

@since 1.0.0

Get the node as a nice formatted string.

@example Inspect the node.

  node.inspect

@return [ String ] The string inspection.

@since 1.0.0

Kill all provided cursors on the node.

@example Kill all the provided cursors.

  node.kill_cursors([ 12345 ])

@param [ Array<Integer> ] cursor_ids The cursor ids.

@return [ Message ] The result of the operation.

@since 1.0.0

Can we send messages to this node in normal cirucmstances? This is true only if the node is a primary or secondary node - arbiters or passives cannot be sent anything.

@example Is the node messagable?

  node.messagable?

@return [ true, false ] If messages can be sent to the node.

@since 2.0.0

Does the node need to be refreshed?

@example Does the node require refreshing?

  node.needs_refresh?(time)

@param [ Time ] time The next referesh time.

@return [ true, false] Whether the node needs to be refreshed.

@since 1.0.0

Is the node passive?

@example Is the node passive?

  node.passive?

@return [ true, false ] If the node is passive.

@since 1.0.0

Get all the other nodes in the replica set according to the server information.

@example Get the node‘s peers.

  node.peers

@return [ Array<Node> ] The peers.

@since 2.0.0

Execute a pipeline of commands, for example a safe mode persist.

@example Execute a pipeline.

  node.pipeline do
    #...
  end

@return [ nil ] nil.

@since 1.0.0 @todo: Remove with piggbacked gle.

Is the node the replica set primary?

@example Is the node the primary?

  node.primary?

@return [ true, false ] If the node is the primary.

@since 1.0.0

Processes the provided operation on this node, and will execute the callback when the operation is sent to the database.

@example Process a read operation.

  node.process(query) do |reply|
    return reply.documents
  end

@param [ Message ] operation The database operation. @param [ Proc ] callback The callback to run on operation completion.

@return [ Object ] The result of the callback.

@since 1.0.0

Execute a query on the node.

@example Execute a query.

  node.query(database, collection, { name: "Tool" })

@param [ Database ] database The database to query from. @param [ Collection ] collection The collection to query from. @param [ Hash ] selector The query selector. @param [ Hash ] options The query options.

@raise [ QueryFailure ] If the query had an error.

@return [ Message ] The result of the operation.

@since 1.0.0

Refresh information about the node, such as it‘s status in the replica set and it‘s known peers.

@example Refresh the node.

  node.refresh

@raise [ ConnectionFailure ] If the node cannot be reached.

@raise [ ReplicaSetReconfigured ] If the node is no longer a primary node and

  refresh was called within an +#ensure_primary+ block.

@return [ nil ] nil.

@since 1.0.0

Execute a remove command for the provided selector.

@example Remove documents.

  node.remove(database, collection, { name: "Tool" })

@param [ Database ] database The database to remove from. @param [ Collection ] collection The collection to remove from. @param [ Hash ] selector The query selector. @param [ Hash ] options The remove options.

@return [ Message ] The result of the operation.

@since 1.0.0

Is the node a replica set secondary?

@example Is the node a secondary?

  node.secondary?

@return [ true, false ] If the node is a secondary.

@since 1.0.0

Get the timeout, in seconds, for this node.

@example Get the timeout in seconds.

  node.timeout

@return [ Integer ] The configured timeout or the default of 5.

@since 1.0.0

Execute an update command for the provided selector.

@example Update documents.

  node.update(database, collection, { name: "Tool" }, { likes: 1000 })

@param [ Database ] database The database to update. @param [ Collection ] collection The collection to update. @param [ Hash ] selector The query selector. @param [ Hash ] change The updates. @param [ Hash ] options The update options.

@return [ Message ] The result of the operation.

@since 1.0.0

[Validate]