Class: Monga::Cursor
- Inherits:
-
Object
show all
- Defined in:
- lib/monga/cursor.rb
Constant Summary
collapse
- CURSORS =
{}
- CLOSED_CURSOR =
0
- CLOSE_TIMEOUT =
Batch kill cursors marked to be killed each CLOSE_TIMEOUT seconds
1
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(connection, db_name, collection_name, options = {}, flags = {}) ⇒ Cursor
Returns a new instance of Cursor.
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/monga/cursor.rb', line 18
def initialize(connection, db_name, collection_name, options = {}, flags = {})
@connection = connection
@db_name = db_name
@collection_name = collection_name
@options = options
@options.merge!(flags)
@fetched_docs = []
@count = 0
@options[:limit] ||= 0
end
|
Instance Attribute Details
#cursor_id ⇒ Object
Returns the value of attribute cursor_id.
3
4
5
|
# File 'lib/monga/cursor.rb', line 3
def cursor_id
@cursor_id
end
|
Class Method Details
.batch_kill(conn) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/monga/cursor.rb', line 66
def self.batch_kill(conn)
cursors = CURSORS.select{ |k,v| v }
cursor_ids = cursors.keys
if cursor_ids.any?
Monga.logger.debug("Following cursors are going to be deleted: #{cursor_ids}")
kill_cursors(conn, cursor_ids)
cursor_ids.each{ |id| CURSORS.delete id }
end
end
|
.create(connection, db_name, collection_name, options = {}, flags = {}) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/monga/cursor.rb', line 5
def self.create(connection, db_name, collection_name, options = {}, flags = {})
if connection.type == :em
CallbackCursor.new(connection, db_name, collection_name, options, flags)
else
BlockCursor.new(connection, db_name, collection_name, options, flags)
end
end
|
Instance Method Details
#batch_size(val) ⇒ Object
43
44
45
|
# File 'lib/monga/cursor.rb', line 43
def batch_size(val)
@options[:batch_size] = val and self
end
|
#explain ⇒ Object
47
48
49
|
# File 'lib/monga/cursor.rb', line 47
def explain
@options[:explain] = true and self
end
|
#flag(opt) ⇒ Object
31
32
33
|
# File 'lib/monga/cursor.rb', line 31
def flag(opt)
@options.merge!(opt) and self
end
|
#hint ⇒ Object
51
52
53
|
# File 'lib/monga/cursor.rb', line 51
def hint
@options[:hint] = true and self
end
|
#kill ⇒ Object
59
60
61
62
63
64
|
# File 'lib/monga/cursor.rb', line 59
def kill
return if @cursor_id == CLOSED_CURSOR
self.class.kill_cursors(@connection, @cursor_id)
CURSORS.delete @cursor_id
@cursor_id = 0
end
|
#limit(val) ⇒ Object
35
36
37
|
# File 'lib/monga/cursor.rb', line 35
def limit(val)
@options[:limit] = val and self
end
|
#mark_to_kill ⇒ Object
Sometime in future all marked cursors will be killed in batch
77
78
79
80
|
# File 'lib/monga/cursor.rb', line 77
def mark_to_kill
CURSORS[@cursor_id] = true if @cursor_id && alive?
@cursor_id = 0
end
|
#skip(val) ⇒ Object
39
40
41
|
# File 'lib/monga/cursor.rb', line 39
def skip(val)
@options[:skip] = val and self
end
|
#sort(val) ⇒ Object
55
56
57
|
# File 'lib/monga/cursor.rb', line 55
def sort(val)
@options[:sort] = val and self
end
|