-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,731 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Copyright (C) 2021 Bosutech XXI S.L. | ||
# | ||
# nucliadb is offered under the AGPL v3.0 and as commercial software. | ||
# For commercial licensing, contact us at info@nuclia.com. | ||
# | ||
# AGPL: | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
from __future__ import annotations | ||
|
||
from nucliadb.writer import logger | ||
from nucliadb.writer.tus.dm import FileDataManager | ||
from nucliadb.writer.tus.storage import BlobStore, FileStorageManager | ||
from nucliadb_protos.resources_pb2 import CloudFile | ||
from nucliadb_utils.storages import CHUNK_SIZE | ||
from nucliadb_utils.storages.azure import AzureObjectStore | ||
from nucliadb_utils.storages.exceptions import ObjectNotFoundError | ||
from nucliadb_utils.storages.utils import ObjectMetadata | ||
|
||
|
||
class AzureBlobStore(BlobStore): | ||
async def finalize(self): | ||
if self._object_store is None: | ||
return | ||
try: | ||
await self._object_store.close() | ||
except Exception: | ||
logger.exception("Error closing AzureBlobStore") | ||
self._object_store = None | ||
|
||
async def initialize(self, connection_string: str): | ||
self.bucket = "nucliadb-{kbid}" | ||
self.source = CloudFile.Source.AZURE | ||
self._object_store = AzureObjectStore(connection_string) | ||
await self._object_store.initialize() | ||
|
||
@property | ||
def object_store(self) -> AzureObjectStore: | ||
assert self._object_store is not None | ||
return self._object_store | ||
|
||
async def check_exists(self, bucket_name: str) -> bool: | ||
return await self.object_store.bucket_exists(bucket_name) | ||
|
||
async def create_bucket(self, bucket_name: str) -> bool: | ||
created = await self.object_store.bucket_create(bucket_name) | ||
return not created | ||
|
||
|
||
class AzureFileStorageManager(FileStorageManager): | ||
storage: AzureBlobStore | ||
chunk_size = CHUNK_SIZE | ||
min_upload_size = None | ||
|
||
@property | ||
def object_store(self) -> AzureObjectStore: | ||
return self.storage.object_store | ||
|
||
async def start(self, dm: FileDataManager, path: str, kbid: str): | ||
bucket = self.storage.get_bucket_name(kbid) | ||
if dm.filename == 0: | ||
filename = "file" | ||
else: | ||
filename = dm.filename | ||
metadata = ObjectMetadata( | ||
filename=filename, | ||
content_type=dm.content_type, | ||
size=dm.size, | ||
) | ||
await self.object_store.upload_multipart_start(bucket, path, metadata) | ||
await dm.update(path=path, bucket=bucket) | ||
|
||
async def delete_upload(self, uri: str, kbid: str) -> None: | ||
bucket = self.storage.get_bucket_name(kbid) | ||
try: | ||
await self.object_store.delete(bucket, uri) | ||
except ObjectNotFoundError: | ||
logger.warning( | ||
"Attempt to delete an upload but not found", | ||
extra={"uri": uri, "kbid": kbid, "bucket": bucket}, | ||
) | ||
|
||
async def append(self, dm: FileDataManager, iterable, offset: int) -> int: | ||
bucket = dm.get("bucket") | ||
assert bucket is not None | ||
path = dm.get("path") | ||
assert path is not None | ||
uploaded_bytes = await self.object_store.upload_multipart_append(bucket, path, iterable) | ||
await dm.update(offset=offset) | ||
return uploaded_bytes | ||
|
||
async def finish(self, dm: FileDataManager): | ||
path = dm.get("path") | ||
await dm.finish() | ||
return path | ||
|
||
def validate_intermediate_chunk(self, uploaded_bytes: int): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
390 changes: 195 additions & 195 deletions
390
nucliadb_protos/python/src/nucliadb_protos/resources_pb2.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
828939e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
tests/search/unit/search/test_fetch.py::test_highligh_error
3038.933642005945
iter/sec (stddev: 0.000006822984662528208
)2841.0684406726436
iter/sec (stddev: 0.000004954958228416619
)0.93
This comment was automatically generated by workflow using github-action-benchmark.
828939e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
tests/search/unit/search/test_fetch.py::test_highligh_error
3143.318018075541
iter/sec (stddev: 0.000004774135904057321
)2841.0684406726436
iter/sec (stddev: 0.000004954958228416619
)0.90
This comment was automatically generated by workflow using github-action-benchmark.
828939e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
tests/search/unit/search/test_fetch.py::test_highligh_error
3002.311769984327
iter/sec (stddev: 0.000006179196220037763
)2841.0684406726436
iter/sec (stddev: 0.000004954958228416619
)0.95
This comment was automatically generated by workflow using github-action-benchmark.