lib/mongo/grid/stream/write.rb in mongo-2.20.1 vs lib/mongo/grid/stream/write.rb in mongo-2.21.0
- old
+ new
@@ -81,10 +81,16 @@
end
=end
@options.freeze
@filename = @options[:filename]
@open = true
+ @timeout_holder = CsotTimeoutHolder.new(
+ operation_timeouts: {
+ operation_timeout_ms: options[:timeout_ms],
+ inherited_timeout_ms: fs.database.timeout_ms
+ }
+ )
end
# Write to the GridFS bucket from the source stream or a string.
#
# @example Write to GridFS.
@@ -105,11 +111,16 @@
# IO objects
io.size
end
chunks = File::Chunk.split(io, file_info, @n)
@n += chunks.size
- chunks_collection.insert_many(chunks) unless chunks.empty?
+ unless chunks.empty?
+ chunks_collection.insert_many(
+ chunks,
+ timeout_ms: @timeout_holder.remaining_timeout_ms!
+ )
+ end
self
end
# Close the write stream.
#
@@ -122,11 +133,14 @@
#
# @since 2.1.0
def close
ensure_open!
update_length
- files_collection.insert_one(file_info, @options)
+ files_collection.insert_one(
+ file_info,
+ @options.merge(timeout_ms: @timeout_holder.remaining_timeout_ms!)
+ )
@open = false
file_id
end
# Get the write concern used when uploading.
@@ -164,11 +178,14 @@
#
# @return [ true ] True if the operation was aborted and the stream is closed.
#
# @since 2.1.0
def abort
- fs.chunks_collection.find({ :files_id => file_id }, @options).delete_many
+ fs.chunks_collection.find(
+ { :files_id => file_id },
+ @options.merge(timeout_ms: @timeout_holder.remaining_timeout_ms!)
+ ).delete_many
(@open = false) || true
end
private
@@ -198,10 +215,10 @@
doc = { length: @length, _id: file_id, filename: filename }
@file_info ||= File::Info.new(options.merge(doc))
end
def ensure_indexes!
- fs.send(:ensure_indexes!)
+ fs.send(:ensure_indexes!, @timeout_holder)
end
def ensure_open!
raise Error::ClosedStream.new if closed?
end