hdfs: copy: don't read everything into memory (#5277)

Regression from #4973 and #4747
This commit is contained in:
Ruslan Kuprieiev
2021-01-16 00:57:13 +02:00
committed by GitHub
parent b027760e12
commit 273518afab
2 changed files with 5 additions and 3 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ import io
import logging
import os
import re
import shutil
import subprocess
from collections import deque
from contextlib import closing, contextmanager
@@ -162,7 +163,7 @@ class HDFSTree(BaseTree):
with closing(
hdfs.open_output_stream(tmp_info.path)
) as tmp_fobj:
tmp_fobj.write(from_fobj.read())
shutil.copyfileobj(from_fobj, tmp_fobj)
hdfs.move(tmp_info.path, to_info.path)
except Exception:
self.remove(tmp_info)
+3 -2
View File
@@ -1,5 +1,6 @@
import logging
import os
import shutil
import threading
from contextlib import contextmanager
from urllib.parse import urlparse
@@ -134,8 +135,8 @@ class WebHDFSTree(BaseTree):
def copy(self, from_info, to_info, **_kwargs):
with self.hdfs_client.read(from_info.path) as reader:
content = reader.read()
self.hdfs_client.write(to_info.path, data=content)
with self.hdfs_client.write(to_info.path) as writer:
shutil.copyfileobj(reader, writer)
def move(self, from_info, to_info, mode=None):
self.hdfs_client.makedirs(to_info.parent.path)