Skip to content

Commit ee53910

Browse files
committed
RDBC-644 Corrupted stream bugfix - bytearray.clear() caused data loss
1 parent 59f8bcf commit ee53910

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

ravendb/documents/bulk_insert_operation.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import concurrent
55
import json
66
from concurrent.futures import Future
7+
from copy import deepcopy
78
from queue import Queue
89
from threading import Lock, Semaphore
910
from typing import Optional, TYPE_CHECKING
@@ -258,19 +259,18 @@ def __return_func():
258259
return __return_func
259260

260261
def _flush_if_needed(self) -> None:
261-
pass
262-
# if len(self._current_data_buffer) > self._max_size_in_buffer or self._enqueue_current_buffer_async.done():
263-
# self._enqueue_current_buffer_async.result()
264-
#
265-
# buffer = self._current_data_buffer
266-
# self._current_data_buffer.clear()
267-
#
268-
# # todo: check if it's better to create a new bytearray of max size instead of clearing it (possible dealloc)
269-
#
270-
# def __enqueue_buffer_for_flush():
271-
# self._buffer_exposer.enqueue_buffer_for_flush(buffer)
272-
#
273-
# self._enqueue_current_buffer_async = self._thread_pool_executor.submit(__enqueue_buffer_for_flush)
262+
if len(self._current_data_buffer) > self._max_size_in_buffer or self._enqueue_current_buffer_async.done():
263+
self._enqueue_current_buffer_async.result() # wait
264+
265+
buffer = deepcopy(self._current_data_buffer)
266+
self._current_data_buffer.clear()
267+
268+
# todo: check if it's better to create a new bytearray of max size instead of clearing it (possible dealloc)
269+
270+
def __enqueue_buffer_for_flush(flushed_buffer: bytearray):
271+
self._buffer_exposer.enqueue_buffer_for_flush(flushed_buffer)
272+
273+
self._enqueue_current_buffer_async = self._thread_pool_executor.submit(__enqueue_buffer_for_flush, buffer)
274274

275275
def _end_previous_command_if_needed(self) -> None:
276276
if self._in_progress_command == CommandType.COUNTERS:

0 commit comments

Comments
 (0)